[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M70NG057252CJT7ZXZYN2ESN":3,"skill-same:01M70NG057252CJT7ZXZYN2ESN":78},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":49,"linkOnly":50,"markdownContent":51,"markdownBody":52,"frontMatter":53,"refName":54,"commitSha":55,"skillDirectory":56,"forksCount":57,"repositoryHtmlUrl":58,"repositoryHomepageUrl":59,"ownerHtmlUrl":60,"ownerBlogUrl":61,"ownerDescription":62,"updatedAt":63,"install":64,"resources":77},"01M70NG057252CJT7ZXZYN2ESN","domain-driven-design",null,"Domain-Driven Design tactical and strategic patterns including entities, value objects, aggregates, bounded contexts, and consistency strategies. Use when modeling business domains, designing aggregate boundaries, implementing business rules, or planning data consistency.","shengdabai\u002FTony-Claude-Code-Skills","shengdabai","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F116417419?v=4","01M70F6D2WY5PQV5A92BKYJQEW","Tony Sheng","01M70F6D3GAAAYZ5H4CC1G8VXM",3,"MIT","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Frsmdt-the-startup\u002Fplugins\u002Fteam\u002Fskills\u002Fdevelopment\u002Fdomain-driven-design\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000015","视觉设计","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48],"design","domain","driven","domain driven design","use","strategic","planning","value","consistency","bounded","patterns","data","modeling","strategies","when","objects","domains","implementing","aggregates","tactical","2026-11-10 10:12:30",false,"---\nname: domain-driven-design\ndescription: Domain-Driven Design tactical and strategic patterns including entities, value objects, aggregates, bounded contexts, and consistency strategies. Use when modeling business domains, designing aggregate boundaries, implementing business rules, or planning data consistency.\n---\n\n# Domain-Driven Design Patterns\n\nPatterns for modeling complex business domains with clear boundaries, enforced invariants, and appropriate consistency strategies.\n\n## When to Activate\n\n- Modeling business domains and entities\n- Designing aggregate boundaries\n- Implementing complex business rules\n- Planning data consistency strategies\n- Establishing bounded contexts\n- Designing domain events and integration\n\n## Strategic Patterns\n\n### Bounded Context\n\nA bounded context defines the boundary within which a domain model applies. The same term can mean different things in different contexts.\n\n```\nExample: \"Customer\" in different contexts\n\n┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐\n│    Sales        │  │    Support      │  │    Billing      │\n│    Context      │  │    Context      │  │    Context      │\n├─────────────────┤  ├─────────────────┤  ├─────────────────┤\n│ Customer:       │  │ Customer:       │  │ Customer:       │\n│ - Leads         │  │ - Tickets       │  │ - Invoices      │\n│ - Opportunities │  │ - SLA           │  │ - Payment       │\n│ - Proposals     │  │ - Satisfaction  │  │ - Credit Limit  │\n└─────────────────┘  └─────────────────┘  └─────────────────┘\n```\n\n#### Context Identification\n\nAsk these questions to find context boundaries:\n- Where does the ubiquitous language change?\n- Which teams own which concepts?\n- Where do integration points naturally occur?\n- What could be deployed independently?\n\n### Context Mapping\n\nDefine how bounded contexts integrate:\n\n| Pattern | Description | Use When |\n|---------|-------------|----------|\n| **Shared Kernel** | Shared code between contexts | Close collaboration, same team |\n| **Customer-Supplier** | Upstream\u002Fdownstream relationship | Clear dependency direction |\n| **Conformist** | Downstream adopts upstream model | No negotiation power |\n| **Anti-Corruption Layer** | Translation layer between models | Protecting domain from external models |\n| **Open Host Service** | Published API for integration | Multiple consumers |\n| **Published Language** | Shared interchange format | Industry standards exist |\n\n### Ubiquitous Language\n\nThe shared vocabulary between developers and domain experts:\n\n```\nBuilding Ubiquitous Language:\n\n1. EXTRACT terms from domain expert conversations\n2. DOCUMENT in a glossary with precise definitions\n3. ENFORCE in code - class names, method names, variables\n4. EVOLVE as understanding deepens\n\nExample Glossary Entry:\n┌─────────────────────────────────────────────────────────────┐\n│ Term: Order                                                  │\n│ Definition: A confirmed request from a customer to purchase │\n│             one or more products at agreed prices.          │\n│ NOT: A shopping cart (which is an Intent, not an Order)     │\n│ Context: Sales                                              │\n└─────────────────────────────────────────────────────────────┘\n```\n\n## Tactical Patterns\n\n### Entities\n\nObjects with identity that persists over time. Equality is based on identity, not attributes.\n\n```\nCharacteristics:\n- Has a unique identifier\n- Mutable state\n- Lifecycle (created, modified, archived)\n- Equality by ID\n\nExample:\n┌─────────────────────────────────────────┐\n│ Entity: Order                           │\n├─────────────────────────────────────────┤\n│ Identity: orderId (UUID)                │\n│ State: status, items, total             │\n│ Behavior: addItem(), submit(), cancel() │\n└─────────────────────────────────────────┘\n\nclass Order {\n  private readonly id: OrderId;      \u002F\u002F Identity - immutable\n  private status: OrderStatus;        \u002F\u002F State - mutable\n  private items: OrderItem[];         \u002F\u002F State - mutable\n\n  constructor(id: OrderId) {\n    this.id = id;\n    this.status = OrderStatus.Draft;\n    this.items = [];\n  }\n\n  equals(other: Order): boolean {\n    return this.id.equals(other.id);  \u002F\u002F Equality by identity\n  }\n}\n```\n\n### Value Objects\n\nObjects without identity. Equality is based on attributes. Always immutable.\n\n```\nCharacteristics:\n- No unique identifier\n- Immutable (all properties readonly)\n- Equality by attributes\n- Self-validating\n\nExample:\n┌─────────────────────────────────────────┐\n│ Value Object: Money                     │\n├─────────────────────────────────────────┤\n│ Attributes: amount, currency            │\n│ Behavior: add(), subtract(), format()   │\n│ Invariant: amount >= 0                  │\n└─────────────────────────────────────────┘\n\nclass Money {\n  constructor(\n    public readonly amount: number,\n    public readonly currency: Currency\n  ) {\n    if (amount \u003C 0) throw new Error('Amount cannot be negative');\n  }\n\n  add(other: Money): Money {\n    if (!this.currency.equals(other.currency)) {\n      throw new Error('Cannot add different currencies');\n    }\n    return new Money(this.amount + other.amount, this.currency);\n  }\n\n  equals(other: Money): boolean {\n    return this.amount === other.amount &&\n           this.currency.equals(other.currency);\n  }\n}\n```\n\n#### When to Use Value Objects\n\n| Use Value Object | Use Entity |\n|------------------|------------|\n| No need to track over time | Need to track lifecycle |\n| Interchangeable instances | Unique identity matters |\n| Defined by attributes | Defined by continuity |\n| Examples: Money, Address, DateRange | Examples: User, Order, Account |\n\n### Aggregates\n\nA cluster of entities and value objects with a defined boundary. One entity is the aggregate root.\n\n```\nAggregate Design Rules:\n\n1. PROTECT invariants at aggregate boundary\n2. REFERENCE other aggregates by identity only\n3. UPDATE one aggregate per transaction\n4. DESIGN small aggregates (prefer single entity)\n\nExample:\n┌─────────────────────────────────────────────────────────────┐\n│ Aggregate: Order                                            │\n│ Root: Order (entity)                                        │\n├─────────────────────────────────────────────────────────────┤\n│  ┌─────────────────┐                                        │\n│  │ Order (Root)    │◄── Aggregate Root                      │\n│  │ - orderId       │                                        │\n│  │ - customerId ───┼──► Reference by ID only                │\n│  │ - status        │                                        │\n│  └────────┬────────┘                                        │\n│           │                                                 │\n│  ┌────────▼────────┐                                        │\n│  │ OrderItem       │◄── Inside aggregate                    │\n│  │ - productId ────┼──► Reference by ID only                │\n│  │ - quantity      │                                        │\n│  │ - price (Money) │◄── Value Object                        │\n│  └─────────────────┘                                        │\n└─────────────────────────────────────────────────────────────┘\n```\n\n#### Aggregate Sizing\n\n```\nStart Small:\n- Begin with single-entity aggregates\n- Expand only when invariants require it\n\nSigns of Too-Large Aggregate:\n- Frequent optimistic lock conflicts\n- Loading too much data for simple operations\n- Multiple users editing simultaneously\n- Transactional failures across unrelated data\n\nSigns of Too-Small Aggregate:\n- Invariants not protected\n- Business rules scattered across services\n- Eventual consistency where immediate is required\n```\n\n### Domain Events\n\nRepresent something that happened in the domain. Immutable facts about the past.\n\n```\nEvent Structure:\n┌─────────────────────────────────────────┐\n│ Event: OrderPlaced                      │\n├─────────────────────────────────────────┤\n│ eventId: UUID                           │\n│ occurredAt: DateTime                    │\n│ aggregateId: orderId                    │\n│ payload:                                │\n│   - customerId                          │\n│   - items                               │\n│   - totalAmount                         │\n└─────────────────────────────────────────┘\n\nNaming Convention:\n- Past tense (OrderPlaced, not PlaceOrder)\n- Domain language (not technical)\n- Include all relevant data (event is immutable)\n\nclass OrderPlaced implements DomainEvent {\n  readonly eventId = uuid();\n  readonly occurredAt = new Date();\n\n  constructor(\n    readonly orderId: OrderId,\n    readonly customerId: CustomerId,\n    readonly items: OrderItemData[],\n    readonly totalAmount: Money\n  ) {}\n}\n```\n\n#### Event Patterns\n\n| Pattern | Description | Use Case |\n|---------|-------------|----------|\n| **Event Notification** | Minimal data, query for details | Loose coupling |\n| **Event-Carried State** | Full data in event | Performance, offline |\n| **Event Sourcing** | Events as source of truth | Audit, temporal queries |\n\n### Repositories\n\nAbstract persistence, providing collection-like access to aggregates.\n\n```\nRepository Principles:\n- One repository per aggregate\n- Returns aggregate roots only\n- Hides persistence mechanism\n- Supports aggregate reconstitution\n\ninterface OrderRepository {\n  findById(id: OrderId): Promise\u003COrder | null>;\n  findByCustomer(customerId: CustomerId): Promise\u003COrder[]>;\n  save(order: Order): Promise\u003Cvoid>;\n  delete(order: Order): Promise\u003Cvoid>;\n}\n\n\u002F\u002F Implementation hides persistence details\nclass PostgresOrderRepository implements OrderRepository {\n  async findById(id: OrderId): Promise\u003COrder | null> {\n    const row = await this.db.query('SELECT * FROM orders WHERE id = $1', [id]);\n    return row ? this.reconstitute(row) : null;\n  }\n\n  private reconstitute(row: OrderRow): Order {\n    \u002F\u002F Rebuild aggregate from persistence\n  }\n}\n```\n\n## Consistency Strategies\n\n### Transactional Consistency (ACID)\n\nUse for invariants within an aggregate:\n\n```\nRule: One aggregate per transaction\n\n\u002F\u002F Good: Single aggregate updated\nasync function addItemToOrder(orderId: OrderId, item: OrderItem) {\n  const order = await orderRepo.findById(orderId);\n  order.addItem(item);  \u002F\u002F Business rules enforced\n  await orderRepo.save(order);\n}\n\n\u002F\u002F Bad: Multiple aggregates in one transaction\nasync function createOrderWithInventory() {\n  await db.transaction(async (tx) => {\n    await orderRepo.save(order, tx);\n    await inventoryRepo.decrement(productId, quantity, tx);  \u002F\u002F Don't do this\n  });\n}\n```\n\n### Eventual Consistency\n\nUse for consistency across aggregates:\n\n```\nPattern: Domain Events + Handlers\n\n\u002F\u002F Order aggregate publishes event\nclass Order {\n  submit(): void {\n    this.status = OrderStatus.Placed;\n    this.addEvent(new OrderPlaced(this.id, this.customerId, this.items));\n  }\n}\n\n\u002F\u002F Separate handler updates inventory (eventually)\nclass InventoryHandler {\n  async handle(event: OrderPlaced): Promise\u003Cvoid> {\n    for (const item of event.items) {\n      await this.inventoryService.reserve(item.productId, item.quantity);\n    }\n  }\n}\n```\n\n### Saga Pattern\n\nCoordinate multiple aggregates with compensation:\n\n```\nSaga: Order Fulfillment\n\n┌─────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────┐\n│ Create  │────►│ Reserve     │────►│ Charge      │────►│ Ship    │\n│ Order   │     │ Inventory   │     │ Payment     │     │ Order   │\n└────┬────┘     └──────┬──────┘     └──────┬──────┘     └─────────┘\n     │                 │                   │\n     │ Compensate:     │ Compensate:       │ Compensate:\n     │ Cancel Order    │ Release Inventory │ Refund Payment\n     ▼                 ▼                   ▼\n\nOn failure at any step, execute compensation in reverse order.\n```\n\n### Choosing Consistency\n\n| Scenario | Strategy |\n|----------|----------|\n| Within single aggregate | Transactional (ACID) |\n| Across aggregates, same service | Eventual (domain events) |\n| Across services | Saga with compensation |\n| Read model updates | Eventual (projection) |\n\n## Anti-Patterns\n\n### Anemic Domain Model\n\n```\n\u002F\u002F Anti-pattern: Logic outside domain objects\nclass Order {\n  id: string;\n  items: Item[];\n  status: string;\n}\n\nclass OrderService {\n  calculateTotal(order: Order): number { ... }\n  validate(order: Order): boolean { ... }\n  submit(order: Order): void { ... }\n}\n\n\u002F\u002F Better: Logic inside domain objects\nclass Order {\n  private items: OrderItem[];\n  private status: OrderStatus;\n\n  get total(): Money {\n    return this.items.reduce((sum, item) => sum.add(item.subtotal), Money.zero());\n  }\n\n  submit(): void {\n    this.validate();\n    this.status = OrderStatus.Submitted;\n  }\n}\n```\n\n### Large Aggregates\n\n```\n\u002F\u002F Anti-pattern: Everything in one aggregate\nclass Customer {\n  orders: Order[];           \u002F\u002F Could be thousands\n  addresses: Address[];\n  paymentMethods: PaymentMethod[];\n  preferences: Preferences;\n  activityLog: Activity[];   \u002F\u002F Could be millions\n}\n\n\u002F\u002F Better: Separate aggregates referenced by ID\nclass Customer {\n  id: CustomerId;\n  defaultAddressId: AddressId;\n  defaultPaymentMethodId: PaymentMethodId;\n}\n\nclass Order {\n  customerId: CustomerId;    \u002F\u002F Reference by ID\n}\n```\n\n### Primitive Obsession\n\n```\n\u002F\u002F Anti-pattern: Primitive types for domain concepts\nfunction createOrder(\n  customerId: string,\n  productId: string,\n  quantity: number,\n  price: number,\n  currency: string\n) { ... }\n\n\u002F\u002F Better: Value objects\nfunction createOrder(\n  customerId: CustomerId,\n  productId: ProductId,\n  quantity: Quantity,\n  price: Money\n) { ... }\n```\n\n## Implementation Checklist\n\n### Aggregate Design\n\n- [ ] Single entity can be aggregate root\n- [ ] Invariants are protected at boundary\n- [ ] Other aggregates referenced by ID only\n- [ ] Fits in memory comfortably\n- [ ] One transaction per aggregate\n\n### Entity Implementation\n\n- [ ] Has unique identifier\n- [ ] Equality based on ID\n- [ ] Encapsulates business rules\n- [ ] State changes through methods\n\n### Value Object Implementation\n\n- [ ] All properties immutable\n- [ ] Equality based on attributes\n- [ ] Self-validating\n- [ ] Operations return new instances\n\n### Repository Implementation\n\n- [ ] One per aggregate\n- [ ] Returns aggregate roots only\n- [ ] Hides persistence details\n- [ ] Supports queries needed by domain\n\n## References\n\n- [Pattern Implementation Examples](examples\u002Fddd-patterns.md) - Code examples in multiple languages\n- [Aggregate Design Guide](reference.md) - Detailed aggregate sizing heuristics\n","# Domain-Driven Design Patterns\n\nPatterns for modeling complex business domains with clear boundaries, enforced invariants, and appropriate consistency strategies.\n\n## When to Activate\n\n- Modeling business domains and entities\n- Designing aggregate boundaries\n- Implementing complex business rules\n- Planning data consistency strategies\n- Establishing bounded contexts\n- Designing domain events and integration\n\n## Strategic Patterns\n\n### Bounded Context\n\nA bounded context defines the boundary within which a domain model applies. The same term can mean different things in different contexts.\n\n```\nExample: \"Customer\" in different contexts\n\n┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐\n│    Sales        │  │    Support      │  │    Billing      │\n│    Context      │  │    Context      │  │    Context      │\n├─────────────────┤  ├─────────────────┤  ├─────────────────┤\n│ Customer:       │  │ Customer:       │  │ Customer:       │\n│ - Leads         │  │ - Tickets       │  │ - Invoices      │\n│ - Opportunities │  │ - SLA           │  │ - Payment       │\n│ - Proposals     │  │ - Satisfaction  │  │ - Credit Limit  │\n└─────────────────┘  └─────────────────┘  └─────────────────┘\n```\n\n#### Context Identification\n\nAsk these questions to find context boundaries:\n- Where does the ubiquitous language change?\n- Which teams own which concepts?\n- Where do integration points naturally occur?\n- What could be deployed independently?\n\n### Context Mapping\n\nDefine how bounded contexts integrate:\n\n| Pattern | Description | Use When |\n|---------|-------------|----------|\n| **Shared Kernel** | Shared code between contexts | Close collaboration, same team |\n| **Customer-Supplier** | Upstream\u002Fdownstream relationship | Clear dependency direction |\n| **Conformist** | Downstream adopts upstream model | No negotiation power |\n| **Anti-Corruption Layer** | Translation layer between models | Protecting domain from external models |\n| **Open Host Service** | Published API for integration | Multiple consumers |\n| **Published Language** | Shared interchange format | Industry standards exist |\n\n### Ubiquitous Language\n\nThe shared vocabulary between developers and domain experts:\n\n```\nBuilding Ubiquitous Language:\n\n1. EXTRACT terms from domain expert conversations\n2. DOCUMENT in a glossary with precise definitions\n3. ENFORCE in code - class names, method names, variables\n4. EVOLVE as understanding deepens\n\nExample Glossary Entry:\n┌─────────────────────────────────────────────────────────────┐\n│ Term: Order                                                  │\n│ Definition: A confirmed request from a customer to purchase │\n│             one or more products at agreed prices.          │\n│ NOT: A shopping cart (which is an Intent, not an Order)     │\n│ Context: Sales                                              │\n└─────────────────────────────────────────────────────────────┘\n```\n\n## Tactical Patterns\n\n### Entities\n\nObjects with identity that persists over time. Equality is based on identity, not attributes.\n\n```\nCharacteristics:\n- Has a unique identifier\n- Mutable state\n- Lifecycle (created, modified, archived)\n- Equality by ID\n\nExample:\n┌─────────────────────────────────────────┐\n│ Entity: Order                           │\n├─────────────────────────────────────────┤\n│ Identity: orderId (UUID)                │\n│ State: status, items, total             │\n│ Behavior: addItem(), submit(), cancel() │\n└─────────────────────────────────────────┘\n\nclass Order {\n  private readonly id: OrderId;      \u002F\u002F Identity - immutable\n  private status: OrderStatus;        \u002F\u002F State - mutable\n  private items: OrderItem[];         \u002F\u002F State - mutable\n\n  constructor(id: OrderId) {\n    this.id = id;\n    this.status = OrderStatus.Draft;\n    this.items = [];\n  }\n\n  equals(other: Order): boolean {\n    return this.id.equals(other.id);  \u002F\u002F Equality by identity\n  }\n}\n```\n\n### Value Objects\n\nObjects without identity. Equality is based on attributes. Always immutable.\n\n```\nCharacteristics:\n- No unique identifier\n- Immutable (all properties readonly)\n- Equality by attributes\n- Self-validating\n\nExample:\n┌─────────────────────────────────────────┐\n│ Value Object: Money                     │\n├─────────────────────────────────────────┤\n│ Attributes: amount, currency            │\n│ Behavior: add(), subtract(), format()   │\n│ Invariant: amount >= 0                  │\n└─────────────────────────────────────────┘\n\nclass Money {\n  constructor(\n    public readonly amount: number,\n    public readonly currency: Currency\n  ) {\n    if (amount \u003C 0) throw new Error('Amount cannot be negative');\n  }\n\n  add(other: Money): Money {\n    if (!this.currency.equals(other.currency)) {\n      throw new Error('Cannot add different currencies');\n    }\n    return new Money(this.amount + other.amount, this.currency);\n  }\n\n  equals(other: Money): boolean {\n    return this.amount === other.amount &&\n           this.currency.equals(other.currency);\n  }\n}\n```\n\n#### When to Use Value Objects\n\n| Use Value Object | Use Entity |\n|------------------|------------|\n| No need to track over time | Need to track lifecycle |\n| Interchangeable instances | Unique identity matters |\n| Defined by attributes | Defined by continuity |\n| Examples: Money, Address, DateRange | Examples: User, Order, Account |\n\n### Aggregates\n\nA cluster of entities and value objects with a defined boundary. One entity is the aggregate root.\n\n```\nAggregate Design Rules:\n\n1. PROTECT invariants at aggregate boundary\n2. REFERENCE other aggregates by identity only\n3. UPDATE one aggregate per transaction\n4. DESIGN small aggregates (prefer single entity)\n\nExample:\n┌─────────────────────────────────────────────────────────────┐\n│ Aggregate: Order                                            │\n│ Root: Order (entity)                                        │\n├─────────────────────────────────────────────────────────────┤\n│  ┌─────────────────┐                                        │\n│  │ Order (Root)    │◄── Aggregate Root                      │\n│  │ - orderId       │                                        │\n│  │ - customerId ───┼──► Reference by ID only                │\n│  │ - status        │                                        │\n│  └────────┬────────┘                                        │\n│           │                                                 │\n│  ┌────────▼────────┐                                        │\n│  │ OrderItem       │◄── Inside aggregate                    │\n│  │ - productId ────┼──► Reference by ID only                │\n│  │ - quantity      │                                        │\n│  │ - price (Money) │◄── Value Object                        │\n│  └─────────────────┘                                        │\n└─────────────────────────────────────────────────────────────┘\n```\n\n#### Aggregate Sizing\n\n```\nStart Small:\n- Begin with single-entity aggregates\n- Expand only when invariants require it\n\nSigns of Too-Large Aggregate:\n- Frequent optimistic lock conflicts\n- Loading too much data for simple operations\n- Multiple users editing simultaneously\n- Transactional failures across unrelated data\n\nSigns of Too-Small Aggregate:\n- Invariants not protected\n- Business rules scattered across services\n- Eventual consistency where immediate is required\n```\n\n### Domain Events\n\nRepresent something that happened in the domain. Immutable facts about the past.\n\n```\nEvent Structure:\n┌─────────────────────────────────────────┐\n│ Event: OrderPlaced                      │\n├─────────────────────────────────────────┤\n│ eventId: UUID                           │\n│ occurredAt: DateTime                    │\n│ aggregateId: orderId                    │\n│ payload:                                │\n│   - customerId                          │\n│   - items                               │\n│   - totalAmount                         │\n└─────────────────────────────────────────┘\n\nNaming Convention:\n- Past tense (OrderPlaced, not PlaceOrder)\n- Domain language (not technical)\n- Include all relevant data (event is immutable)\n\nclass OrderPlaced implements DomainEvent {\n  readonly eventId = uuid();\n  readonly occurredAt = new Date();\n\n  constructor(\n    readonly orderId: OrderId,\n    readonly customerId: CustomerId,\n    readonly items: OrderItemData[],\n    readonly totalAmount: Money\n  ) {}\n}\n```\n\n#### Event Patterns\n\n| Pattern | Description | Use Case |\n|---------|-------------|----------|\n| **Event Notification** | Minimal data, query for details | Loose coupling |\n| **Event-Carried State** | Full data in event | Performance, offline |\n| **Event Sourcing** | Events as source of truth | Audit, temporal queries |\n\n### Repositories\n\nAbstract persistence, providing collection-like access to aggregates.\n\n```\nRepository Principles:\n- One repository per aggregate\n- Returns aggregate roots only\n- Hides persistence mechanism\n- Supports aggregate reconstitution\n\ninterface OrderRepository {\n  findById(id: OrderId): Promise\u003COrder | null>;\n  findByCustomer(customerId: CustomerId): Promise\u003COrder[]>;\n  save(order: Order): Promise\u003Cvoid>;\n  delete(order: Order): Promise\u003Cvoid>;\n}\n\n\u002F\u002F Implementation hides persistence details\nclass PostgresOrderRepository implements OrderRepository {\n  async findById(id: OrderId): Promise\u003COrder | null> {\n    const row = await this.db.query('SELECT * FROM orders WHERE id = $1', [id]);\n    return row ? this.reconstitute(row) : null;\n  }\n\n  private reconstitute(row: OrderRow): Order {\n    \u002F\u002F Rebuild aggregate from persistence\n  }\n}\n```\n\n## Consistency Strategies\n\n### Transactional Consistency (ACID)\n\nUse for invariants within an aggregate:\n\n```\nRule: One aggregate per transaction\n\n\u002F\u002F Good: Single aggregate updated\nasync function addItemToOrder(orderId: OrderId, item: OrderItem) {\n  const order = await orderRepo.findById(orderId);\n  order.addItem(item);  \u002F\u002F Business rules enforced\n  await orderRepo.save(order);\n}\n\n\u002F\u002F Bad: Multiple aggregates in one transaction\nasync function createOrderWithInventory() {\n  await db.transaction(async (tx) => {\n    await orderRepo.save(order, tx);\n    await inventoryRepo.decrement(productId, quantity, tx);  \u002F\u002F Don't do this\n  });\n}\n```\n\n### Eventual Consistency\n\nUse for consistency across aggregates:\n\n```\nPattern: Domain Events + Handlers\n\n\u002F\u002F Order aggregate publishes event\nclass Order {\n  submit(): void {\n    this.status = OrderStatus.Placed;\n    this.addEvent(new OrderPlaced(this.id, this.customerId, this.items));\n  }\n}\n\n\u002F\u002F Separate handler updates inventory (eventually)\nclass InventoryHandler {\n  async handle(event: OrderPlaced): Promise\u003Cvoid> {\n    for (const item of event.items) {\n      await this.inventoryService.reserve(item.productId, item.quantity);\n    }\n  }\n}\n```\n\n### Saga Pattern\n\nCoordinate multiple aggregates with compensation:\n\n```\nSaga: Order Fulfillment\n\n┌─────────┐     ┌─────────────┐     ┌─────────────┐     ┌─────────┐\n│ Create  │────►│ Reserve     │────►│ Charge      │────►│ Ship    │\n│ Order   │     │ Inventory   │     │ Payment     │     │ Order   │\n└────┬────┘     └──────┬──────┘     └──────┬──────┘     └─────────┘\n     │                 │                   │\n     │ Compensate:     │ Compensate:       │ Compensate:\n     │ Cancel Order    │ Release Inventory │ Refund Payment\n     ▼                 ▼                   ▼\n\nOn failure at any step, execute compensation in reverse order.\n```\n\n### Choosing Consistency\n\n| Scenario | Strategy |\n|----------|----------|\n| Within single aggregate | Transactional (ACID) |\n| Across aggregates, same service | Eventual (domain events) |\n| Across services | Saga with compensation |\n| Read model updates | Eventual (projection) |\n\n## Anti-Patterns\n\n### Anemic Domain Model\n\n```\n\u002F\u002F Anti-pattern: Logic outside domain objects\nclass Order {\n  id: string;\n  items: Item[];\n  status: string;\n}\n\nclass OrderService {\n  calculateTotal(order: Order): number { ... }\n  validate(order: Order): boolean { ... }\n  submit(order: Order): void { ... }\n}\n\n\u002F\u002F Better: Logic inside domain objects\nclass Order {\n  private items: OrderItem[];\n  private status: OrderStatus;\n\n  get total(): Money {\n    return this.items.reduce((sum, item) => sum.add(item.subtotal), Money.zero());\n  }\n\n  submit(): void {\n    this.validate();\n    this.status = OrderStatus.Submitted;\n  }\n}\n```\n\n### Large Aggregates\n\n```\n\u002F\u002F Anti-pattern: Everything in one aggregate\nclass Customer {\n  orders: Order[];           \u002F\u002F Could be thousands\n  addresses: Address[];\n  paymentMethods: PaymentMethod[];\n  preferences: Preferences;\n  activityLog: Activity[];   \u002F\u002F Could be millions\n}\n\n\u002F\u002F Better: Separate aggregates referenced by ID\nclass Customer {\n  id: CustomerId;\n  defaultAddressId: AddressId;\n  defaultPaymentMethodId: PaymentMethodId;\n}\n\nclass Order {\n  customerId: CustomerId;    \u002F\u002F Reference by ID\n}\n```\n\n### Primitive Obsession\n\n```\n\u002F\u002F Anti-pattern: Primitive types for domain concepts\nfunction createOrder(\n  customerId: string,\n  productId: string,\n  quantity: number,\n  price: number,\n  currency: string\n) { ... }\n\n\u002F\u002F Better: Value objects\nfunction createOrder(\n  customerId: CustomerId,\n  productId: ProductId,\n  quantity: Quantity,\n  price: Money\n) { ... }\n```\n\n## Implementation Checklist\n\n### Aggregate Design\n\n- [ ] Single entity can be aggregate root\n- [ ] Invariants are protected at boundary\n- [ ] Other aggregates referenced by ID only\n- [ ] Fits in memory comfortably\n- [ ] One transaction per aggregate\n\n### Entity Implementation\n\n- [ ] Has unique identifier\n- [ ] Equality based on ID\n- [ ] Encapsulates business rules\n- [ ] State changes through methods\n\n### Value Object Implementation\n\n- [ ] All properties immutable\n- [ ] Equality based on attributes\n- [ ] Self-validating\n- [ ] Operations return new instances\n\n### Repository Implementation\n\n- [ ] One per aggregate\n- [ ] Returns aggregate roots only\n- [ ] Hides persistence details\n- [ ] Supports queries needed by domain\n\n## References\n\n- [Pattern Implementation Examples](examples\u002Fddd-patterns.md) - Code examples in multiple languages\n- [Aggregate Design Guide](reference.md) - Detailed aggregate sizing heuristics\n",{"name":5,"description":7},"main","7850740bd837adb32f0a109ab2af82482196c6f2","skills\u002Frsmdt-the-startup\u002Fplugins\u002Fteam\u002Fskills\u002Fdevelopment\u002Fdomain-driven-design",1,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills","https:\u002F\u002Fzturnsgo.com","https:\u002F\u002Fgithub.com\u002Fshengdabai","https:\u002F\u002Fzturnsgo.com\u002F","AI × education creator — producer, not consumer. Taught 6,000+ learners; shipping learning tools & daily essays with Claude Code, practicing @xiaolai's way 🥋","2026-11-01 21:28:23",{"source":8,"skillName":5,"commands":65,"prompt":75,"zipAvailable":76},[66,69,72],{"tool":67,"command":68},"npx","npx skills add shengdabai\u002FTony-Claude-Code-Skills --skill domain-driven-design",{"tool":70,"command":71},"bunx","bunx skills add shengdabai\u002FTony-Claude-Code-Skills --skill domain-driven-design",{"tool":73,"command":74},"pnpm","pnpm dlx skills add shengdabai\u002FTony-Claude-Code-Skills --skill domain-driven-design","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Frsmdt-the-startup\u002Fplugins\u002Fteam\u002Fskills\u002Fdevelopment\u002Fdomain-driven-design\u002FSKILL.md",true,[],[79,88,96,104,112,120],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":83,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":87},"01M73H7XKBHE1ETQDZT94MF9HH","seedance-prompt-en","Write effective prompts for Jimeng Seedance 2.0 multimodal AI video generation. Use when users want to create video prompts using text, images, videos, and audio inputs with the @ reference system. Covers camera movements, effects replication, video extension, editing, music beat-matching, e-commerce ads, short dramas, and educational content.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fseedance-prompt-en\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fseedance-prompt-en\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":92,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":87},"01M73GRE9998Q1DZWC71N41JWG","onepage-pdf","Convert an HTML page into a single continuous-page PDF (one tall page, no pagination breaks), preserving desktop layout, backgrounds and selectable text. Use when the user asks to turn an HTML file\u002Freport\u002Fproposal into a \"single-page PDF\", \"long PDF\", \"不分页 PDF\", \"单页 PDF\", \"长图式 PDF\", or complains that an HTML-to-PDF export breaks into pages or cuts content. Supports optional string redaction with leak verification.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fonepage-pdf\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fonepage-pdf\u002FSKILL.md",[],[],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":100,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":87},"01M73GQG1KZDADVPV3MHAT1J5A","native-feel-cross-platform-desktop","Use when the user is designing, prototyping, or rewriting a desktop app that must run on multiple OSes (macOS + Windows, optionally Linux) AND feel indistinguishable from a native app to its users — fast launch, native windowing, native input handling, native materials. Trigger words include \"cross-platform desktop\", \"Electron alternative\", \"Tauri vs native\", \"WebView wrapper\", \"near-native performance\", \"Raycast architecture\", \"WebKit\u002FWebView2 quirks\", \"WKWebView\", \"system tray app\", \"global hotkey app\", \"launcher app\". Do NOT trigger this skill for pure web apps, pure mobile apps, or for greenfield projects that have no native-feel requirement.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fnative-feel-cross-platform-desktop\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fnative-feel-cross-platform-desktop\u002FSKILL.md",[],[],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":108,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":87},"01M73G87PDNSMKG2FHWCYER6N8","gstack","Router for the gstack skill suite. (gstack)","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fgstack\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fgstack\u002FSKILL.md",[],[],{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":116,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":87},"01M73G3EAQWKCM8DB8D0N0QSVG","fireworks-tech-graph","Use when the user wants to create any technical diagram - architecture, data flow, flowchart, sequence, agent\u002Fmemory, or concept map - and export as SVG+PNG. Trigger on: \"画图\" \"帮我画\" \"生成图\" \"做个图\" \"架构图\" \"流程图\" \"可视化一下\" \"出图\" \"generate diagram\" \"draw diagram\" \"visualize\" or any system\u002Fflow description the user wants illustrated.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ffireworks-tech-graph\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ffireworks-tech-graph\u002FSKILL.md",[],[],{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":126,"publishedAt":87},"01M73G086AXAH9DW1H5G5N3CPB","dbs-video-extract","接收抖音、小红书、微信视频号等短视频链接或分享文案，查询作品／账号数据并提取语音文字稿，按作者和标题归档为 Markdown。用户希望完整解析短视频、取得数据或文字稿时使用；运行前检查 TikHub 与轻抖使用凭证，缺少时用新手能理解的方式引导购买和安全配置。","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fdbs-video-extract\u002FSKILL.md",[],[]]