liveBook · Manning

Anticorruption layer

As explained in Grokking Software Architecture

A boundary pattern that translates between an external system's model and an application's domain model to prevent external concepts from affecting the domain model.

An anticorruption layer is a protective translator at a system boundary. It converts an external system’s data into the application core’s language, keeping API details and database schemas from leaking into business logic. section 5.3.3

Without that boundary, the core can end up speaking a vendor’s language. In hexagonal architecture, an adapter can do the translation instead: incoming adapters convert outside requests for a core port, while outgoing adapters implement core ports to communicate with infrastructure. The dependency points toward the core, even when data flows outward. section 5.3.3

Figure 5.6 Adapters translate the messy language of the outside world (JSON, SQL) into the clean language of the Core, and back again.

The diagram illustrates adapters translating between external formats and the core’s language. section 5.3.3

An order at the boundary

An order controller unpacks a JSON HTTP request and calls the order service through a primary port. On the other side, a SQL order repository implements a secondary port and translates an Order object into database statements. These adapters keep transport and storage details outside the core. section 5.3.3

The boundary can also filter outgoing data. Before a payload leaves the backend, mask sensitive fields and limit it to what the recipient needs. Hiding fields in the user interface is not enough if the API has already sent the entire user object. section 11.7.1 section 11.6

Assign an owner to each external integration and document its threat model and mitigations in an architecture decision record. Revisit those decisions regularly and after major integration changes so the boundary does not quietly become outdated. section 11.7.1

How Grokking Software Architecture covers it

How deep it goes
Defines adapter translation and gives security guidance on masking and filtering, without a detailed layer implementation.
Examples
Uses an order controller, a SQL repository, and an API exposing a complete user object to illustrate boundaries.
What you can do after
Evaluate integration boundaries for external-model leakage and unnecessary data exposure.
How it connects
Connects domain-driven design, hexagonal architecture, ports and adapters, dependency inversion, and least privilege.

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 Grokking Software Architecture. The section links point to the parts of the book it draws on.