An example of clean architecture with NestJS
This application is designed using a Clean Architecture pattern (also known as Hexagonal Architecture). Therefore SOLID principles are used in code, especially the Dependency Inversion Principle (do not mix up with the classic dependency injection in NestJS for example).
Concretely, there are 3 main packages: domain
, use_cases
and infrastructure
. These packages have to respect these rules:
domain
contains the business code and its logic, and has no outward dependency: nor on frameworks (NestJS for example), nor onuse_cases
orinfrastructure
packages.use_cases
is like a conductor. It will depend only ondomain
package to execute business logic.use_cases
should not have any dependencies oninfrastructure
.infrastructure
contains all the technical details, configuration, implementations (database, web services, etc.), and must not contain any business logic.infrastructure
has dependencies ondomain
,use_cases
and frameworks.
npm install
npm test
npm run typeorm:migration:run
npm run start:dev