DSM — Data Storage 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”DSM answers: how is information stored, constrained and retrieved?
When to use it
Section titled “When to use it”Use it when persistent data needs explicit types, keys, relationships, constraints or indexes. Start with one table, a primary key and a constraint that rejects a bad row. Reverse-engineering an existing schema is often a better first step than drawing it again. Storage decisions should support domain rules and access patterns without pretending to describe the whole domain.
Common mistakes
Section titled “Common mistakes”- Expecting a row-level constraint to solve a cross-row concurrency rule.
- Adding indexes without naming the query they support.
- Changing nullability without reviewing data already stored.
Background and history
Section titled “Background and history”Relational modeling has a foundational reference in E. F. Codd’s 1970 paper. ContextBrew’s DSM represents storage choices such as tables, columns, constraints, indexes and migrations. A broader explanation of relational concepts and hands-on SQL appears in the PostgreSQL tutorial.
Separate logical integrity from performance. A foreign key prevents a missing parent; an index may accelerate a query but does not establish a business invariant. Some invariants span rows or transactions and cannot be proven by a single column check. Record those in DDD/CBRL and use an appropriate implementation test. A schema diff shows a structural change; it does not prove a production migration preserves data or meets a latency target.
Alternatives and trade-offs
Section titled “Alternatives and trade-offs”An ORM schema keeps storage close to code; SQL DDL provides database-native precision; an ER diagram emphasizes entities and relationships. Use a document or other storage model when its access and consistency trade-offs fit the problem. Choosing a storage pattern compares those choices.
References
Section titled “References”- 1970 paper
- PostgreSQL tutorial
- Learning with models — choose a practice workflow and interpret its results.
What DSM Captures
Section titled “What DSM Captures”- Tables – database tables mapped from DDD aggregates
- Columns – typed columns with nullability, defaults, and length constraints
- Constraints – primary keys, foreign keys, unique constraints, CHECK constraints
- Indexes – performance indexes on frequently queried columns
- Migrations – versioned schema changes with up/down paths
Relationships to Other Models
Section titled “Relationships to Other Models”- DDD – Tables carry an
aggregatefield naming the owning aggregate; invariants map to CHECK constraints when schemas are derived from code (ctxbrew init --from-code) - CBRL – Requirements can reference table constraints they depend on
- SCM – Screens reference tables whose data they display
- USM – Stories involving data persistence link to the relevant tables
Next Steps
Section titled “Next Steps”- DDD Model to define the aggregates that drive DSM proposals
- SIM Model for modeling data flow across multiple services
- Travel Booking Tutorial to see DSM in a complete example
File format (JSON Schema)
Section titled “File format (JSON Schema)”The serialized DSM model (models/dsm.json inside a .ctxbrew archive) is validated by a normative JSON Schema generated from ContextBrew’s source code. See the DSM file schema page — or print the schema anywhere with ctxbrew schema dsm.
