一键导入
ddd
领域驱动设计(DDD)建模与架构指导。用于创建领域模型、设计限界上下文、实现聚合根、实体、值对象、领域服务和领域事件。支持战略设计(上下文映射、子域划分)和战术设计(聚合、仓储、工厂模式)。当用户需要进行领域建模、微服务划分、复杂业务逻辑设计时使用。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
领域驱动设计(DDD)建模与架构指导。用于创建领域模型、设计限界上下文、实现聚合根、实体、值对象、领域服务和领域事件。支持战略设计(上下文映射、子域划分)和战术设计(聚合、仓储、工厂模式)。当用户需要进行领域建模、微服务划分、复杂业务逻辑设计时使用。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Fetch, categorize, and summarize GitHub Trending projects across daily, weekly, and monthly spans. Use when a user asks for "trending projects", "latest hot repos", or a "summary of GitHub trends" to provide a structured, categorised report with full hyperlinking. Supports Markdown, HTML (Pinterest design), or both output formats, with optional Obsidian vault storage.
Turn a local folder or GitHub repository into an interactive browser-based course that explains how the codebase works for non-expert programmers and AI-assisted builders. Use when a user asks to make a course, tutorial, walkthrough, learning guide, codebase explanation, or interactive lesson from a project.
Converts a PRD or broad technical requirement into an AI-executable agile workflow with cards, checklists, branch-diff mapping, review gates, and a final comparison report. Use when the user wants PRD review, agile card decomposition, AI execution tracking, implementation branch review, or PRD-to-code traceability.
Two complementary Bezos heuristics in one skill. (A) Two-Way Door — classify decisions by reversibility; reversible = decide fast with 70% info, irreversible = decide slow with 90% info. (B) Regret Minimization — for life-defining choices, project to age 80 and pick what minimizes regret. Use Two-Way Door triggers on Chinese 决策瘫痪 / 反复纠结小事 / 开了三次会还没定 / 大事小事一样慢; Regret Min triggers on 离职 / 创业 / 移民 / 结婚 / 生育 / 转行 / 重大决定 / 这辈子. Especially when team applies identical heavy process to all decisions (need Two-Way), or when user faces once-in-a-decade pivot where rational analysis ties (need Regret Min). Do NOT misclassify One-Way as Two-Way (most expensive mistake), use Regret Min for daily decisions (age-80 view on "what to eat" is meaningless), or run Regret Min in heated emotion (cool 24-48h first to avoid romanticizing risk).
Use BEFORE selecting any other decision framework — Cynefin (kuh-NEV-in) classifies WHICH framework fits the current situation across 5 domains (Clear / Complicated / Complex / Chaotic / Confused). Triggers when user is about to apply a method and the fit feels off, asks meta-questions like "should we follow SOP or explore?", or when same approach that worked last time seems wrong now. Also use after failure when "the method was right but the situation didn't match", or when team argues over deterministic-plan-vs-experimentation. Especially valuable at the start of major decisions to avoid using the wrong hammer for the nail. Do NOT use for trivial classified decisions (don't run Cynefin for "what to eat for lunch"), true Chaotic situations needing immediate stabilizing action (act first, classify later), or teams unfamiliar with the model (use simpler known/unknown binary).
Use when user reports overwhelm from too many tasks, asks for week/sprint/OKR planning help, or describes spending 'all day firefighting' while long-term projects stall. Triggers on Chinese phrases 太多事 / 不知道先做哪个 / 排不过来 / 周计划 / sprint planning / 救火 / 优先级 / overwhelm / 焦虑 / 做不完 / todo 列表炸了, and explicit task triage requests. Especially valuable when waiting list has 15+ pending items, or when user says "重要的事一直推不动 / 都在做紧急的事". Do NOT use for small lists (<5 items just sort by deadline), team-level responsibility assignment (use RAPID/DACI from backlog), or when importance needs quantitative weighting (use weighted decision matrix).
| name | ddd |
| version | 1.0.0 |
| description | 领域驱动设计(DDD)建模与架构指导。用于创建领域模型、设计限界上下文、实现聚合根、实体、值对象、领域服务和领域事件。支持战略设计(上下文映射、子域划分)和战术设计(聚合、仓储、工厂模式)。当用户需要进行领域建模、微服务划分、复杂业务逻辑设计时使用。 |
| author | DeepArchi |
| license | MIT |
| keywords | ["ddd","domain-driven-design","domain-modeling","bounded-context","aggregate","microservices","architecture"] |
DDD Skill 提供领域驱动设计的完整指导,帮助开发者和架构师进行领域建模、限界上下文划分和战术模式实现。
当用户需要:
确定业务领域的边界和上下文关系:
核心域(Core Domain)→ 竞争优势所在
支撑域(Supporting Domain)→ 支持核心业务
通用域(Generic Domain)→ 可外购/复用
在限界上下文内进行详细建模:
聚合根(Aggregate Root)
├── 实体(Entity)- 有唯一标识
├── 值对象(Value Object)- 无标识,不可变
└── 领域事件(Domain Event)- 记录业务变化
限界上下文是DDD的核心概念,定义了领域模型的边界:
┌─────────────────────────────────────────────────────┐
│ 订单上下文 │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ 订单 │ │ 订单项 │ │ 支付 │ │
│ │ 聚合根 │ │ 实体 │ │ 值对象 │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────────┘
│
│ 上下文映射
▼
┌─────────────────────────────────────────────────────┐
│ 库存上下文 │
│ ┌─────────┐ ┌─────────┐ │
│ │ 库存 │ │ 库存项 │ │
│ │ 聚合根 │ │ 实体 │ │
│ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────────┘
识别领域中的关键事件:
橙色便签:领域事件(发生了什么)
蓝色便签:命令(触发事件的动作)
黄色便签:聚合(处理命令、产生事件)
紫色便签:策略(响应事件的规则)
粉色便签:外部系统
根据事件风暴结果划分上下文边界:
定义上下文间的集成关系:
| 模式 | 说明 | 适用场景 |
|---|---|---|
| 共享内核 | 共享部分模型 | 紧密协作团队 |
| 客户-供应商 | 上下游依赖 | 明确的服务依赖 |
| 防腐层 | 隔离外部模型 | 集成遗留系统 |
| 开放主机服务 | 提供标准API | 多消费者场景 |
| 发布语言 | 共享数据格式 | 事件驱动集成 |
在每个上下文内进行详细设计:
# 聚合根示例
class Order(AggregateRoot):
def __init__(self, order_id: OrderId, customer_id: CustomerId):
self.id = order_id
self.customer_id = customer_id
self.items: List[OrderItem] = []
self.status = OrderStatus.DRAFT
def add_item(self, product_id: ProductId, quantity: int, price: Money):
"""添加订单项 - 业务逻辑封装在聚合内"""
if self.status != OrderStatus.DRAFT:
raise DomainException("只能向草稿订单添加商品")
item = OrderItem(product_id, quantity, price)
self.items.append(item)
self.add_event(OrderItemAdded(self.id, item))
def submit(self):
"""提交订单 - 触发领域事件"""
if not self.items:
raise DomainException("订单不能为空")
self.status = OrderStatus.SUBMITTED
self.add_event(OrderSubmitted(self.id, self.total_amount))
# 值对象示例 - 不可变,无标识
@dataclass(frozen=True)
class Money:
amount: Decimal
currency: str
def add(self, other: 'Money') -> 'Money':
if self.currency != other.currency:
raise ValueError("货币类型不匹配")
return Money(self.amount + other.amount, self.currency)
# 领域事件示例
@dataclass(frozen=True)
class OrderSubmitted(DomainEvent):
order_id: OrderId
total_amount: Money
occurred_at: datetime = field(default_factory=datetime.utcnow)
┌─────────────────────────────────┐
│ 应用层(Application) │
┌───────────┐ │ ┌─────────────────────────┐ │ ┌───────────┐
│ REST │◄──┼──│ 端口(Ports) │──┼──►│ 数据库 │
│ API │ │ └─────────────────────────┘ │ │ 适配器 │
└───────────┘ │ │ │ └───────────┘
│ ▼ │
┌───────────┐ │ ┌─────────────────────────┐ │ ┌───────────┐
│ 消息 │◄──┼──│ 领域层(Domain) │──┼──►│ 消息 │
│ 队列 │ │ │ 聚合、实体、值对象 │ │ │ 适配器 │
└───────────┘ │ └─────────────────────────┘ │ └───────────┘
└─────────────────────────────────┘
命令端(Command Side) 查询端(Query Side)
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Command Bus │ │ Query Bus │
└──────────────┘ └──────────────┘
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ 聚合根 │──事件──► │ 读模型 │
│(写模型) │ │(优化查询) │
└──────────────┘ └──────────────┘
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ 事件存储 │ │ 查询数据库 │
└──────────────┘ └──────────────┘
详细参考文档:
references/strategic-design.md - 战略设计详解references/tactical-design.md - 战术设计模式references/patterns.md - DDD架构模式assets/ddd-model-template.drawio - 领域模型模板