ddd-aggregate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScaffold a complete aggregate root inside a bounded context.
Parse as (both kebab-case). The context must already exist under .
$ARGUMENTS<context-name> <aggregate-name>src/在限界上下文内生成完整的聚合根脚手架。
将解析为(均为短横线命名格式)。该上下文必须已存在于目录下。
$ARGUMENTS<context-name> <aggregate-name>src/Steps
步骤
-
Validate: Confirmexists. If not, suggest running
src/<context>/domain/first./ddd-context <context> -
Pre-task hook:
npx @claude-flow/cli@latest hooks pre-task --description "DDD aggregate: <aggregate-name> in <context>" -
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, based on identity
equals() - Export a TypeScript class extending or implementing a base interface
AggregateRoot
- File:
-
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
- File:
-
Create repository interface:
- File:
src/<context>/domain/repositories/<aggregate-name>.repository.ts - Include: ,
findById,savemethodsdelete - Use the aggregate root and its ID value object as types
- This is an interface only -- no implementation (infrastructure concern)
- File:
-
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
- File:
-
Create unit test stubs:
- File:
src/<context>/domain/entities/<aggregate-name>.entity.test.ts - Include: test cases for construction invariants, domain methods, equality
- Use /
describewithitnamesshould [behavior] when [condition]
- File:
-
Update barrel exports: Add new files to the relevantbarrel files.
index.ts -
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 -
Post-task hook:
npx @claude-flow/cli@latest hooks post-task --task-id "ddd-aggregate-<aggregate-name>" --success true --train-neural true
-
验证:确认目录存在。若不存在,建议先运行
src/<context>/domain/命令。/ddd-context <context> -
任务前置钩子:
npx @claude-flow/cli@latest hooks pre-task --description "DDD aggregate: <aggregate-name> in <context>" -
创建聚合根实体:
- 文件路径:
src/<context>/domain/entities/<aggregate-name>.entity.ts - 包含内容:唯一ID字段、带有不变量验证的构造函数、执行业务规则的领域方法、基于标识的方法
equals() - 导出一个继承或实现基础接口的TypeScript类
AggregateRoot
- 文件路径:
-
创建值对象:
- 文件路径:
src/<context>/domain/value-objects/<aggregate-name>-id.value-object.ts - 包含内容:带有工厂方法和验证逻辑的不可变ID值对象
- 根据聚合根的属性建议添加额外的值对象
- 文件路径:
-
创建仓库接口:
- 文件路径:
src/<context>/domain/repositories/<aggregate-name>.repository.ts - 包含方法:、
findById、savedelete - 使用聚合根及其ID值对象作为类型
- 这仅为接口——不包含实现(属于基础设施层职责)
- 文件路径:
-
创建领域事件:
- 文件路径:
src/<context>/domain/events/<aggregate-name>-created.event.ts - 文件路径:
src/<context>/domain/events/<aggregate-name>-updated.event.ts - 包含内容:事件名称(过去式)、时间戳、聚合根ID、负载
- 文件路径:
-
创建单元测试桩:
- 文件路径:
src/<context>/domain/entities/<aggregate-name>.entity.test.ts - 包含内容:构造不变量、领域方法、相等性的测试用例
- 使用/
describe语法,测试名称遵循“should [行为] when [条件]”格式it
- 文件路径:
-
更新桶导出:将新文件添加到对应的桶文件中。
index.ts -
存储到领域模型图:
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 -
任务后置钩子:
npx @claude-flow/cli@latest hooks post-task --task-id "ddd-aggregate-<aggregate-name>" --success true --train-neural true