跳到正文
Skillpedia
API 与服务器(后端)81k · #1614

ddd-aggregate

它能做什么

这项技能在现有模块中为一个聚合创建初始代码。聚合是一种核心业务对象,负责保护自身的规则。适合使用领域驱动设计的软件团队。

适用场景

  • ✓当你向现有模块添加一个带有自身规则的新业务概念时。
  • ✓当你需要同时创建实体、仓储和事件文件时。
  • ✓当你希望创建与新聚合相匹配的测试桩时。

技能链接

https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-ddd/skills/ddd-aggregate/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-ddd/skills/ddd-aggregate/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

  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__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" })
    
  10. 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能