domain-driven-design

dralgorhythm's avatarfrom dralgorhythm

Apply Domain-Driven Design patterns. Use when modeling complex business domains, defining bounded contexts, or designing aggregates. Covers entities, value objects, and repositories.

⭐1stars🔀0forks📁View on GitHub🕐Updated Dec 20, 2025

When & Why to Use This Skill

This Claude skill facilitates the application of Domain-Driven Design (DDD) patterns to manage software complexity. It helps developers model intricate business domains, define bounded contexts, and implement core building blocks like entities, value objects, and aggregates, ensuring that the software architecture remains closely aligned with business goals and remains maintainable over time.

Use Cases

  • Strategic Modeling: Defining bounded contexts and context maps to organize large-scale software systems and clarify team responsibilities.
  • Tactical Design: Implementing entities, value objects, and aggregates to encapsulate complex business logic and maintain data consistency.
  • Ubiquitous Language Development: Bridging the gap between technical teams and domain experts by ensuring code and documentation reflect shared business terminology.
  • Architectural Refactoring: Applying anti-corruption layers to safely integrate modern domain models with legacy infrastructure or external APIs.
namedomain-driven-design
descriptionApply Domain-Driven Design patterns. Use when modeling complex business domains, defining bounded contexts, or designing aggregates. Covers entities, value objects, and repositories.
allowed-toolsRead, Write, Glob, Grep

Domain-Driven Design

Core Concepts

Ubiquitous Language

Use the same terminology as domain experts. Code should read like business documentation.

Bounded Context

A boundary within which a particular domain model is defined and applicable.

Context Map

Shows how bounded contexts relate to each other.

Building Blocks

Entity

Has identity that persists over time. Equality based on ID.

class User {
  constructor(
    public readonly id: UserId,
    public email: Email,
    public name: string
  ) {}
}

Value Object

Immutable, equality based on attributes.

class Email {
  private constructor(public readonly value: string) {}

  static create(value: string): Email {
    if (!value.includes('@')) {
      throw new Error('Invalid email');
    }
    return new Email(value);
  }

  equals(other: Email): boolean {
    return this.value === other.value;
  }
}

Aggregate

Cluster of entities and value objects with a root entity.

class Order { // Aggregate Root
  private items: OrderItem[] = [];

  addItem(product: ProductId, quantity: number): void {
    // Business rules enforced here
    this.items.push(new OrderItem(product, quantity));
  }

  get total(): Money {
    return this.items.reduce((sum, item) => sum.add(item.subtotal), Money.zero());
  }
}

Repository

Abstracts data access for aggregates.

interface OrderRepository {
  findById(id: OrderId): Promise<Order | null>;
  save(order: Order): Promise<void>;
}

Domain Event

Something that happened in the domain.

class OrderPlaced {
  constructor(
    public readonly orderId: OrderId,
    public readonly userId: UserId,
    public readonly occurredAt: Date
  ) {}
}

Strategic Patterns

Anti-Corruption Layer

Translate between your model and external systems.

Shared Kernel

Shared subset of domain model between contexts.

Customer-Supplier

Upstream provides what downstream needs.