Clean Architecture in Node
On this page
Core Principle
Clean Architecture centers around the idea that business rules should not depend on frameworks, databases, or UI. Dependencies must point inward toward the domain.
Dependency Rule
Outer layers (HTTP, database, frameworks) depend on inner layers (use cases, entities). Inner layers must not import infrastructure concerns.
Typical Structure
- Entities (domain models)
- Use cases (application logic)
- Interface adapters (controllers, repositories)
- Frameworks & drivers (Express, DB drivers)
Example Boundary
interface UserRepository {
findById(id: string): Promise;
}
The use case depends on the interface, not the database implementation.
Trade-Off
Clean Architecture increases abstraction and boilerplate. It is most valuable in long-lived, complex systems where domain logic must remain stable despite infrastructure changes.