liveBook · Manning

Anticorruption layer

As explained in Clean Applications with Hexagonal Architecture

A translation boundary that protects a domain model from the concepts and representations of an external system.

When a service call brings another bounded context’s vocabulary and failures into a domain, translate them at the boundary. An anti-corruption layer (ACL) lets the consuming domain use its own model; it is an adapter, not a new domain layer, and contains no business rules. section 11.0 section 11.2

Put the translation on the side that consumes the foreign model:

  • When WriteFlow calls the author service, its outbound adapter translates the service response into the DTO declared by WriteFlow’s output port. section 11.2
  • When the partner CMS calls WriteFlow using WriteFlow’s contract, the CMS translates its own model. WriteFlow’s input adapter maps that contract to a command or query; this is ordinary input-adapter work, not an ACL. section 11.2
  • Map foreign failures too: for example, convert “not-found” to AuthorNotFound and remote failures or outages to DependencyUnavailable. section 11.4

Author validation

WriteFlow’s handler calls its output port with validateAuthor(authorId). The outbound adapter calls the author service, translates its response into WriteFlow’s port DTO, and returns errors in WriteFlow’s vocabulary. The handler sees the port’s model, not the service’s. section 11.4

Figure 11.1 The anti-corruption layer sits with the consumer of the foreign model. When WriteFlow calls a neighbor, the layer is on WriteFlow's side. When a neighbor calls WriteFlow, the layer is on the neighbor's side. The domain stays untouched in both cases.

Use the diagram to check which side owns translation: the consumer of the foreign model, not automatically the side receiving a request. section 11.2

Keep foreign types out of commands, queries, and domain objects. If one appears, correct the mapping at the boundary responsible for that data. section 11.4

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Explains adapter placement, response and failure mapping, and stops short of assigning business rules to the layer.
Examples
Uses WriteFlow author validation and a partner CMS reopening an article for review.
What you can do after
Apply the boundary by translating a neighbor’s response and failures before they reach a use case.
How it connects
Connects bounded contexts, domain models, output ports, and adapters.

Also explained in

Compare how 5 books explain anticorruption layer →

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.