SuperAPI AI Directory

ddd-domain-interactions

Coding & development

View repository

Updated 10-15 15:16

About this skill

DDD Domain Interactions

English version: English

When to Use

  • The aggregate boundaries have been designed, and the collaboration mechanisms between aggregates, and between aggregates and the outside, need to be defined.
  • It is necessary to answer "how aggregates communicate, who orchestrates cross-aggregate processes, and what the persistence contracts are".
  • As the final step of tactical modeling, complete all the "connecting tissue".

Input Requirements

  • Required: Aggregate catalog and invariant table (from ddd-aggregates), event candidate list (from ddd-discover)。
  • Optional: Context mapping and contract information (from ddd-context-map), context catalog and glossary (from ddd-contexts, used to distinguish the boundary between domain events and integration events).

Process

  1. Event normalization: Unify event naming rules (past tense, business-readable, no technical terms); define trigger conditions, source aggregate, key fields, and ordering requirements for each event.
  2. Distinguish scope: Distinguish domain events (within a context) from integration events (cross-context/published externally).
  3. Reliability strategy: Define idempotency keys, replay strategies, deduplication windows, and dead-letter handling for each event.
  4. Domain services: Identify operations that do not belong to any single aggregate but carry domain logic, and define them as domain services—clarifying inputs, outputs, aggregates used, and events.
  5. Repository interfaces: Define the semantic interface of the repository for each aggregate (load, persist, query)—define only the contract, without implementation.
  6. Factories: Identify complex aggregate creation logic and define factory methods—clarifying creation conditions, validation rules, and initial state.
  7. Subscribers and side effects: Clarify the consumers of each event, triggered actions, compensation strategies, and monitoring metrics.

Output

Artifact Structural Requirements
Domain event catalog Table: event name, source aggregate, trigger condition, key fields, scope (Domain/Integration)
Integration event contracts Table: event name, publisher, consumer, contract owner, version strategy, compatibility window
Idempotency and replay strategies Table: event, idempotency key, deduplication window, replay rules, exception handling
Domain service definitions Table: service name, responsibility, input, output, dependent aggregates/events, logic that should not be included
Repository interface list Table: aggregate, method signature (semantic), semantic description, query boundary
Factory list Table: factory name/method, creation target, creation conditions, validation rules, initial state
Subscribers and side effects Table: event, subscriber, triggered action, compensation strategy, monitoring metrics

Validation Checklist

  • All event names use the past tense, with no technical term contamination
  • Events published across contexts have a version strategy and compatibility window
  • Key events provide idempotency keys and replay strategies
  • Domain services do not contain business logic that should belong to aggregates (avoid anemic models)
  • Repository interfaces define only semantic contracts, without implementation details (SQL, ORM)
  • Every complex creation logic has a corresponding factory (no bare new in the application layer)

Retroactive trigger

  • The event needs to carry private data of another aggregate (a clean event schema cannot be designed) → Retrospect to ddd-aggregates(aggregate boundaries need to be adjusted to ensure the event is self-contained).

Example

@ddd-domain-interactions
基于以下聚合设计,帮我设计领域交互层:
- 聚合:Booking(根:Booking,VO:TimeSlot, BookingStatus)
- 聚合:RoomSchedule(根:RoomSchedule,VO:TimeSlotOccupancy)
- 事件候选:BookingConfirmed, BookingCancelled, CheckInRecorded
请输出领域事件目录、领域服务、仓储接口与订阅者清单。