What’s a bounded context
Bounded contexts encapsulate specific concepts, terminology, and rules relevant to a subset of the business domain, ensuring internal consistency. Different bounded contexts communicate through well-defined interfaces, minimizing confusion and ambiguity across the system.
We have a need for this in our workshop project! There’s a fancy UI for dragging and dropping plants into raised beds, just waiting for us to hook some data up to
We have an existing domain model that lives in our UI
This has nothing to do with gardening! Our UI entirely deals in a world of
- A
Workspace
which consists of multipleZone
s Zone
s have a grid whereItemPlacement
s are arranged- Each
ItemPlacement
relates to anItem
We’re about to create a gardening-related bounded context of our own, and there’s going to be some messy code we’ll have to write to adapt between the two
Anti-corruption layers
Anti-corruption layers in DDD are effectively well-contained adapters a bounded contexts and other models or external systems. We have the beginnings of one in our server’s routing layer. For example,
packages/server/src/application/plants-router.ts
adapts between ourPlant
entity and the HTTP response then endpoint needs to returnpackages/server/src/application/seed-packets-router.ts
adapts between ourSeedPacket
entity and a different HTTP response.
Anti-corruption layers help keep our domain services (e.g. packages/server/src/services/plants-service.ts
) clean and simple. They’ll be easy to unit test in isolation, and they deal exclusively in the entities that they’re associated with.