Tactical DDD — Rich Domain Modeling
Workflow
Determine the user's intent first:
Phase 1 — Detect
Load detection.md [blocked] and scan the target code for anemia signals. Produce a severity score and list of affected classes.
Phase 2 — Assess
For each affected class, determine the correct building block:
Prefer Value Objects over Entities. Prefer small Aggregates over large ones.
If intent was validate/review: stop here. Report findings using the output format below. Ask "Would you like me to apply these fixes?" before proceeding.
Phase 3 — Refactor
Load refactoring.md [blocked] for step-by-step moves. Apply in this order:
- Replace setter chains with a single expressive method
- Move service logic into the Aggregate that owns it
- Add business guards at the top of each method
- Publish a Domain Event after each successful state change
- Replace primitive types with Value Objects
For deep pattern questions (boundary design, event modeling, service vs. entity decision), load reference.md [blocked].
Quick Anemia Signals (scan first)
Golden Rules
- Behaviour with data — Objects own both state and the operations that change it
- Ubiquitous Language — Method names come from the domain, not CRUD (
commitTo, notsetStatus) - Small Aggregates — Root + Value Objects by default; add child Entities only for true invariants
- One transaction = one Aggregate — Cross-Aggregate rules use eventual consistency via Domain Events
- Reference by ID — Never hold object references to other Aggregates
- Value Objects first — Use Entities only when individual identity is essential
- Domain Services sparingly — Excessive services → anemic model
- Protect invariants — The Aggregate is the last line of defence; never trust the caller
Output Format
When reviewing code, report:
When refactoring, show a before/after diff for each class touched.


