ddd-tactical-patterns
它能做什么
这个工具会按照一种叫做“DDD 战术模式”的设计原则来组织你的程序代码。它关注如何构建程序的核心部分,使其更易理解和维护,尤其是在业务规则比较复杂的时候。
适用场景
- ✓当你需要把业务规则转化为代码时。
- ✓当你要决定如何组织程序的不同部分时。
- ✓当你需要改进混乱或逻辑不清晰的代码时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/ddd-tactical-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“把这些业务规则翻译成代码:[在这里填写规则]”
每周 5 个新技能,1 分钟读完。
工作原理
工具会把你的代码组织成“实体”和“值对象”等模块,并确保重要的规则(不变量)始终得到遵守。它还会帮你定义这些模块之间如何通信,以及如何记录重要的变化。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
DDD Tactical Patterns
Use this skill when
- Translating domain rules into code structures.
- Designing aggregate boundaries and invariants.
- Refactoring an anemic model into behavior-rich domain objects.
- Defining repository contracts and domain event boundaries.
Do not use this skill when
- You are still defining strategic boundaries.
- The task is only API documentation or UI layout.
- Full DDD complexity is not justified.
Instructions
- Identify invariants first and design aggregates around them.
- Model immutable value objects for validated concepts.
- Keep domain behavior in domain objects, not controllers.
- Emit domain events for meaningful state transitions.
- Keep repositories at aggregate root boundaries.
If detailed checklists are needed, open references/tactical-checklist.md.
Example
class Order {
private status: "draft" | "submitted" = "draft";
submit(itemsCount: number): void {
if (itemsCount === 0) throw new Error("Order cannot be submitted empty");
if (this.status !== "draft") throw new Error("Order already submitted");
this.status = "submitted";
}
}
Limitations
- This skill does not define deployment architecture.
- It does not choose databases or transport protocols.
- It should be paired with testing patterns for invariant coverage.
常见问题
什么是“不变量”?
不变量是程序中某部分必须始终成立的业务规则。例如,一个银行账户的余额永远不能为负数。
什么是“实体”和“值对象”?
实体是有自己身份标识、会随时间变化的事物(比如“用户”)。值对象是由其属性定义、没有自己身份标识的事物(比如“地址”)。
什么是“聚合”?
聚合是一组协同工作、被视为一个整体的实体和值对象。它们有助于维护业务规则的一致性。
详情
作者的原始描述
Apply DDD tactical patterns in code using entities, value objects, aggregates, repositories, and domain events with explicit invariants.
热度
- GitHub 星标
- 48k
- 排名
- #4348
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。