ddd-validate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseValidate domain boundary integrity across all bounded contexts.
验证所有限界上下文中的领域边界完整性。
Steps
步骤
-
Discover contexts: Scanto find all bounded contexts.
src/*/domain/ -
Check cross-boundary violations:
- For each context, scan all files for import statements
.ts - Flag any import that reaches into another context's directory directly
domain/ - Allowed: importing from another context's public (application layer)
index.ts - Violation: importing from directly
src/<other-context>/domain/entities/...
bash# Find cross-boundary imports for ctx in $(find src -maxdepth 2 -name "domain" -type d | sed 's|src/||;s|/domain||'); do grep -rn "from ['\"].*src/" "src/$ctx/" --include="*.ts" | grep -v "src/$ctx/" || true done - For each context, scan all
-
Check aggregate invariant enforcement:
- Scan aggregate root entities for public setters that bypass validation
- Flag mutable public properties without invariant checks
- Verify that child entities are not directly accessible (must go through aggregate root)
-
Check event naming conventions:
- Domain events should be past-tense named (e.g., , not
OrderCreated)CreateOrder - Events should be immutable (no public setters)
- Events should carry the aggregate ID
- Domain events should be past-tense named (e.g.,
-
Check repository patterns:
- Repository interfaces should exist in , not
domain/repositories/infrastructure/ - Repository implementations should exist in , not
infrastructure/domain/ - Each aggregate root should have exactly one repository
- Repository interfaces should exist in
-
Report findings:
- Output a table of violations with file path, line number, violation type, and suggestion
- Categorize as: ,
BOUNDARY,INVARIANT,EVENTREPOSITORY - Exit with summary: total violations, by category, severity
-
Store results:bash
npx @claude-flow/cli@latest memory store --key "ddd-validation-TIMESTAMP" --value "RESULTS_SUMMARY" --namespace tasks npx @claude-flow/cli@latest hooks post-task --task-id "ddd-validate" --success true --store-results true
-
发现限界上下文:扫描目录以找出所有限界上下文。
src/*/domain/ -
检查跨边界违规:
- 针对每个上下文,扫描所有 文件中的导入语句
.ts - 标记任何直接导入其他上下文的 目录的行为
domain/ - 允许:从其他上下文的公共 (应用层)导入
index.ts - 违规:直接从 导入
src/<other-context>/domain/entities/...
bash# Find cross-boundary imports for ctx in $(find src -maxdepth 2 -name "domain" -type d | sed 's|src/||;s|/domain||'); do grep -rn "from ['\"].*src/" "src/$ctx/" --include="*.ts" | grep -v "src/$ctx/" || true done - 针对每个上下文,扫描所有
-
检查聚合不变量的执行情况:
- 扫描聚合根(aggregate root)实体,查找绕过验证的公共setter方法
- 标记未进行不变量检查的可变公共属性
- 验证子实体无法直接访问(必须通过聚合根)
-
检查事件命名规范:
- 领域事件应采用过去式命名(例如:,而非
OrderCreated)CreateOrder - 事件应是不可变的(无公共setter方法)
- 事件应携带聚合ID
- 领域事件应采用过去式命名(例如:
-
检查仓储模式:
- 仓储(Repository)接口应位于 目录,而非
domain/repositories/目录infrastructure/ - 仓储实现应位于 目录,而非
infrastructure/目录domain/ - 每个聚合根应对应恰好一个仓储
- 仓储(Repository)接口应位于
-
报告检查结果:
- 输出包含文件路径、行号、违规类型及建议的违规表格
- 分类为:,
BOUNDARY,INVARIANT,EVENTREPOSITORY - 退出时显示总结:违规总数、按分类统计、严重程度
-
存储结果:bash
npx @claude-flow/cli@latest memory store --key "ddd-validation-TIMESTAMP" --value "RESULTS_SUMMARY" --namespace tasks npx @claude-flow/cli@latest hooks post-task --task-id "ddd-validate" --success true --store-results true