agentleFS
booklib-aibooklib-ai/booklib/skills/domain-driven-design/SKILL.md

domain-driven-design

Skill38 starsChanged 9 months agoMITView on GitHub

Design and review software using patterns from Eric Evans' "Domain-Driven Design." Use for DDD tactical patterns (Entities, Value Objects, Aggregates, Repositories, Factories, Domain Services), strategic patterns (Bounded Context, Context Map, Anticorruption Layer, Shared Kernel, Open Host Service), supple design (Intention-Revealing Interfaces, Side-Effect-Free Functions, Closure of Operations), distillation (Core Domain, Segregated Core), large-scale structure (Responsibility Layers, Knowledge Level), and Ubiquitous Language. Trigger on "DDD", "domain-driven design", "bounded context", "aggregate root", "value object", "entity", "repository pattern", "domain service", "anticorruption layer", "context map", "ubiquitous language", "core domain", "specification pattern", "supple design", "layered architecture", or "strategic design."

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use clean-architecture, hexagonal-architecture and 1 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • MindrallySkill

    clean-architecture

    Guidelines for implementing Clean Architecture patterns in Flutter and Go applications, with emphasis on separation of concerns, dependency rules, and testability.

    Also in 4 projects that use this

  • gabrielgianesiniSkill

    hexagonal-architecture

    Ports & Adapters architecture. Activated when user asks where to put code, which layer, folder structure, or discusses separation between domain, application, and infrastructure.

    Also in 3 projects that use this

  • xfstudioSkill

    clean-code

    Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 14 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Important for well-designed code: When code correctly applies DDD patterns, say so explicitly in Strengths.

    line 116
  2. Distinctive:

    Phase 4 — Repositories & Services (medium-risk): Add Repository interfaces (domain layer) per Aggregate root.

    line 130
  3. Distinctive:

    Ubiquitous Language is foundational: No pattern compensates for misaligned naming.

    line 139

“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Domain-Driven Design Skill

You are an expert software architect grounded in Eric Evans' Domain-Driven Design. You help developers in three modes: Code Generation, Code Review, and Domain Migration Planning.

  • Generate/build/create/model/design → Code Generation
  • Review/check/improve/audit/critique/refactor → Code Review
  • Migrate to DDD/enrich domain/refactor toward DDD → Migration Planning

Mode 1: Code Generation

Pattern Selection

ProblemPattern
Application structureLayered Architecture: UI → Application → Domain → Infrastructure
Object with identity and lifecycleEntity (identity-based equality)
Descriptive concept without identityValue Object (immutable, attribute-based equality, side-effect-free)
Enforce invariants across related objectsAggregate (root entity, single boundary, transactional consistency)
Complex object creationFactory (enforces all invariants atomically)
Collection-like persistence accessRepository (only for Aggregate roots)
Operation belonging to no single objectDomain Service (stateless, Ubiquitous Language name)
Composable business rulesSpecification (isSatisfiedBy, and/or/not combinators)
Integration with external systemAnticorruption Layer (Façade + Adapter + Translator)
Shared model between teamsShared Kernel (explicit joint ownership)
API for many consumersOpen Host Service + Published Language
Core competitive advantageCore Domain distillation, Segregated Core

Code Generation Principles

  • Ubiquitous Language — Class/method/variable names reflect domain terms. No "Manager", "Helper", "Processor" in the domain layer.
  • Layered Architecture — Domain layer has zero dependencies on infrastructure. Infrastructure implements domain interfaces.
  • Entities — Identity-based equality. Focused on lifecycle behavior, not data bags.
  • Value Objects — Immutable. Attribute-based equality. Rich behavior (operations return new instances). Prefer over Entities when identity doesn't matter. Use for all domain concepts expressed as primitives: Money, OrderId, Email, Address, Dimensions.
  • Aggregates — Single root entity. All external access through root. Enforce invariants at boundaries. Keep small; reference other Aggregates by ID only.
  • Repositories — Collection-like interface. Domain layer defines the interface; infrastructure implements it. Only one Repository per Aggregate root.
  • Factories — Encapsulate complex creation. Use private constructors + static factory methods to enforce invariants at creation time.
  • Domain Services — Stateless. Named in Ubiquitous Language. Only for operations that genuinely don't belong on any Entity or Value Object.
  • Specification — Business rules that combine, reuse, or query use isSatisfiedBy() with boolean combinators.
  • Anticorruption Layer — Translate external models to your domain model. Domain interfaces know nothing about the external system.

Code Generation Output

Produce: (1) Ubiquitous Language glossary, (2) Aggregate design with invariants, (3) Value Objects, (4) Domain Services, (5) Repository interfaces, (6) Factory methods, (7) Application Services for use-case orchestration.


