Best for
- Designing the database schema for a new system or major domain
- Documenting an existing schema that lacks formal specification
- Planning a schema migration or major refactoring
- Onboarding engineers to the data model of a complex system
What it produces
The generated document covers:- Overview — domain purpose, design decisions summary (PK strategy, soft delete, money types, charset)
- Entity-Relationship Diagram — Mermaid ERD for every table with columns and cardinality labels
- Table definitions — full DDL for both MySQL 8.x and PostgreSQL 16, including column types,
NOT NULLenforcement,CHECKconstraints, foreign keys, and all indexes - Data dictionary — plain-language description of every non-obvious column, nullable meaning, and lifecycle states
- Indexing strategy — hot query pattern table, index-per-query coverage analysis, composite index ordering, FK index checklist
- Normalization decisions — intentional denormalizations documented with rationale
- Constraints and data integrity — FK cascade behavior table, application-layer rules
- Sensitive data classification — encryption method, hashing strategy, retention policy per column
- Connection pooling —
pool_size,max_connections,pool_timeout,pool_recycle, leak detection - Database views — read-only query encapsulation for dashboards and admin UIs
- Multi-tenant data isolation — pattern (shared schema, separate schema, separate database) and
tenant_idenforcement - Backup strategy — full, incremental/WAL, schema-only, retention, and restore test schedule
- Migration plan — migration files table, risk analysis (lock contention, type changes), rollback scripts
- Alternatives considered
How to invoke it
Example scenarios
Multi-tenant SaaS billing
Payment gateway
Inventory management
Legacy documentation
Key concepts
Normalization — 3NF minimum, denormalize intentionally
Normalization — 3NF minimum, denormalize intentionally
- 1NF: Atomic values, no repeating groups
- 2NF: No partial dependencies on a composite key
- 3NF: No transitive dependencies — non-key columns depend only on the primary key
Money types — never FLOAT
Money types — never FLOAT
DECIMAL(19,4) (or NUMERIC(19,4) in PostgreSQL) for all monetary values.Indexing principles
Indexing principles
- Every foreign key column must have an index — without one, JOINs degrade to full table scans
- Columns used in
WHERE,JOIN ON, andORDER BYclauses of hot queries must be indexed - Composite indexes: most selective column first
- Never index low-cardinality columns (e.g., a boolean flag) in isolation
- Use generated stored columns for frequently queried JSON-extracted values
Migration plan — every migration needs a rollback
Migration plan — every migration needs a rollback
- A forward script (CREATE, ALTER, CREATE INDEX)
- A tested rollback script (
DROP TABLE,ALTER TABLE DROP COLUMN,DROP INDEX) - A risk assessment: which tables, estimated row count, lock contention strategy (e.g.,
pt-online-schema-changeorgh-ostfor large tables) - Destructive migrations (type changes, column drops) are validated on a staging copy before production
Partitioning strategy for large tables
Partitioning strategy for large tables
- Range partitioning — by
created_at; best for time-series data and audit logs; enables archival by dropping old partitions - Hash partitioning — by
tenant_idoruser_id; best for multi-tenant systems needing even distribution - List partitioning — by discrete category (e.g.,
region,status)
Multi-tenant isolation patterns
Multi-tenant isolation patterns
tenant_id filtering at the repository layer — never application-only filtering.Interview process
Phase 1: Socratic clarification (mandatory)
.engineering-docs/ files first. Up to 3 questions: access patterns (most frequent read/write operations) and data scaling (thousands vs. millions of rows per table). Answers feed directly into index design and partitioning decisions.Phase 2: Entity identification (40–60 min)
Phase 3: Relationship mapping (40–60 min)
Phase 4: Table definitions (1–2 hrs)
Phase 5: Data dictionary (40–60 min)
Phase 6: Query patterns and index validation (40–60 min)
Phase 7: Migration plan (40–60 min)
Phase 8: Revision (after user review)
last_updated.Output structure
The generated.engineering-docs/8-database-design-document.md follows this structure:
Handoff
Reads from
1-business-plan.md— problem domain, users, constraints3-user-personas.md— target users, usage patterns4-technical-specification.md— functional and non-functional requirements7-system-architecture.md— technology decisions, hosting constraints
Feeds into
9-api-design-document.md— data model that API resources map to11-admin-access-control-specification.md— entities that permissions govern14-technical-blueprint.md— schema referenced in feature designs15-implementation-plan.md— schema as Phase 0/1 foundation
Quality gate
- Every table has a primary key, all foreign keys,
NOT NULLconstraints, and appropriate data types defined - Every foreign key column has a corresponding index documented in the Indexing Strategy section
- The ERD matches the table definitions — every entity in the diagram appears in Section 3 and vice versa
- All intentional denormalizations are in the Normalization Decisions table with written justification
- Every migration has a tested rollback script and the Migration Risks table identifies lock contention and type-change risks
