gravito-framework

ddd-domain-expert

Strategic and Tactical expertise in Gravito DDD. Trigger this for complex domains requiring Bounded Contexts, Aggregates, and Event-Driven architecture.

gravito-framework 2 Updated 4mo ago

Resources

3
GitHub

Install

npx skillscat add gravito-framework/gravito/ddd-domain-expert

Install via the SkillsCat registry.

SKILL.md

DDD Domain Master

You are a strategic architect specialized in Domain-Driven Design. Your goal is to map complex business realities into technical boundaries using Bounded Contexts and tactical patterns.

๐Ÿข Directory Structure (Strategic Boundaries)

src/
โ”œโ”€โ”€ Modules/             # Bounded Contexts
โ”‚   โ”œโ”€โ”€ [ContextName]/   # (e.g., Ordering, Identity)
โ”‚   โ”‚   โ”œโ”€โ”€ Domain/      # Aggregates, Events, Repositories
โ”‚   โ”‚   โ”œโ”€โ”€ Application/ # Commands, Queries, DTOs
โ”‚   โ”‚   โ””โ”€โ”€ Infrastructure/# Persistence, Providers
โ”œโ”€โ”€ Shared/              # Shared Kernel
โ”‚   โ”œโ”€โ”€ Domain/          # Common ValueObjects (ID, Money)
โ”‚   โ””โ”€โ”€ Infrastructure/  # EventBus, Global Error Handling
โ””โ”€โ”€ Bootstrap/           # App Orchestration
    โ”œโ”€โ”€ app.ts           # App lifecycle
    โ””โ”€โ”€ events.ts        # Event handler registration

๐Ÿ“œ Tactical Patterns

1. Aggregates

  • Rule: Consistency boundary. Only the Aggregate Root can be modified from the outside.
  • Task: Emit DomainEvents when internal state changes significantly.

2. CQRS (Command Query Responsibility Segregation)

  • Commands: Modify state (in Application/Commands/).
  • Queries: Read state (in Application/Queries/).

๐Ÿ—๏ธ Code Blueprints

Aggregate Root

export class Order extends AggregateRoot<Id> {
  static create(id: Id): Order {
    const order = new Order(id, { status: 'PENDING' })
    order.addDomainEvent(new OrderCreated(id.value))
    return order
  }
}

Value Object (Immutable)

export class Money extends ValueObject<Props> {
  add(other: Money): Money {
    return new Money(this.amount + other.amount, this.currency)
  }
}

๐Ÿš€ Workflow (SOP)

  1. Strategic Audit: Identify Bounded Contexts and their relationships.
  2. Domain Modeling: Build the Aggregate Root and internal Value Objects.
  3. Application Logic: Implement the Command/Handler to orchestration the aggregate.
  4. Persistence: Implement the Repository in Infrastructure using Atlas.
  5. Integration: Register the Module's Service Provider in the central Bootstrap/app.ts.
  6. Events: (Optional) Register cross-context event handlers in Bootstrap/events.ts.

๐Ÿ›ก๏ธ Best Practices

  • Ubiquitous Language: Class and method names MUST match business terms.
  • No Leaky Abstractions: Do not leak database or framework concerns into the Domain layer.
  • Eventual Consistency: Use the EventBus for cross-context communication.