A service layer is the conductor of an application use case: it receives a request, coordinates the work, and returns the result. Also called the application layer, it translates actions such as “create order” into domain operations and may handle transactions. It directs business work without owning the core business rules. section 4.2.3
Without clear boundaries, a controller can grow into a catch-all for HTTP handling, business rules, database access, and email. Keep HTTP concerns in presentation, orchestration in the service layer, business rules in the domain, and external details in infrastructure. A rich domain model keeps its rules testable in isolation. section 4.7.4 section 4.2.3
Create an order
A request to create an order reaches an application service. The service coordinates domain objects or services and any needed infrastructure work; the domain owns the business rules, while infrastructure handles details such as database access or sending email. If database and email components need to work together, the application layer can coordinate them rather than making those infrastructure siblings depend on each other. section 4.2.3 section 4.4.1
/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 one folder-based arrangement: services orchestrate use cases, domain objects hold business logic, and repositories and clients handle infrastructure. section 4.4.1
In the layered blueprint, commands and dependencies point downward; result data can flow back up. Lower layers should not initiate commands to higher layers. Infrastructure can supply concrete implementations of interfaces defined above it, helping keep external details out of the core. section 4.6.1 section 4.2.3
The boundary matters in production, too. A raw HTTP call buried in checkout logic couples the workflow to a library and URL while hiding risks such as timeouts, outages, and double charges. Inject a service rather than hardcoding the dependency, and make network assumptions and failure risks visible. Protect layer boundaries with automated architectural tests, such as a test preventing controllers from communicating directly with the database. section 10.4.1 section 4.7.4




