ddd-aggregate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Scaffold a complete aggregate root inside a bounded context.
Parse
$ARGUMENTS
as
<context-name> <aggregate-name>
(both kebab-case). The context must already exist under
src/
.
在限界上下文内生成完整的聚合根脚手架。
$ARGUMENTS
解析为
<context-name> <aggregate-name>
(均为短横线命名格式)。该上下文必须已存在于
src/
目录下。

Steps

步骤

  1. Validate: Confirm
    src/<context>/domain/
    exists. If not, suggest running
    /ddd-context <context>
    first.
  2. Pre-task hook:
    npx @claude-flow/cli@latest hooks pre-task --description "DDD aggregate: <aggregate-name> in <context>"
  3. Create aggregate root entity:
    • File:
      src/<context>/domain/entities/<aggregate-name>.entity.ts
    • Include: unique ID field, constructor with invariant validation, domain methods that enforce business rules,
      equals()
      based on identity
    • Export a TypeScript class extending or implementing a base
      AggregateRoot
      interface
  4. Create value objects:
    • File:
      src/<context>/domain/value-objects/<aggregate-name>-id.value-object.ts
    • Include: immutable ID value object with factory method and validation
    • Add additional value objects as properties of the aggregate suggest them
  5. Create repository interface:
    • File:
      src/<context>/domain/repositories/<aggregate-name>.repository.ts
    • Include:
      findById
      ,
      save
      ,
      delete
      methods
    • Use the aggregate root and its ID value object as types
    • This is an interface only -- no implementation (infrastructure concern)
  6. Create domain events:
    • File:
      src/<context>/domain/events/<aggregate-name>-created.event.ts
    • File:
      src/<context>/domain/events/<aggregate-name>-updated.event.ts
    • Include: event name (past tense), timestamp, aggregate ID, payload
  7. Create unit test stubs:
    • File:
      src/<context>/domain/entities/<aggregate-name>.entity.test.ts
    • Include: test cases for construction invariants, domain methods, equality
    • Use
      describe
      /
      it
      with
      should [behavior] when [condition]
      names
  8. Update barrel exports: Add new files to the relevant
    index.ts
    barrel files.
  9. Store in domain model graph:
    mcp__claude-flow__agentdb_hierarchical-store --parent "context:<context>" --child "aggregate:<aggregate-name>" --relation "contains"
    mcp__claude-flow__memory_store --key "ddd-aggregate-<context>-<aggregate-name>" --value "AGGREGATE_SUMMARY" --namespace tasks
  10. Post-task hook:
    npx @claude-flow/cli@latest hooks post-task --task-id "ddd-aggregate-<aggregate-name>" --success true --train-neural true
  1. 验证:确认
    src/<context>/domain/
    目录存在。若不存在,建议先运行
    /ddd-context <context>
    命令。
  2. 任务前置钩子
    npx @claude-flow/cli@latest hooks pre-task --description "DDD aggregate: <aggregate-name> in <context>"
  3. 创建聚合根实体
    • 文件路径:
      src/<context>/domain/entities/<aggregate-name>.entity.ts
    • 包含内容:唯一ID字段、带有不变量验证的构造函数、执行业务规则的领域方法、基于标识的
      equals()
      方法
    • 导出一个继承或实现基础
      AggregateRoot
      接口的TypeScript类
  4. 创建值对象
    • 文件路径:
      src/<context>/domain/value-objects/<aggregate-name>-id.value-object.ts
    • 包含内容:带有工厂方法和验证逻辑的不可变ID值对象
    • 根据聚合根的属性建议添加额外的值对象
  5. 创建仓库接口
    • 文件路径:
      src/<context>/domain/repositories/<aggregate-name>.repository.ts
    • 包含方法:
      findById
      save
      delete
    • 使用聚合根及其ID值对象作为类型
    • 这仅为接口——不包含实现(属于基础设施层职责)
  6. 创建领域事件
    • 文件路径:
      src/<context>/domain/events/<aggregate-name>-created.event.ts
    • 文件路径:
      src/<context>/domain/events/<aggregate-name>-updated.event.ts
    • 包含内容:事件名称(过去式)、时间戳、聚合根ID、负载
  7. 创建单元测试桩
    • 文件路径:
      src/<context>/domain/entities/<aggregate-name>.entity.test.ts
    • 包含内容:构造不变量、领域方法、相等性的测试用例
    • 使用
      describe
      /
      it
      语法,测试名称遵循“should [行为] when [条件]”格式
  8. 更新桶导出:将新文件添加到对应的
    index.ts
    桶文件中。
  9. 存储到领域模型图
    mcp__claude-flow__agentdb_hierarchical-store --parent "context:<context>" --child "aggregate:<aggregate-name>" --relation "contains"
    mcp__claude-flow__memory_store --key "ddd-aggregate-<context>-<aggregate-name>" --value "AGGREGATE_SUMMARY" --namespace tasks
  10. 任务后置钩子
    npx @claude-flow/cli@latest hooks post-task --task-id "ddd-aggregate-<aggregate-name>" --success true --train-neural true