liveBook · Manning

Four-layer architecture

As explained in Grokking Software Architecture

A four-layer architecture organizes an application into presentation, application, domain, and infrastructure layers with distinct responsibilities and dependencies.

Four-layer architecture separates an application’s responsibilities into Presentation, Application, Domain, and Infrastructure. It applies separation of concerns across the application, so each layer has a clearer job. section 4.2.3 section 4.10

Think of the layers as four different kinds of work:

  • Presentation shows information and captures user input; it does not own the underlying business rules. section 4.2.3
  • Application coordinates use cases, including calls to domain objects or services and transaction handling. section 4.2.3
  • Domain holds the business rules, logic, and state, independently of presentation and storage. section 4.2.3
  • Infrastructure handles external concerns such as database access, email, and third-party services. section 4.2.3

A layer may start as one broad bucket, but split it when it becomes a junk drawer, teams keep colliding in the same files, or no one can tell where a rule belongs. The goal is clearer responsibilities, not layers for their own sake. section 4.2.3

/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

The project tree maps folders such as /app/, /services/, /domain/, and /repositories/ to the four layers. section 4.4.1

Folders are one way to represent layers; siblings within a layer should stay decoupled. For example, database and email components can both belong to Infrastructure without depending on each other—the Application Layer can coordinate their work. section 4.4.1

How Grokking Software Architecture covers it

How deep it goes
Defines four layer responsibilities and maps them to project folders, while naming dependency and cross-cutting concerns without detailing their implementation.
Examples
Uses a project-folder layout with UI, controllers, services, domain objects, repositories, and external-service code.
What you can do after
Evaluate/understand layer responsibilities and identify when blurred responsibilities may warrant splitting a layer.
How it connects
Connects separation of concerns with logical layers, physical tiers, dependency rules, cross-cutting concerns, and rich domain models.

Also explained in

Compare how 2 books explain four-layer architecture →

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.