The domain layer is the heart of an application: it holds core business knowledge, rules, logic, and state. It represents the business independently of how the application is presented or how its data is stored. section 4.2.3
In a four-layer architecture, the domain layer sits between application orchestration and infrastructure details:
- Entities, value objects, and domain services hold business concepts and behavior. section 4.2.3
- The application layer coordinates use cases and calls domain objects or services; it does not hold the core business rules itself. section 4.2.3
- Infrastructure handles technical details such as databases and external services. Keeping it separate lets storage implementations change without requiring the application layer to notice. section 4.2.3 section 4.8.3
Sort components by why and how
When deciding where a component belongs, ask whether it handles the business “why” or a technical “how.” Business logic belongs in the domain; database access and email clients belong in infrastructure. section 4.4.1 section 4.9.2
/my-project/src/
/api/ # Application Layer (part 1)
controllers.js
routes.js # Handles HTTP, validation, calls service
/app/ # Presentation layer
app.js # Main UI (React/Angular/Vue, etc) code
Index.html
/domain/ # Domain Layer
order.js
widget.js # Widget class with business logic
/lib/ # Infrastructure Layer (part 2)
emailClient.js # Other external services
/repositories/ # Infrastructure Layer (part 1)
widgetRepository.js # Database code
/services/ # Application Layer (part 2)
orderService.js # Orchestrates the “create order” use case
widgetService.jsSee a project-folder example mapping domain, application, presentation, and infrastructure components to their layers. section 4.4.1




