Skip to content

Domain Layer Separation

Domain layer separation puts business logic into a layer of its own. The domain layer is the heart of a bounded context (see Bounded Context). It should be well isolated from the other layers. This isolation is central to Domain-Driven Design (see Domain-Driven Design).

The layers around it

  • The presentation layer shows information to users and takes their input.
  • The application layer, also called the service layer, stays thin. The key logic lies in the domain layer, not here.
  • The infrastructure layer acts as a supporting library for the other layers.

Logical, not physical

These layers are logical layers, not physical tiers. You can split the code into layers without putting each layer on its own server.

Direction of dependency

Each layer should depend only on the layer below it.

Why it pays off

Separating presentation from domain logic lets you build several presentations on top of the same domain logic. You do not have to copy that logic into each one.

For the general idea of layers, see Layered Architecture.

An insurance company has a web portal and a mobile app. Both need the same rule for calculating a premium. The team keeps that rule in the domain layer. Both front ends reach it through a thin application layer. When the rule changes, the team edits one place. Neither front end holds its own copy.

The verified facts describe benefits, not costs. One caution follows from them: the application layer must stay thin. If key logic moves into it, the domain layer stops being the home of the business rules. Also remember that layers are logical. Drawing layers on a diagram does not by itself decide how the system is deployed.

Logical layers: the application layer stays thin and the domain layer holds the key logic.

Diagram source
flowchart TD
UI[Presentation layer] --> APP[Application layer - thin]
APP --> DOM[Domain layer - business logic]
APP --> INF[Infrastructure layer]
DOM --> INF
  • The domain layer is described as isolated from the other layers.
  • The application layer is thin and the key logic sits in the domain layer.
  • Each layer depends only on the layer below it.
  • Layers are described as logical layers, not as physical tiers.