This is a repository to start a new React + Typescript project following SOLID principles (Clean Architecture).
$ yarn
$ yarn start
$ yarn build
$ yarn preview
$ yarn test
$ yarn test:watch
$ yarn coverage
This project has 4 layers:
- Entities: entities of the system (enterprise business rules)
- App: use-cases of the system (application business rules) and contracts to interact with external services
- Externals: implementations with external services of the contracts defined in the Application layer
- UI: presentation layer (regular React project structure) isolated from the core business rules
This repository supports the following features:
- Path aliases with
@/
(e.g.,import { User } from "@/entities/user";
)
This codebase has 5 main folders:
src/entities
: To define the entities
For example: There is an entity User
.
src/app/contracts
: To define the contracts that should be followed especially by external items likeIUserRepository
:
- create()
- update()
- delete()
- deleteAll()
- getById()
- listAll()
src/app/use-cases
: To define the system actions. For example:
- create-user
- update-user
- delete-user
- get-user-by-id
- list-users
Each use case should have its automated tests.
-
src/externals
: To define the rest, implementations that are not important for the business rules like Http Clients, Libraries, Cache, etc. -
src/ui
: To define the UI or Presentation layer of the app, in this case a React project.
React
as the UI LibraryAxios
as the Http ClientFormik
for handling formsVitest
for unit and integration tests
This is a template following SOLID principles with React + Typescript. The goal here is to use React only in the UI layer, in order to decouple the business rules.
Feel free to use the best practices for React in terms of routing, componentization, contexts, hooks, etc. Business rules should be reserverd to use cases
and entities
.