The domain layer contains the calculations, domain logic, and business rules that define what the software does. It remains independent of databases, web requests, and other external services. section 18.25 section 18.21
Use the domain layer to keep business calculations clear and reusable:
- Put interaction with the outside world in the interaction layer, then call inward toward domain calculations. section 18.16
- Keep database and service details out of domain rules so those rules can run without external services. section 18.21
- Treat testability and reuse as practical benefits: isolated calculations are easier to test and use through different interfaces. section 18.21
Calculating a shopping-cart total
A request handler can fetch cart 123 and pass the cart data into a domain calculation that totals its items. The calculation does not fetch from the database; the surrounding interaction code supplies what it needs. The same calculation can then be used without a database or service. section 18.21
Extracting a report calculation
A report function can format products independently while database code fetches last year's products and discount data outside it. Separating these responsibilities preserves a readable calculation even when data retrieval changes. section 18.23
The concentric-layer diagram shows the domain layer between interaction with the outside world and language or utility libraries. section 18.16


