domain-driven-design
This skill should be used whenever domain modeling is taking place. It provides specialized guidance for type-driven and data-driven design based on Rich…
от bfollington★ 53 звезды на GitHub
Установить domain-driven-design в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Domain-Driven Design
Overview
This skill provides guidance for domain modeling based on Rich Hickey's data-oriented design principles and Scott Wlaschin's type-driven design approach. Focus on building systems that make illegal states unrepresentable, prioritize data and transformations over objects and methods, and establish a ubiquitous language that bridges technical implementation and business domain.
Core Principles
Rich Hickey's Data-Oriented Design
Simplicity over Ease
- Favor simple constructs that can be understood independently
- Avoid complecting (intertwining) unrelated concerns
- Separate policy from mechanism, data from behavior
Data is King
- Model the domain using pure data structures, not objects with behavior
- Prefer generic data structures (maps, sets, vectors) over custom classes when appropriate
- Data should be self-describing and inspectable
- Functions transform data; data does not execute behavior
Value of Values
- Use immutable values to represent facts
- Values enable local reasoning and simple equality
- Values can be freely shared without coordination
- Consider: what are the immutable facts in this domain?
Decomplecting
- Identify what is truly essential to the domain vs. incidental complexity
- Separate when-it-happens from what-happens
- Separate mechanism from policy
- Question: are these concerns actually separate, or have we tangled them?
Scott Wlaschin's Type-Driven Design
Make Illegal States Unrepresentable
- Use the type system to eliminate invalid states at compile time
- Model optional values explicitly (Option/Maybe types)
- Use sum types (discriminated unions) for states that are mutually exclusive
- Avoid primitive obsession; create domain-specific types
Domain Modeling Made Functional
- Model workflows as data transformations: Input → Process → Output
- Explicitly model business rules as functions
- Separate validation from business logic
- Think in terms of: What can happen? What are the valid transitions?
Railway-Oriented Programming
- Model success and failure paths explicitly (Result types)
- Chain operations that can fail using bind/flatMap
- Keep the happy path clear and linear
- Handle errors at appropriate boundaries
Types as Documentation
- Type signatures should communicate intent
- Use newtype wrappers for semantic clarity (UserId, EmailAddress, Timestamp)
- Constrain inputs to valid ranges using types
- Let the type system guide API design
DDD Building Blocks
Entities vs Value Objects
Entities are defined by identity, not attributes:
- Have a unique identifier (ID, account number, etc.)
- Can change over time while maintaining identity
- Two entities with same attributes but different IDs are distinct
- Used when domain experts refer to things by name/ID
Value Objects are defined entirely by attributes:
- No unique identifier
- Immutable
- Two value objects with same attributes are interchangeable
- Used when only the value matters, not identity
Decision Guide:
- Ask: Do domain experts refer to this by ID/name? → Entity
- Ask: Can I replace it with an equivalent copy? → If yes: Value Object
Aggregates and Aggregate Roots
Aggregate: A cluster of entities and value objects treated as a single unit for data changes.
Aggregate Root: The single entity through which all external access to the aggregate must pass.
Purpose:
- Define transactional consistency boundaries
- Enforce invariants that span multiple objects
- Simplify the model by grouping related concepts
Rules:
- External references go only to the aggregate root (use ID references)
- Root enforces all invariants for the entire aggregate
- Transactions don't cross aggregate boundaries (use eventual consistency)
- Keep aggregates small for better performance and scalability
When NOT to create an aggregate:
- Objects can be modified independently
- No shared invariants requiring transactional consistency
- Different objects have different lifecycles
Bounded Contexts
Definition: An explicit boundary within which a domain model applies.
Purpose:
- Divide large domains into manageable pieces
- Allow same term to have different meanings in different contexts
- Prevent model corruption from mixing incompatible concepts
Key Insight: Ubiquitous language is only ubiquitous within a context. "Customer" in Sales context may be different from "Customer" in Shipping context.
When modeling:
- Identify which bounded context you're in
- Make context boundaries explicit in code structure (separate modules/namespaces)
- Use anti-corruption layers when integrating across contexts
- Document relationships between contexts (context map)
Domain Events
Definition: Something important that happened in the domain.
Characteristics:
- Named in past tense (OrderPlaced, PaymentProcessed, UserRegistered)
- Immutable facts
- Domain experts care about them
- Can trigger reactions
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/ddd_foundations_and_patterns.md
- references/rich_hickey_principles.md
- references/visualization_examples.md
- references/wlaschin_patterns.md
FAQ
Что делает скилл domain-driven-design?
This skill should be used whenever domain modeling is taking place. It provides specialized guidance for type-driven and data-driven design based on Rich Hickey and Scott Wlaschin's principles. The skill helps contextualize current modeling within the existing domain model, identifies inconsistencies, builds ubiquitous language, and creates visualizations (Mermaid, Graphviz/DOT, ASCII diagrams) to communicate domain concepts clearly. Use this skill when designing types, modeling business domains, refactoring domain logic, or ensuring domain consistency across a codebase.
Как установить скилл domain-driven-design?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл domain-driven-design запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…