ddd-aggregate
它能做什么
这项技能在现有模块中为一个聚合创建初始代码。聚合是一种核心业务对象,负责保护自身的规则。适合使用领域驱动设计的软件团队。
适用场景
- ✓当你向现有模块添加一个带有自身规则的新业务概念时。
- ✓当你需要同时创建实体、仓储和事件文件时。
- ✓当你希望创建与新聚合相匹配的测试桩时。
技能链接
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-ddd/skills/ddd-aggregate/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在我的销售模块中创建一个新的订单聚合,包括它的 ID、仓储和事件。”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能先检查模块文件夹是否存在,然后写入带有规则的实体文件、一个 ID 值对象、一个仓储接口、领域事件文件和测试桩。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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/.
Steps
Validate: Confirm
src/<context>/domain/exists. If not, suggest running/ddd-context <context>first.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,
equals()based on identity - Export a TypeScript class extending or implementing a base
AggregateRootinterface
- 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,save,deletemethods - 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
describe/itwithshould [behavior] when [condition]names
- File:
Update barrel exports: Add new files to the relevant
index.tsbarrel files.Store in domain model graph:
mcp__plugin_ruflo-core_ruflo__agentdb_hierarchical-store({ key: "domain/context-<context>/aggregate-<aggregate-name>", value: "Aggregate <aggregate-name> (parent: context-<context>)", tier: "semantic" }) mcp__plugin_ruflo-core_ruflo__agentdb_causal-edge({ sourceId: "entity:context-<context>", targetId: "entity:aggregate-<aggregate-name>", relation: "contains" }) mcp__plugin_ruflo-core_ruflo__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
常见问题
使用前必须先存在什么?
限界上下文文件夹必须已存在于源代码文件夹下。如果不存在,这项技能会建议先创建上下文。
它会编写存储代码吗?
不会。仓储只是一个接口,存储代码留给基础设施层。
它生成什么语言的文件?
它生成 TypeScript 文件,并遵循限界上下文的文件夹和命名结构。
详情
作者的原始描述
Scaffold an aggregate root with entity, value objects, repository interface, domain events, and test stubs. Use when adding a new aggregate to an existing bounded context, modeling a new business concept that owns invariants, or generating the boilerplate for an entity + repo + events triplet.
repo: ruvnet/ruflo
热度
- GitHub 星标
- 81k
- 排名
- #1614
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
agent-adaptive-coordinator
81k帮你的智能体在工作量变化时拆分和重新平衡一组 AI 智能体,并选择适合任务的分工方式。
agent-agent
81k教你的智能体把一个大目标拆成有顺序的行动计划,并在情况变化时重新规划。
agent-agentic-payments
81k帮你的智能体管理 AI 购物的消费授权,包括消费上限、时间窗口、商户规则和签名审批。
agent-analyze-code-quality
81k帮你的智能体检查代码质量,找出代码异味、技术债务和重构建议,且不改动文件。