# Domain Driven Design

> Design software architecture around business domain models. Use when starting a new project, creating module structure, defining entities and their relationships, or when the user mentions DDD, domain model, bounded context, aggregates, or business logic architecture. Use when this capability is needed.

- Skill: `tomevault-io/domain-driven-design-5` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/domain-driven-design-5`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/domain-driven-design-5/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/domain-driven-design-5

---


# Domain-Driven Design

Apply DDD principles to create architecture that reflects business reality.

## Workflow

1. **Gather domain context**: Ask the user to describe key business entities, their relationships, and core business rules
2. **Define bounded contexts**: Identify distinct subdomains and their boundaries
3. **Model entities and value objects**: Create domain classes that encapsulate business logic
4. **Establish aggregates**: Group related entities with clear aggregate roots
5. **Generate project structure**: Create directories and files reflecting the domain model

## Prompting for context

When user provides incomplete domain information, ask:

- What are the main entities in your domain? (e.g., Order, Customer, Product)
- What states or statuses do these entities have?
- What business rules govern transitions between states?
- How do entities relate to each other?

## Output structure

```
src/
├── domain/
│   ├── entities/
│   │   └── [entity_name].py
│   ├── value_objects/
│   │   └── [value_object_name].py
│   ├── aggregates/
│   │   └── [aggregate_name].py
│   └── services/
│       └── [domain_service].py
├── application/
│   └── use_cases/
└── infrastructure/
    └── repositories/
```

## Example prompt

User: "Create architecture for an e-commerce system"

Response approach:
1. Ask about key entities (Order, Customer, Product, Cart)
2. Clarify business rules (order lifecycle, inventory management)
3. Generate domain model with entities, value objects, and services
4. Create project structure reflecting bounded contexts

## Entity template

```python
from dataclasses import dataclass
from enum import Enum
from typing import List
from datetime import datetime

class OrderStatus(Enum):
    DRAFT = "draft"
    CONFIRMED = "confirmed"
    SHIPPED = "shipped"
    DELIVERED = "delivered"

@dataclass
class Order:
    id: str
    customer_id: str
    items: List["OrderItem"]
    status: OrderStatus
    created_at: datetime
    
    def confirm(self) -> None:
        if self.status != OrderStatus.DRAFT:
            raise ValueError("Only draft orders can be confirmed")
        if not self.items:
            raise ValueError("Cannot confirm empty order")
        self.status = OrderStatus.CONFIRMED
    
    def ship(self) -> None:
        if self.status != OrderStatus.CONFIRMED:
            raise ValueError("Only confirmed orders can be shipped")
        self.status = OrderStatus.SHIPPED
```

## Key principles

- **Ubiquitous language**: Use business terms in code (not technical jargon)
- **Rich domain model**: Entities contain business logic, not just data
- **Aggregate boundaries**: Protect invariants within aggregate roots
- **Domain events**: Capture significant business occurrences

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/mb-mal) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

