liveBook · Manning

Domain layer

As explained in Grokking Software Architecture

The architectural part of an application that contains core business knowledge, rules, logic, state, entities, value objects, and domain services.

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.js

See a project-folder example mapping domain, application, presentation, and infrastructure components to their layers. section 4.4.1

How Grokking Software Architecture covers it

How deep it goes
Defines its contents and boundaries, but offers little implementation detail beyond naming entities, value objects, and services.
Examples
Uses Order and Customer entities, a Widget class with business logic, and a project /domain/ folder.
What you can do after
Evaluate which components express business logic and which handle technical infrastructure.
How it connects
Connects to layered architecture, the application and infrastructure layers, entities, value objects, and domain services.

Also explained in

Compare how 5 books explain domain layer →

Related concepts

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