How rasouza/node-clean-architecture works
Project Type and Core Architecture
• Domain (Core Business Layer)
• Application (Use Cases)
• Ports/Adapters (Interface Adapters)
• Infrastructure (External Frameworks/Tools)
Main Components
A. Core Components (Inner Layers):
• Domain Layer
• User Entity (domain/User.js)
• Repository Interfaces
• Application Layer
• Use Cases:
• CreateUser
• DeleteUser
• GetUser
• ListUsers
• UpdateUser
B. Interface Adapters:
• HTTP Controllers (ports/http)
• UsersController
• Routes Handler
C. Infrastructure (Outer Layer):
• Database
• MongoDB Implementation
• Mongoose Schemas
• Web Server (Fastify)
• Repositories
• UserRepositoryMongo
• UserRepositoryInMemory (for testing)
Second Ring (Application Layer)
• Use cases around the domain
Third Ring (Interface Adapters)
• Controllers and routes
Outer Ring (Infrastructure)
• External elements (MongoDB, Fastify, etc.)
Important Elements to Highlight
A. Dependency Flow:
• Dependency Injection container (infrastructure/bootstrap/container.js)
B. Data Flow:
• Typical request flow:
1. HTTP Request → Fastify
2. Routes → Controller
3. Controller → Use Case
4. Use Case → Domain
5. Repository Interface → MongoDB Implementation
C. Cross-Cutting Concerns:
• Logging system (infrastructure/bootstrap/logger.js)
• Error handling (infrastructure/webserver/errors.js)
Technical Details
• Technologies:
• Fastify (Web Framework)
• MongoDB/Mongoose (Database)
• Awilix (Dependency Injection)
• Jest (Testing)
Additional Notes
• A small section showing the testing setup with UserRepositoryInMemory