liveBook · Manning

Hexagonal architecture

As explained in Unit Testing Principles, Practices, and Patterns

An architectural pattern that separates domain logic from application services and connects external applications through ports or common interfaces.

Hexagonal architecture organizes an application around business logic. A domain layer contains that logic, while application services coordinate use cases and communication with external applications. section 5.3 section 5.5

Apply three structural rules:

  • Keep domain classes responsible for business logic rather than external concerns. section 5.3
  • Direct dependencies from application services toward the domain; domain classes depend only on one another. section 5.5
  • Connect external applications through interfaces maintained by application services instead of exposing the domain directly. section 5.5

Purchasing through an application service

A purchase service retrieves a customer and product, invokes the customer's purchase operation with a store interface, and sends a receipt through an email gateway only after success. The domain remains separate from those external applications. section 5.3

Figure 5.8. A typical application consists of a domain layer and an application services layer. The domain layer contains the application’s business logic; application services tie that logic to business use cases.

Use the layer diagram to distinguish the domain's business logic from application services that connect it to business use cases. section 5.3

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines two layers, dependency direction, and interface boundaries, then demonstrates them through a purchase orchestration example.
Examples
Uses user renaming, customer purchasing, repositories, a store interface, and an email gateway as concrete artifacts.
What it assumes
Introduces domain layers, application services, external applications, and observable behavior while assuming basic object-oriented application structure.
What you can do after
Evaluate application boundaries and diagnose fragile tests by distinguishing external behavior from internal communication.
How it connects
Connects domain logic, application services, dependency direction, observable behavior, mocks, and test fragility.

Also explained in

Compare how 6 books explain hexagonal architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.