# Domain-Driven Design

**Also known as:** DDD  
**Category:** Design Approach (Modeling lens)  
**Complexity:** 4/5  
**Guide:** https://layra4.dev/architectures/design-approach/ddd

*Model the software around the business, in words everyone shares.*

Domain-Driven Design (DDD) is an approach to modeling, not a folder layout. Its claim: in software with real business rules, the hard part is understanding the domain, not the technology. So DDD puts the domain model at the center and builds everything else around it. The main cost is time: you need regular conversations with domain experts.

DDD has two halves, and each has its own category on this site. The strategic half draws the boundaries: the shared language, the bounded contexts, how they connect, and where to invest. The tactical half builds the model inside one boundary: entities, value objects, aggregates, repositories. Do the strategic half first. Most teams also get more value from it.

> **In one sentence.** Let the business domain drive the design, so the model in the code and the model in the experts' heads are the same model.

## Origin (2003)

Eric Evans introduced it in “Domain-Driven Design: Tackling Complexity in the Heart of Software”, the “blue book”. Vaughn Vernon's “Implementing Domain-Driven Design” (2013) made the strategic patterns and aggregate design more concrete.

## The strategic tools

### Ubiquitous Language

One shared vocabulary, built with domain experts and used everywhere: in meetings, code, tests and class names. It removes the translation step between how the business talks and how the code is written.

- One term, one meaning, inside one context
- Lives in the code, not only in a glossary
- Changes as your understanding of the domain grows

> Support says an order is “on hold”, so the code has order.hold(), not setStatus(4).

### Bounded Context

A clear boundary inside which one model and its words stay consistent. “Customer” in Sales and “Customer” in Support can mean different things. A bounded context makes that split deliberate instead of accidental.

- One consistent model per context
- Often maps to one team, service or module
- A term is guaranteed one meaning only inside it

> To Sales, a Customer is a buyer with a credit limit; to Support, a person with open tickets. Two models, not one.

### Context Map

A picture of how the bounded contexts relate: which one is upstream, which one conforms, and where an anti-corruption layer (a translation layer) protects a model from another one.

- Names each relationship: partnership, customer–supplier, conformist
- Shows where translation happens
- Makes integration an explicit design decision

### Core, supporting and generic subdomains

Not every part of the domain deserves equal effort. The core is where the business competes, so a rich model pays off there. Supporting parts are needed but ordinary. Generic parts, like login or payments, are best bought.

- Put the rich modeling in the core
- Keep supporting subdomains simple
- Buy or reuse a product for generic ones

## Applying it well

### Model with domain experts, not after them

Discover the language and the model in conversation with the people who know the domain. DDD is a way of working together first. The code records what you learned together.

### Spend the rich model on the core

Tactical DDD costs real time. Use it in the core subdomain, where the business competes. Elsewhere, a simple transaction script or a bought product is the better choice.

### Keep contexts small and boundaries firm

A model stays consistent only inside its bounded context. Do not share one model across the whole company. Guard each boundary and translate at the edges, for example with an anti-corruption layer.

### Let the language change the code

When the experts refine a term, rename it in the model and in the code. A ubiquitous language that the code ignores is only documentation, and it goes out of date.

## Diagrams

Rendered as geometry on the guide page; not reproducible as text.

- `ddd-halves` — see https://layra4.dev/architectures/design-approach/ddd

## Examples

### The two halves, in the order they are meant to be used

```typescript
// ── STRATEGIC: where the boundaries are, and whose language wins ──
// Sales and Support both say "customer" and mean different things, so
// each context keeps its own model rather than sharing one "Customer".
//
//   Sales  ──customer–supplier──▶  Shipping
//   Sales  ──anti-corruption────▶  Support    (the layer sits on Support's side)
//   (arrows point downstream, the way changes flow)
//
// That decision is made on a whiteboard with domain experts. Nothing
// below is worth writing until it is made.

// ── TACTICAL: inside ONE context, build the model out of blocks ──
// modules/sales/domain/order.ts — Sales's language, Sales's rules
export class Order {                    // an entity: identity over time
  private constructor(
    readonly id: OrderId,
    private lines: OrderLine[],         // value objects, no identity
    private status: OrderStatus,
  ) {}

  /** The business says an order is "placed", so the method is place(). */
  place(): void {
    if (this.lines.length === 0) throw new EmptyOrder();
    this.status = "placed";
  }
}
```

Strategic design decides where the boundary is and which words hold inside it. Tactical design fills that boundary in. Done the other way round, you build a rich model of the wrong thing.

## When to use

- The core domain has real business rules that keep changing
- Domain experts are available to build a shared language with
- Different parts of the business use the same words differently

## When not to use

- CRUD or data-entry software with little real domain logic
- Generic subdomains where a bought or open-source product already fits
- Short-lived code that will not repay the modeling effort

## Benefits

- The code uses the same model and the same words as the domain experts
- Bounded contexts make large systems and large teams manageable
- Effort goes where the business actually competes

## Costs

- A steep learning curve, and steady time with domain experts
- Easy to overuse: full tactical DDD on a CRUD subdomain is waste
- Wrong boundaries are expensive to fix later

## Pitfalls

- Tactical DDD without strategic design: aggregates everywhere, but no bounded contexts.
- One giant model for the whole company. The words blur, and every change touches every team.
- An anemic model: DDD class names, but all the logic still sits in service classes.
- A ubiquitous language that lives in a wiki while the code uses different words.

## Related patterns

- [Bounded Context](https://layra4.dev/architectures/strategic/bounded-context) — strategic: the boundary a model is consistent inside
- [Ubiquitous Language](https://layra4.dev/architectures/strategic/ubiquitous-language) — strategic: the shared words inside that boundary
- [Core / Supporting / Generic Subdomains](https://layra4.dev/architectures/strategic/subdomains) — strategic: where a rich model is worth the cost
- [Context Map](https://layra4.dev/architectures/strategic/context-map) — strategic: how the contexts connect
- [DDD Building Blocks](https://layra4.dev/architectures/tactical/ddd-building-blocks) — tactical: entities, value objects and aggregates in code

## Further reading

- *Domain-Driven Design: Tackling Complexity in the Heart of Software* — Eric Evans (2003) — The “blue book”. Part II covers the building blocks; Part IV covers strategic design.
- *Domain-Driven Design Distilled* — Vaughn Vernon (2016) — A short, readable introduction to both halves.
- *Learning Domain-Driven Design* — Vlad Khononov (2021) — A modern view, strong on subdomains and context mapping.
