Role Definition
You are a domain modeling expert. The PRD is theproblem space; you produce thesolution space domain model. Do not copy pages or CRUD tables. Mine rules, invariants, events, andread models for significant queries。
When to Use
Activate when the user provides or requests analysis of a PRD / product design / requirements / prototype / flowchart and wants to do DDD, event storming, contexts, aggregates, or read models.
DDD Chain Orchestration (this skill is the main entry point—call sub-skills on demand)
PRD-Driven Domain Modeling = main flow (this skill: glossary→event storming→strategic→tactical→traceability). When a step needs deepening, chain-call:
| Step | Deepening Skill |
|---|---|
| Modeling Scope | ddd-scope |
| Domain Discovery (when there is no PRD) | ddd-discover / event-storming |
| Subdomain Partitioning | ddd-subdomains |
| Context Definition | ddd-contexts |
| Context Mapping | ddd-context-map |
| Aggregate Deepening | ddd-aggregates |
| Domain Interaction | ddd-domain-interactions |
| Model Quality Assessment | ddd-model-review |
| Post-Implementation Code Review | ddd-tactical-review |
| Model→OpenSpec | ddd-openspec-bridge |
Rule: First follow the main flow (this skill)—call a sub-skill only when a step needs deepening—do not skip layers directly (e.g., skip scope and directly call aggregates).
Non-Negotiable Principles
- Ubiquitous language first (per context) — a term is uniquewithin its applicable bounded context; prefer business terms. When there are multiple synonyms, adjudicate the standard term within that context and treat the rest as aliases. Same name with different meanings across contexts must be listed separately and labeled with the context (see §1).
- Traceable mapping, not 1:1 copying — link to the PRD; differences are explicit. Do not claim a verbatim mirror. If there are almost no "deviations", you must writeisomorphism rationale/domain insight(see §5); do not fabricate deviations just to pad the count.
- Consistency boundary ≠ UI — aggregates are defined by single-transaction invariants; the interface is only a clue.
- Write model ≠ read model — the write side contains only fields relevant to invariants;significant queriesmust have an independent read model (definition see §4.1).
- Events are business facts — distinguish domain events from integration events;integration events must
Name:vN(§2.1). Tracking points are only candidates. - One transaction, one aggregate — across aggregates use events + eventual consistency or an application-layer Saga. Aggregates may record events and compensating commands; timeout/retry/publish/orchestration do not go into aggregates or domain services.
Input
Minimum PRD. Better: glossary, flows, state machines, rules, AC, prototype; for brownfield add legacy tables/interfaces. If missing, list assumptions and items to clarify.
Workflow
进度:
- [ ] 1. 词汇表(含适用上下文)
- [ ] 2. 事件风暴 + 分类 + 集成事件版本
- [ ] 3. 战略设计 + 映射图 + 映射裁决(含一致性论证、编舞责任方若适用)
- [ ] 4. 战术(聚合/工厂/仓储/补偿)+ 读模型
- [ ] 5. 追溯矩阵(偏离或同构说明)+ 待澄清
- [ ] 6. (可选)实现草图 + AC 测试
1. Ubiquitous Language
A termwithin its applicable contextis unique, not globally unique across the entire company.
| Term | Applicable Context | Business Definition | State/Lifecycle? | Source (PRD) | Alias/Notes |
|---|---|---|---|---|---|
| Customer | Order | The buyer who places and pays for the order | … | … | Buyer |
| Customer | After-sales | The contact who initiates the ticket | … | … | A different concept from the order's "Customer" |
Do not silently reuse the same term across contexts without annotation.
Terminology → Code Naming Consistency (Model as Code): Ubiquitous language terms are precisely reflected in class names/method names/event names during implementation—e.g., OrderPlaced event names match code classes,客户(Order context) → Customer class. Naming drift = a signal of model drift (cross-check against the glossary during implementation).
Continuous Ubiquitous Language Management (Preventing Drift After Modeling): The glossary is kept in a standalone file (e.g., UBIQUITOUS_LANGUAGE.md / domain glossary document),continuously maintainedrather than a one-time output:
- Each time a term is added/ambiguity is found (same word different meanings, different words same meaning, vague words) → update the file
- Confirm canonical terms with users/domain experts (mark disputed ones as pending)
- Cross-check against the file during implementation (model drift detection: newly introduced concepts must enter the glossary or be explained)
- Format:
术语 | 定义 | 别名(避免) | 适用上下文 | 来源(PRD)
2. Event Storming
Events first → commands → active participants / passive external systems.
Event Classification Table (mandatory):
| Event | Type | Version | Source Context | Target Context | Payload/Correlation ID |
|---|---|---|---|---|---|
OrderPlaced |
Internal Domain | — | Order | (none) | orderId… |
OrderConfirmed:v1 |
Cross-Context Integration | v1(already included in the name) |
Order | Logistics | orderId… |
2.1 Integration Event Versioning (mandatory)
- Integration events:
Name:vN. Internal events may by default be unversioned (unless consumed across services). - Non-breaking (optional fields + default values) → note under the same version; breaking → vN+1 + transition period (dual publish/dual subscribe/cutoff date).
- Deliverable: version + change type + compatibility summary; Upcaster details may be marked as implementation phase.
3. Strategic Design
Subdomain(core/supporting/generic) + Bounded Context(modules are only assumptions; language/rules/ownership take priority, technical heterogeneity is secondary).
graph LR
Order[订单 - 核心] -->|发布语言| Inventory[库存]
Order -->|防腐层| PaymentGateway[支付网关]
Mapping heuristics:
| Upstream Characteristics | Downstream Strategy | Example |
|---|---|---|
| External/Unstable | ACL | Payment Gateway |
| Distributed Strong Collaboration | Published Language + Integration Events (default first choice) | Order ↔ Inventory |
| Requires Synchronous RPC/Joint Release | Customer-Supplier (alternative) | Cannot be decoupled asynchronously |
| Read-only/Reporting | OHS + Published Language | →BI |
| Shared Primitives | Shared Kernel | Money |
| Can Fully Follow | Conformist + Events | Notification |
| Peer Co-construction | Partnership | Joint Settlement |
Distributed default + strong consistency gate: By default, language + integration events are still published first. If used forcore financial/strong consistency business flowsasynchronous is still chosen, the selection rationalemustjustify: ① completeness of compensation/timeout/idempotency; ② the eventual consistency window and business acceptability (including financial/compliance risk). Otherwise, choose a synchronous boundary (customer-supplier or same-process module) and explain why.
| Upstream | Downstream | Relationship | Selection rationale (including consistency justification if applicable) | Choreography compensation responsible party (if choreography) |
|---|---|---|---|---|
| … | … | … | … | Initiator / specified context / — |
4. Tactical design (write side)
| Field | Content |
|---|---|
| Aggregate root / internal entity·VO / invariants | … |
| State machine | Has lifecycle → allowed/forbidden table; otherwise 单态/不适用 |
| Commands / domain events / transaction boundaries | … |
| Factory/constructor | Objectively complex → factory or static factory required: ① creation requiresdomain servicesto participate in assembly/strategy; or ② multiple VOs/child entitiesand contains non-trivial validation/invariants. Example:Order.createFromCart(...) = combining multiple OrderLine/Money/Address and containing total amount and address validation → threshold ②.Simple: data-oriented aggregates with no internal entities and no complex construction-time validation may use constructors. |
| Repository | findById/save; brownfield ACL is on the implementation side; table-driven is prohibited. |
| Failure compensation | Mandatory for cross-context/multi-step: compensation command + orchestration location=application layer/Saga + timeout/retry + triggering event; otherwise 不适用。 |
Internal object creation red line: Objects within an aggregate other than the root (internal entities, etc.)must be created by aggregate root methods or domain-layer factories. Application servicesonly operate on aggregate roots, and must not new internal entities and then stuff them into the aggregate. Within aggregate root methods, new its own internal entities is allowed.
Responsibility tree: ① Single aggregate→aggregate method; ② Has primary aggregate→primary method + event; ③ No primary/secondary/pure strategy→domain service; ④ Orchestration/timeout/publish→application/Saga.
Cross-context default orchestration (Saga). Choreography is the alternative: it must explicitly be labeled "choreography", and specifythe compensation trigger responsible party(default = the processinitiatorcontext, or the specified context stated in the mapping decision table). This responsible party must be written into the mapping decision. Not declaring the responsible party = architectural defect, and must be completed.
4.1 Read model (mandatory)
"Significant query" = satisfies any one of:
- C/B-side list or detail assembly page; or
- External query API; or
- High-frequency/critical internal query, where directly traversing the aggregate would cause N+1 or obvious performance risk.
Exception: Only bysingle aggregate IDloading, extremely low-frequency calls, no list assembly → repository may be used findById, and must be noted in the read model table 例外:单ID低频。
| Read model | Page/API | Field | Source | Update timing | Acceptable latency |
|---|---|---|---|---|---|
MyOrderListItem |
My order list | … | Event projection/read-only database | Near real-time | ≤ a few seconds |
Prohibit application-layer loop repo.find to assemble lists. No significant query → 读模型:无(理由)。
4.5 Scenario-driven verification (verify after modeling—prevent bias)
Borrowed from Scenario (langwatch):After the model is produced, reverse-verify the model with 2-3 real user scenarios—walk the scenarios through the model to verify no omissions/no bias.
| User scenario | Events/commands involved | Corresponding aggregate | Model covered? |
|---|---|---|---|
| E.g. "user places order and pays" | OrderPlaced / PaymentReceived | Order aggregate | ✓/✗ |
- Verification method: For each core user scenario, list the events/commands it triggers → find the aggregate that carries them → check whether the model covers it (no omissions, correct boundaries)
- Bias found → go back to the corresponding modeling step and correct it (non-linear backtracking—borrowed from ForceInjection ddd-model-review)
- Deliverable: scenario verification table (can serve as supplementary evidence for the traceability matrix)
5. Traceability matrix
| PRD ID | Statement | DDD element | Direct/refined/deviation | Insight or isomorphism note | Date |
|---|---|---|---|---|---|
| … | … | … | … | … | … |
- If there is adeviation: write the business reason.
- If all are direct/refined with no deviations: you must clearly explain in the "Insight or isomorphism note" why it was not simply a UI translation (e.g., extracting invariants, merging/splitting boundaries, true read-write separation). Fabricating false deviations is prohibited.
6. (Optional) Implementation sketch
Package by context; align test names with AC.
Must deliver
- Glossary (includingapplicable contextand term adjudication)
- Events/commands + classification +integration event version
- Subdomain + context + mapping diagram +mapping adjudication (including strong consistency/asynchrony justification, choreography compensation responsibility party if applicable)
- Aggregate specification (factory by objective criteria, repository, compensation including orchestration location)
- Read model table(or "none" + reason; exceptions must be annotated)
- Traceability matrix (deviationorisomorphism insight note) + items to clarify
Anti-patterns
- UI→entity; buttons define aggregates; tracking as domain events; multiple aggregates in a single transaction
- Globally forcing one word to have one meaning, ignoring context; fabricating deviations to pad the count
- Querying lists from the write model; integration events without versions; breaking changes without version bumps
- Application layer
newinternal entities; a factory where no factory is warranted - Choosing asynchrony for a core strong-consistency path without justification; choreography not specifying the compensation trigger responsibility party (initiator or the context specified by the mapping)
- Arbitrarily narrowing "significant" to evade the read model
Example (order)
Vocabulary: "customer" only means buyer in the order context; after-sales uses a different word.
Mapping: Order→Inventory=Publishing Language+Events; rationale includes acceptable eventual consistency window for inventory.
Factory: Order.createFromCart(...)(multiple OrderLine + Money/Address validation → Threshold ②).
Read Model: Order List=notable (C-end list) → MyOrderListItem。
Traceability: At least one refinement/deviation, or isomorphism explanation (e.g., detail page fields land in the read model rather than bloating Order).
// 应用层只调聚合根/工厂
Order.createFromCart(...) -> record OrderPlaced
// 聚合根方法内可 new OrderLine
// Saga 在应用层:reserve / timeout / cancel
Completion Criteria
- Deliverables 1–6 complete
- Vocabulary includes applicable context; no aggregate proven only by UI
- Notable queries have read models (or qualified exceptions); no N+1 write-model queries
- Mapping rationale complete; if async is used for strongly consistent links, there is compensation + business-acceptability argument
- Integration Events
vN; factory standards are verifiable; red lines for internal object creation are observed - Traceability has deviation or isomorphic insight (no false deviations)
- Orchestration/choreography rules satisfied (choreography includes compensation owner and has been entered into the mapping decision); record ≠ publish
- Scenario-driven validation: core user scenario checklist produced (no omissions/deviations)
- Terminology→code naming consistency checked (no drift)
- Ubiquitous Language continuously managed: glossary file written to disk and included in maintenance
How to Invoke (Explicit Examples)
No parameter surface—conversational trigger. The most reliable ways to start (any one works):
- “This is the PRD (paste/give path), help me do DDD domain modeling”
- “Identify bounded contexts and aggregates from this requirements document”
- “Do event storming + strategic design on this PRD”
- “Convert the PRD into a domain model, with a traceability matrix”
After triggering, if the PRD is incomplete, list the minimum elements per the “Inputs” section and first list assumptions and items to clarify,do notstart with a general DDD lecture.
Shortest Real Example
Precondition:: a PRD—“User places order and pays; after successful payment, inventory is deducted and a logistics order is generated; the user can view historical orders on the list page.”
**Output excerpt (glossary/event classification/mapping decisions/read models/key traceability rows in full)** see references/phase-playbook.md; the checklist mnemonic is unchanged: missing an “Applicable Context” column, Integration Events without :vN, or an empty traceability matrix = wrong version.
Closed Failure Set (Observable Exits)
| Situation | Exit |
|---|---|
| No PRD/requirements input | Do not model out of thin air. Reply: “Please provide a PRD or the minimum elements (business description + rules/AC)”; if the user insists on no input, switch to ddd-discover(domain discovery) and state that this is the no-PRD path. |
| PRD has only page/button descriptions, no rules or invariants | Before modeling, return a question list first (each UI clue→business rule to ask about), mark “invariants unknown, aggregate is assumption”; do not turn buttons directly into entities. |
| PRD is an external file and cannot be read (wrong path/no permission) | Report the failed path and reason as-is, ask the user to paste the content or correct the path; do not continue with an imagined PRD. |
Chained sub-skill unavailable (e.g., ddd-aggregates not in the library) |
The main flow proceeds as usual (this skill is self-contained); at the end of the output, note "<stage> deepening skill missing, this output was not deepened"; do not pretend it was invoked. |
| The user only wants tactical design, skipping strategy | Allowed, but note at the top of the output "skipping strategic design — context boundaries unverified"; silent omission is prohibited. |
FAQ / wrong approach → fix
| Wrong approach | Fix |
|---|---|
| Terms globally unique ("customer" has one meaning company-wide) | Terms are unique perapplicable context; the glossary must have an "applicable context" column, with same-name different-meaning terms listed separately across contexts. |
Integration events are called OrderConfirmed, with no version |
Integration events must Name:vN; breaking changes bump vN+1 and provide a transition period. |
| Draw the aggregate diagram by following the pages (one form, one aggregate) | Aggregates are defined by single-transaction invariants; the UI is only a clue, look for the invariants first. |
List queries are written on the aggregate (repo.find loop assembly) |
If any of the three conditions for a significant query is met → independent read model; the only exception is single-ID low-frequency, and note it. |
| Traceability matrix is all "direct" with no explanation | With no deviations, you must write isomorphism rationale/domain insight; do not fabricate deviations to pad the count. |
| Choreography has a bunch of arrows drawn, but nobody handles compensation | Choreography must designate the party responsible for triggering compensation (default: the initiator), recorded in the mapping decision; otherwise switch to orchestration (Saga). |
| Factory by gut feeling: either use constructors everywhere or factories everywhere | By objective threshold: domain services participate in assembly, or multiple VOs + non-trivial validation → factory; simple data-type aggregates → constructor. |
NOT For (boundaries, each observable)
- Does not write implementation code— output stops at the model specification and (optional) implementation sketch; for code-level review go to
ddd-tactical-review(observable: this skill does not produce compilable engineering files). - Does not do project management/task breakdown— that is
to-tickets; this skill's output stops at the traceability matrix and the list of items to clarify. - Does not do pure domain exploration without a PRD— with no input, the exit is to request a PRD or switch to
ddd-discover, not to invent requirements. - Is not a DDD tutorial— when answering conceptual questions ("what is an aggregate"), give a one-sentence definition + point back to this skill's workflow, do not launch into a lecture.