ddd-validate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Validate domain boundary integrity across all bounded contexts.
验证所有限界上下文中的领域边界完整性。

Steps

步骤

  1. Discover contexts: Scan
    src/*/domain/
    to find all bounded contexts.
  2. Check cross-boundary violations:
    • For each context, scan all
      .ts
      files for import statements
    • Flag any import that reaches into another context's
      domain/
      directory directly
    • Allowed: importing from another context's public
      index.ts
      (application layer)
    • Violation: importing from
      src/<other-context>/domain/entities/...
      directly
    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
  3. 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)
  4. Check event naming conventions:
    • Domain events should be past-tense named (e.g.,
      OrderCreated
      , not
      CreateOrder
      )
    • Events should be immutable (no public setters)
    • Events should carry the aggregate ID
  5. Check repository patterns:
    • Repository interfaces should exist in
      domain/repositories/
      , not
      infrastructure/
    • Repository implementations should exist in
      infrastructure/
      , not
      domain/
    • Each aggregate root should have exactly one repository
  6. Report findings:
    • Output a table of violations with file path, line number, violation type, and suggestion
    • Categorize as:
      BOUNDARY
      ,
      INVARIANT
      ,
      EVENT
      ,
      REPOSITORY
    • Exit with summary: total violations, by category, severity
  7. 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
  1. 发现限界上下文:扫描
    src/*/domain/
    目录以找出所有限界上下文。
  2. 检查跨边界违规:
    • 针对每个上下文,扫描所有
      .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
  3. 检查聚合不变量的执行情况:
    • 扫描聚合根(aggregate root)实体,查找绕过验证的公共setter方法
    • 标记未进行不变量检查的可变公共属性
    • 验证子实体无法直接访问(必须通过聚合根)
  4. 检查事件命名规范:
    • 领域事件应采用过去式命名(例如:
      OrderCreated
      ,而非
      CreateOrder
    • 事件应是不可变的(无公共setter方法)
    • 事件应携带聚合ID
  5. 检查仓储模式:
    • 仓储(Repository)接口应位于
      domain/repositories/
      目录,而非
      infrastructure/
      目录
    • 仓储实现应位于
      infrastructure/
      目录,而非
      domain/
      目录
    • 每个聚合根应对应恰好一个仓储
  6. 报告检查结果:
    • 输出包含文件路径、行号、违规类型及建议的违规表格
    • 分类为:
      BOUNDARY
      ,
      INVARIANT
      ,
      EVENT
      ,
      REPOSITORY
    • 退出时显示总结:违规总数、按分类统计、严重程度
  7. 存储结果:
    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