How z3r0j/nodejs-clean-architecture works
This repository is a Clean Architecture starter for TypeScript REST APIs, illustrated with a Test resource. The documented request path is HTTP routing through controllers and application services to repositories and a TypeORM database, with DTO validation, Result-based service outcomes, and centralized error responses. Bootstrap initializes the data source and dependency container before configuring Express. The README describes additional capabilities such as API-key protection and transactional Unit of Work; their runtime wiring is not shown in the sampled source, so those links are documented rather than source-verified.
Main entry points: TestServices.ts Test services · test.controller.ts Test controller · index.ts Dependency container · express.config.ts Express configuration
Components 20
HTTP interface
- Test routes
src/interfaces/routes/test.route.ts - Test controller
src/interfaces/controllers/test.controller.ts - API-key middleware
src/interfaces/middlewares/apikey.middleware.ts - Result responder
src/interfaces/controllers/helpers/respond.ts - Error handler
src/interfaces/middlewares/error.handler.middleware.ts
Application logic
- Create DTO
src/application/dtos/createTestDTO.ts - Response DTO
src/application/dtos/testResponseDTO.ts - Domain errors
src/error-handling/CustomError.ts - Test services
src/application/services/TestServices.ts - Generic services
src/application/services/GenericServices.ts - Test entity
src/domain/entities/Test.ts
Persistence
- Unit of Work
src/infrastructure/UnitOfWork.ts - Test repository
src/infrastructure/repositories/TestRepository.ts - Generic repository
src/infrastructure/repositories/GenericRepository.ts - TypeORM database
src/infrastructure/typeorm.config.ts
Runtime and wiring
- Express configuration
src/config/express.config.ts - Dependency container
src/container/index.ts - Application bootstrap
src/index.ts
Other components
- API client
- MySQL
Connections 24
- API client → Test routes: sends request
README.md - Express configuration → Test routes: mounts routes
- Test routes → Test controller: dispatches
- Test controller → Create DTO: validates input
README.md - Test controller → Test services: calls
- Test controller → Result responder: formats result
README.md - Result responder → Response DTO: returns DTO
README.md - Express configuration → API-key middleware: protects routes
README.md - Express configuration → Error handler: registers handler
README.md - Error handler → Domain errors: maps errors
src/interfaces/middlewares/error.handler.middleware.ts - Test services → Generic services: extends
src/application/services/TestServices.ts - Generic services → Test repository: delegates CRUD
README.md - Test services → Unit of Work: runs transaction
src/application/services/TestServices.ts - Unit of Work → Test repository: provides repositories
README.md - Test services → Test entity: creates entity
src/application/services/TestServices.ts - Test repository → Generic repository: extends
src/infrastructure/repositories/TestRepository.ts - Generic repository → TypeORM database: queries via ORM
src/infrastructure/repositories/GenericRepository.ts - TypeORM database → MySQL: connects to
README.md - Application bootstrap → TypeORM database: initializes
src/index.ts - Application bootstrap → Dependency container: builds bindings
src/index.ts - Dependency container → Test services: registers service
src/container/index.ts - Dependency container → Test repository: registers repository
src/container/index.ts - Dependency container → Unit of Work: registers unit of work
src/container/index.ts - Application bootstrap → Express configuration: starts server
src/index.ts