Architectureacltranslation layer

Anti-corruption layer

Definition

An anti-corruption layer is a component on the downstream side of an integration that translates the upstream system's model, protocol and vocabulary into the downstream bounded context's own model.

In practice

Integrating with a legacy system or third party tempts you to use its types everywhere, after which every upstream change ripples through your code. An anti-corruption layer confines that model to one place: adapters, translators and facades that map between the two worlds.

It is one more component to build, test and keep in sync, and it adds a mapping step to every call. It pays off when the upstream model is messy, unstable or owned by someone else; for a clean, stable upstream, conforming to its model can be the cheaper choice.

Example

A PaymentProviderAdapter turns the provider's { status: "succeeded", amount_cents: 1999 } into the domain's PaymentCaptured(Money.Eur(19.99)), so no provider field names appear in the core.