microwind/ai-skills/aggregate-root-design
Claude Code and agent skill by microwind/ai-skills
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
聚合的入口点,外部只能通过聚合根访问聚合内部对象,保证数据一致性和业务不变量。
Install
npx vskill@latest install microwind/ai-skills/aggregate-root-designSKILL.md
聚合根设计 (Aggregate Root Design)
概述
聚合根是聚合的唯一入口,外部对象只能通过聚合根与聚合交互;它持有聚合的全局标识,负责维护聚合的所有业务不变量。
核心规则:
- 聚合根本身是 Entity,拥有全局唯一标识
- 外部对象只引用聚合根,不直接引用内部实体或值对象
- 聚合根负责维护所有跨子对象的业务不变量
- 仓储以聚合根为单位加载与保存(一次性加载完整聚合)
- 聚合根负责产生(raise / record)领域事件——把"已发生的事实"记入自身;事件的对外发布则由应用服务在事务边界统一完成(或经由 Outbox 投递)
- 一个事务只修改一个聚合实例
- 聚合间通过 ID 引用,不通过对象引用
代码示例
聚合设计原则
常见误区
❌ 为内部实体单独建仓储——OrderItemRepository、OrderLineRepository → 一聚合一仓储;内部实体通过聚合根加载和保存
❌ 聚合根成为"上帝类"——所有方法都堆在 Order 上,单类逾千行 → 跨聚合的协同抽到领域服务;聚合内的复杂规则抽成规约 / 策略对象
❌ 对外暴露内部可写集合——getItems() 返回可写 List,外部直接增删 → 返回不可变视图(Collections.unmodifiableList),或只暴露查询方法(findItemBySku())
与其他DDD概念的关系
总结
核心:聚合根是唯一入口,维护一致性,控制所有写操作。
实践:聚合尽量小、通过 ID 引用其他聚合、一个事务一个聚合。
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdomain-driven-design/aggregate-root-design/SKILL.md
Popularity
- Repository stars
- 51
- Repository forks
- 13
- 7-day trend score
- 20
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/microwind/ai-skills/aggregate-root-design)