liveBook · Manning

Application layer

As explained in Clean Applications with Hexagonal Architecture

A software layer that coordinates application operations and use cases above the domain layer.

When a controller reaches straight into a repository and returns a domain entity, API, persistence, and domain concerns become tangled. The application layer provides a thin boundary between external actors and the domain: it coordinates use cases, delegates business decisions to the domain model, and communicates outward through output ports. section 5.4.2 section 4.0

A use case exposes an input port to adapters such as REST controllers, message consumers, and CLI runners. Its handler orchestrates collaborators, including repositories, output ports, and domain services; it does not take over the domain’s business rules. Commands and queries can carry self-validating input and be routed through a bus. section 4.0 section 4.2.2 section 4.2.3

The use-case contract should make expected failure visible to its callers. A void command signature promises no returned data but says nothing about failure. Vavr’s Either<Error, R> puts the outcome in the return type; a command can use Void on the success side while returning an explicit error on failure. This keeps expected outcomes composable rather than hiding unchecked failures in exception control flow. section 4.0 section 4.2.2 section 4.2.3

Publishing an article

A publishing handler must account for an article that is missing, already published, or not owned by the requester, as well as an unavailable repository. If collaborators throw distinct exceptions, orchestration can become a series of try-catch blocks. A typed outcome gives callers one explicit contract for expected results. section 4.2.2

Across system boundaries, the domain still decides what is allowed. The application layer decides whether a domain fact becomes an integration event and what leaves the hexagon. Adapters own external formats and delivery mechanics; the application layer or domain sets the relevant policies. section 10.5

Table 10.2 Who owns what at the boundary
Concern
Owner
Rules
Business rules and invariants
Domain model
The domain decides what is allowed
The steps of a use case
Application layer
The handler locally orchestrates the steps and delegates decisions to the domain
What crosses the boundary
Application layer
It shapes the integration event from a domain fact; the domain never knows the fact left
Translation to and from the other system
Adapter
The adapter is the only place that knows the external format
Delivery mechanisms
Adapter for implementation; application layer or domain for policy
The adapter implements serialization, retries, timeouts, deduplication, and failure mapping; the application layer or domain sets the relevant limits and semantics
Sequencing across systems
External coordinator
It owns when and in what order, never what is allowed
Reading and writing domain state
Repository adapter
Domain state crosses a core-owned port; the mapping stays in the adapter

Use the ownership table to distinguish use-case orchestration from domain rules, adapter mechanics, and cross-system sequencing. section 10.5

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Explains handler responsibilities, typed failure contracts, and boundary ownership, including the consequences of bypassing the layer.
Examples
Uses article publishing failures and an article-reopening integration to illustrate orchestration and boundary decisions.
What you can do after
Evaluate/understand application-layer boundaries and identify responsibilities that belong in the domain or adapters.
How it connects
Connects use cases to hexagonal architecture, input and output ports, domain models, and integration events.

Related concepts

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