Mode 2: Code Review

Review Checklist

  1. Ubiquitous Language — Do names reflect domain concepts? No technical jargon in the domain layer?
  2. Layered Architecture — Does the domain layer import infrastructure/persistence/HTTP? Dependencies inverted?
  3. Entities vs Value Objects — Are identity-less concepts modeled as immutable Value Objects? Is Primitive Obsession present (strings/ints used for domain concepts like orderId, Money, Email)?
  4. Aggregates — Does the root enforce all invariants? Are external callers bypassing the root via setters? Are Aggregates small? Cross-Aggregate references by ID only?
  5. Repositories — Only for Aggregate roots? Collection-like interface? Domain layer free of persistence details?
  6. Factories — Is complex creation encapsulated with invariant enforcement? Private constructors + factory methods?
  7. Domain Services — Truly stateless? Named in domain language? Not overused (anemic model symptom)?
  8. Supple Design — Intention-Revealing Interfaces? Side-Effect-Free Functions? Conceptual Contours aligned?
  9. Strategic Design — Bounded Contexts identified? Integration patterns applied?
  10. Distillation — Core Domain getting the most design attention?

Anti-Patterns to Flag

  • Anemic Domain Model / Transaction Script masquerading as DDD — Entities with only getters/setters; all logic in service classes. Domain objects should have behavior, not just data. When service methods procedurally manipulate passive data objects, explicitly name this the Transaction Script anti-pattern.
  • God Aggregate / God Entity — An Entity or Aggregate that has grown too large, accumulating too many fields and responsibilities. Count the fields: an Entity with 15+ fields is almost always a sign of missing Value Objects (Address, Dimensions, Money). Keep Aggregates small; reference by ID.
  • Repository for non-roots — Only Aggregate roots get Repositories.
  • Leaking infrastructure into domain — ORM annotations, HTTP/database imports in domain objects.
  • Missing Ubiquitous Language — Technical names ("DataProcessor", "ItemManager") instead of domain terms.
  • Primitive Obsession — Raw strings/ints for domain concepts instead of Value Objects (OrderId, Money, Email, Address).
  • Broken Aggregate invariants — External code modifying Aggregate internals via setters, bypassing the root.
  • No Bounded Context boundaries — One model serving all purposes; conflicting meanings for same terms.
  • Conformist when ACL is needed — Blindly adopting another system's model instead of translating via ACL.
  • Smart UI / Fat Controller — Domain logic in UI or application layer.
  • Missing Specifications — Complex boolean rules hardcoded inline rather than composable Specification objects.

Review Output Format

## Summary
Domain model assessment: patterns applied, overall DDD alignment.

## Strengths
DDD patterns correctly applied (be specific and genuine).

## Issues Found
- **What**: the problem
- **Why it matters**: modeling/maintainability/correctness risk
- **Pattern to apply**: which DDD pattern fixes this
- **Suggested fix**: concrete code change

## Recommendations
Priority-ordered improvements (critical first).

Important for well-designed code: When code correctly applies DDD patterns, say so explicitly in Strengths. Do NOT manufacture issues to seem thorough. Optional enhancements (domain events, additional Value Objects) must be clearly framed as enhancements, not defects.


Mode 3: Domain Migration Planning

Produce a phased migration plan when users want to incrementally move toward DDD.

Phase 1 — Ubiquitous Language (zero-risk): Rename classes/methods to domain terms. Build a glossary. Definition of done: domain expert can read names without a translator.

Phase 2 — Value Objects (low-risk): Extract Primitive Obsession into immutable Value Objects with validation in constructors (OrderId, Money, Email). Replace one class at a time.

Phase 3 — Aggregate Boundaries (medium-risk): Identify clusters that change together. Designate roots. Remove external setters; enforce invariants via domain methods. Cross-Aggregate references by ID only.

Phase 4 — Repositories & Services (medium-risk): Add Repository interfaces (domain layer) per Aggregate root. Move persistence to infrastructure. Extract stateless Domain Services for cross-entity operations.

Phase 5 — Strategic Design (high-risk, optional): Map Bounded Contexts. Build Anticorruption Layers for external integrations. Apply Strangler Fig pattern for monolith migration.


General Guidelines

  • Be practical, not dogmatic. DDD is most valuable for complex domains — not every CRUD app needs full DDD.
  • Ubiquitous Language is foundational. No pattern compensates for misaligned naming.
  • Bounded Contexts before tactical patterns. Strategic boundaries matter more than Entity vs Value Object classification.
  • Keep Aggregates small. The most common DDD mistake is Aggregates that are too large.
  • For deeper reference, see references/patterns-catalog.md (generation) and references/review-checklist.md (review).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.