/design-patterns:anti-corruptionfrom design-patterns
Use when external system types, vocabulary, or conventions bleed into your domain model, a single provider change would require touching many internal files, or a legacy system must keep running while a new one is built alongside it. Apply before writing any integration with an external API, legacy codebase, or third-party service. Covers Anti-Corruption Layer, Gateway, Facade, and Strangler Fig.
Ships in design-patterns. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Sources: Eric Evans — Domain-Driven Design (2003); Martin Fowler — PoEAA (2002), Refactoring (1999)
External systems have their own models, terminology, and constraints. Without an explicit translation layer, external concepts leak into your domain — corrupting it with foreign vocabulary, shapes, and assumptions. These patterns prevent that leakage.
An explicit translation layer between your domain model and an external system's model. Your domain never sees the external model directly.
Pain it removes: external types and vocabulary bleeding into domain code; domain logic breaking when an external API changes its response shape.
When to use: integrating with a legacy system, third-party API, or another bounded context using different concepts for the same things.
# External payment API — their vocabulary, their types
class StripeClient:
def create_payment_intent(self, amount_cents: int, currency: str) -> dict:
... # returns Stripe's response structure
# ACL — translates between domains; lives in infrastructure layer
class PaymentGatewayACL:
def __init__(self, stripe: StripeClient):
self._stripe = stripe
def authorize(self, money: Money) -> PaymentAuthorization:
# Translate YOUR domain type → external format
response = self._stripe.create_payment_intent(
amount_cents=int(money.amount * 100),
currency=money.currency.code.lower()
)
# Translate external response → YOUR domain type
return PaymentAuthorization(
id=PaymentId(response['id']),
status=self._map_status(response['status']),
authorized_at=datetime.utcnow()
)
def _map_status(self, stripe_status: str) -> PaymentStatus:
mapping = {
'requires_capture': PaymentStatus.AUTHORIZED,
'succeeded': PaymentStatus.CAPTURED,
'canceled': PaymentStatus.VOIDED,
}
return mapping.get(stripe_status, PaymentStatus.UNKNOWN)
Rules:
Encapsulates access to an external system or resource behind an interface that your domain defines. Hides the external system entirely, not just translating its model.
Pain it removes: business logic coupled to the specifics of an external service; inability to test business logic without calling the external system; difficulty swapping providers.
When to use: you want to decouple your application from external service specifics; you want swappable implementations (real, stub, test double); you want to prevent provider-specific concerns from leaking into business logic.
# Your domain defines the interface — it owns the vocabulary
class EmailGateway:
def send_order_confirmation(self, order: Order) -> None: ...
def send_password_reset(self, user: User, token: ResetToken) -> None: ...
def send_payment_failed_notice(self, subscription: Subscription) -> None: ...
# Infrastructure satisfies it — using SendGrid, SES, Mailgun, etc.
class SendGridEmailGateway(EmailGateway):
def send_order_confirmation(self, order: Order) -> None:
self._client.send(
to=str(order.customer_email),
subject=f"Order #{order.id} confirmed",
template_id=self._config.order_confirmation_template,
data={'order_number': str(order.id), 'total': str(order.total)}
)
# Test double — no external calls, full verification
class RecordingEmailGateway(EmailGateway):
def __init__(self):
self.sent: list[tuple] = []
def send_order_confirmation(self, order: Order) -> None:
self.sent.append(('order_confirmation', order.id))
Testing benefit: swap the real gateway for a recording double in tests — no external calls, full verification of what was sent and to whom.
Provides a simplified interface to a complex external subsystem or integration. Reduces the knowledge required to use the integration correctly.
(See also: structural skill for Facade in internal subsystem contexts)
When to use: an external integration requires multiple steps that must be called in sequence; you want to expose a single, safe entry point for the common cases.
class ReportingFacade:
"""Hides the complexity of the reporting pipeline from callers."""
def generate_monthly_summary(
self, tenant_id: str, month: YearMonth
) -> ReportUrl:
dataset = self._loader.load(tenant_id, month.start, month.end)
normalised = self._normaliser.normalise(dataset)
rendered = self._renderer.render(normalised, template='monthly_summary')
return self._uploader.upload(rendered)
Incrementally replaces a legacy system by routing traffic through a new implementation, gradually expanding the new surface until the legacy system can be retired.
Pain it removes: a legacy system that cannot be rewritten in one go; need to deliver value during migration; legacy must keep running throughout.
When to use: you cannot stop the world for a full rewrite; the legacy system must keep serving some traffic during migration; you want to prove the new system in production before fully committing.
# Phase 1 — proxy routes all requests to legacy
class OrderServiceProxy:
def get_order(self, id: str) -> Order:
return self._legacy.get_order(id) # 100% legacy
# Phase 2 — new system handles new-format IDs
class OrderServiceProxy:
def get_order(self, id: str) -> Order:
if id.startswith('ORD-'):
return self._new.get_order(id) # new format → new system
return self._legacy.get_order(id) # old format → legacy
# Phase N — legacy retired, proxy removed
Critical rule: the strangler proxy must be transparent to callers — same interface, same contract, same error semantics. Callers must not know which implementation served them.
Migration checklist:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub entelligentsia/skillforge --plugin design-patterns10 skills in this plugin
/behaviouralUse when behaviour varies across cases, accumulates conditionals, or needs to be decoupled, queued, undone, or observed. Apply when a method is growing if/switch branches, an algorithm differs per context, a pipeline needs flexible steps, or objects need to react to each other without tight coupling. Covers all 10 GoF behavioural patterns./cqrsUse when read and write performance requirements diverge significantly, complex reporting is painful through the domain model, or you need to scale reads and writes independently. Apply before splitting any command/query handler or building read-optimised projections. Covers Command Query Responsibility Segregation — including when it is overkill — with guidance on applying only as much separation as the problem demands./creationalUse when object creation is the source of pain — constructors growing too complex, the same setup repeated, unclear which concrete type to instantiate, or a shared instance causing hidden coupling. Apply before writing any factory, builder, or instantiation logic. Covers all 5 GoF creational patterns: Singleton, Builder, Factory Method, Abstract Factory, Prototype./data-accessUse when persistence logic bleeds into domain or business code, tests require a real database to verify business logic, ORM types appear in service or handler code, or switching storage would require touching domain classes. Apply before writing any database query, repository, or ORM integration. Covers Repository, Unit of Work, Data Mapper, and Active Record with explicit guidance on when each applies./domain-eventsUse when aggregates need to stay loosely coupled, side effects (emails, audit logs, projections) are tangled into domain operations, or one aggregate directly calls methods on another. Apply when something significant happens in the domain that other parts of the system need to react to without being tightly coupled. Covers Domain Events, publishing patterns, synchronous vs asynchronous handling, idempotency, and eventual consistency trade-offs./domain-modelingUse when business objects have no behaviour (anemic model), invariants are enforced in services or controllers instead of domain classes, ownership of business rules is unclear, or the code allows states the business forbids. Apply before designing or reviewing any business domain class. Covers DDD tactical patterns: Entity, Value Object, Aggregate, Aggregate Root.Other plugins' skills for the same job