DDD — Domain Model
This guide is split into three parts, and you are on Short info. Continue with the tutorial or browse the samples.
Summary
Section titled “Summary”DDD answers: what business concepts and rules must remain consistent?
When to use it
Section titled “When to use it”Use it when the system has rules such as “a booking cannot exceed capacity” or “a shipped order cannot be cancelled.” Start with one aggregate, its vocabulary, and one invariant. Keep persistence and screen layout in their own models. A small CRUD feature may need only a simple data model until its business rules become more demanding.
Common mistakes
Section titled “Common mistakes”- Choosing an aggregate solely because several tables have foreign keys.
- Giving Booking and Inventory competing authority over the remaining-seat count.
- Treating a generated scaffold as evidence that a concurrent reservation is safe.
Background and history
Section titled “Background and history”Domain-Driven Design was popularized by Eric Evans’s book and treats collaboration with domain experts as part of software design. Its vocabulary includes bounded contexts, entities, value objects, aggregates and a ubiquitous language. The ContextBrew DDD format concentrates on explicit domain structure, invariants and events; it is a representation of part of DDD, rather than the entire practice. See Eric Evans’s DDD resources for the underlying method.
An aggregate groups state that must obey a consistency boundary. Choose that boundary from the business transaction, then describe valid changes. A database foreign key or a box around related nouns is not enough to justify an aggregate. Review invariants with an example that should succeed and another that should be rejected. Generating a test scaffold records an obligation; a real implementation and test run supply evidence that it is met.
Alternatives and trade-offs
Section titled “Alternatives and trade-offs”Use an ER diagram or DSM for storage structure, a transaction script for simple operations, or ESDM when event history and projections are central. A Context Map complements tactical aggregates with relationships between bounded contexts.
References
Section titled “References”- Eric Evans’s DDD resources
- Learning with models — choose a practice workflow and interpret its results.
What DDD Captures
Section titled “What DDD Captures”The DDD model contains four core element types:
- Aggregates – the primary entities in your domain (e.g.,
Order,Customer,Booking) - Properties – typed fields on aggregates (e.g.,
status:OrderStatus,total:Decimal) - Invariants – business rules that must always hold (e.g., “status cannot transition from COMPLETED to CANCELLED”)
- Domain Events – things that happen in the domain (e.g.,
OrderPlaced,PaymentReceived)
Aggregates can also have associations (relationships to other aggregates) and value objects (immutable composite types like Money or Address).
Relationships to Other Models
Section titled “Relationships to Other Models”- USM – Each aggregate links to the user stories that involve it
- CBRL – Invariants are referenced by formal requirements via
INVOLVES_AGGREGATE - SCM – Screens are linked to the aggregate they manage
- DSM – Tables are auto-proposed from aggregates (invariants become CHECK constraints, properties become columns, associations become foreign keys)
Next Steps
Section titled “Next Steps”- USM Model to define user stories that connect to your aggregates
- CBRL Model to write formal requirements referencing your aggregates
- DSM Model to see how aggregates map to database schemas
File format (JSON Schema)
Section titled “File format (JSON Schema)”The serialized DDD model (models/ddd.json inside a .ctxbrew archive) is validated by a normative JSON Schema generated from ContextBrew’s source code. Every field, its type, and the canonical schema URL are documented on the DDD file schema page — or print the schema anywhere with ctxbrew schema ddd.
