liveBook · Manning

Domain layer

As explained in Grokking Simplicity

The architectural layer containing domain rules and calculations while remaining independent of external services.

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

Image

The concentric-layer diagram shows the domain layer between interaction with the outside world and language or utility libraries. section 18.16

How Grokking Simplicity covers it

How deep it goes
Defines layer boundaries and demonstrates extraction through examples, while stopping short of prescribing a fixed set of layers.
Examples
Uses shopping-cart totals, report generation, product discounts, database retrieval, and service protocols as concrete applications.
What you can do after
Apply it by extracting business calculations from database and web interactions for reuse, testing, and easier infrastructure changes.
How it connects
Connects domain logic with onion architecture, interaction layer, language layer, functional architecture, and external services.

Also explained in

Compare how 3 books explain domain layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Simplicity. The section links point to the parts of the book it draws on.