agentleFS
patfornapatforna/core-skills/skills/ddd/SKILL.md

ddd

Skill0 starsChanged 5 months agoMITView on GitHub

Domain-driven design (Evans-style). Use when modelling domains, structuring modules, naming things, or reviewing domain model design. TRIGGER when: user asks about domain modelling, bounded contexts, aggregates, entities vs value objects, or ubiquitous language. DO NOT TRIGGER when: purely algorithmic code with no domain model.

21 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use convention-learner, opentelemetry and 8 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.
  • codewithmukeshSkill

    convention-learner

    Detects and enforces project-specific coding conventions by analyzing existing codebase patterns. Learns naming conventions, folder structure, test organization, and coding style from the existing code. Load when: "conventions", "coding standards", "project patterns", "enforce style", "detect patterns", "learn conventions", "code consistency".

    Also in 3 projects that use this

  • codewithmukeshSkill

    opentelemetry

    OpenTelemetry observability for .NET 10 applications. Covers traces, metrics, and logs using the OpenTelemetry SDK with OTLP export. Includes custom ActivitySource, IMeterFactory metrics, resource configuration, and Aspire Dashboard integration. Load this skill when setting up distributed tracing, custom metrics, OTLP export, or when the user mentions "OpenTelemetry", "OTLP", "traces", "spans", "Activity", "ActivitySource", "metrics", "IMeterFactory", "Meter", "Counter", "Histogram", "Gauge", "telemetry", "observability", "distributed tracing", "OTEL", or "Aspire Dashboard".

    Also in 3 projects that use this

  • MovGP0Skill

    modern-csharp

    Modern C# style guidance for Bendex and MicroSea code changes, including primary constructors, expression-bodied members, var usage, target-typed new, lambdas, and pattern matching.

    Also in 3 projects that use this

  • MicrosoftSkill

    resilience

    Apply resilience patterns (retry, backoff, circuit breaking) when writing or reviewing code that makes outbound HTTP/REST calls, database operations, or any I/O that can experience transient failures. Use this skill when: (1) writing new code that calls external services or APIs, (2) reviewing code that uses fetch, HTTP clients, or service-to-service calls, (3) adding queue consumers or workers that interact with remote systems, (4) debugging intermittent failures in production.

    Also in 3 projects that use this

  • hongyuancSkill

    vertical-slice

    Build and evaluate a production-quality vertical slice before advancing from Pre-Production to Production.

    Also in 3 projects that use this

  • wpankSkill

    caching

    Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

30 rules. 0 are common, 29 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 19 edited versions we read keep these.

  • 29

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every class, method, parameter, and module name must come from the domain language -- the terms the user (domain expert) would use.

    line 12
  2. Distinctive:

    If a name in the code does not map to a concept a domain expert would recognise, rename it.

    line 14
  3. Distinctive:

    If two different concepts share a name, you have a Bounded Context problem (see Strategic Design below).

    line 15
  4. Distinctive:

    When introducing a domain concept, classify it using this table:

    line 20
  5. Distinctive:

    Default to Value Object: Only use Entity when identity matters independent of attributes.

    line 31
  6. Distinctive:

    Keep Entities lean -- push attribute-heavy logic into Value Objects owned by the Entity.

    line 37
  7. Distinctive:

    Immutable: no setters, no mutation. All operations return new instances.

    line 42
  8. Distinctive:

    Use VOs for: measurements, quantities, ranges, money, dates, addresses, coordinates, descriptions, identifiers (when identity itself is a …

    line 45
  9. Very specific:

    When an Entity has a cluster of related attributes (e.g., street/city/zip), extract a Value Object.

    line 46
  10. Distinctive:

    Use a Domain Service when an operation:

    line 50
  11. Distinctive:

    Do not put domain logic in application Services.

    line 56
  12. Distinctive:

    Every Aggregate has exactly one root Entity.

    line 64
  13. Distinctive:

    Only the root may be retrieved from a Repository.

    line 67
  14. Distinctive:

    All invariants within the boundary are enforced on every state change -- the boundary is the transaction boundary.

    line 72
  15. Distinctive:

    Keep Aggregates small: Prefer a single Entity root with Value Objects.

    line 77
  16. Distinctive:

    When defining an Aggregate:

    line 82
  17. Distinctive:

    No query technology leaks into the domain layer -- no SQL, no ORM query builders, no storage-specific types.

    line 93
  18. Distinctive:

    Use a Factory when constructing an Aggregate requires assembling multiple parts or enforcing invariants that a simple constructor cannot …

    line 99
  19. Distinctive:

    Every object produced by a Factory must satisfy all invariants -- an Aggregate that exists is valid.

    line 101
  20. Distinctive:

    Do not use Factories for reconstitution from storage.

    line 102
  21. Distinctive:

    If a name requires a comment to explain, rename it.

    line 118
  22. Distinctive:

    Place as much domain logic as possible in functions on Value Objects -- these are naturally side-effect-free.

    line 123
  23. Distinctive:

    When a command is necessary, keep it simple and do not return domain data from it.

    line 124
  24. Distinctive:

    If adding a feature requires modifying many unrelated classes, your contours are wrong.

    line 134
  25. Distinctive:

    When domain logic is buried in conditionals, boolean flags, or string comparisons, a concept is implicit.

    line 148
  26. Distinctive:

    When you notice the same term meaning different things in different parts of the codebase, you have discovered a context boundary.

    line 163
  27. Distinctive:

    When wrapping an external system:

    line 184
  28. Distinctive:

    When code is hard to extend, suspect the model first, not the code structure.

    line 213
  29. Distinctive:

    When domain experts describe a concept the code cannot express, add the concept to the model.

    line 214
  30. Distinctive:

    When a name feels wrong, it is wrong.

    line 215

“Common” is measured: kept by at least 6 in 10 of the 19 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

DDD -- Domain-Driven Design

You structure domain code using Evans-style domain-driven design. Follow these rules exactly.

Ubiquitous Language

Every class, method, parameter, and module name must come from the domain language -- the terms the user (domain expert) would use. When you introduce a new domain concept, name it in the language of the problem, not the language of the solution.

  • If a name in the code does not map to a concept a domain expert would recognise, rename it.
  • If two different concepts share a name, you have a Bounded Context problem (see Strategic Design below).
  • A change to the naming is a change to the model. Treat it as such.

Choosing Building Blocks

When introducing a domain concept, classify it using this table:

If the concept...It is a...Key design rule
Has a lifecycle and must be tracked across state changesEntityDefine identity explicitly. Equality by identity, not attributes.
Is defined entirely by its attributes, with no lifecycleValue ObjectMake immutable. Equality by all attributes. Operations return new instances.
Is an operation that does not belong to any Entity or VODomain ServiceMake stateless. Name from domain. Interface uses domain types only.
Is a cluster of objects with consistency rules between themAggregateDefine a root Entity. Enforce invariants at the boundary.
Is a rule or predicate about a domain objectSpecificationMake a first-class object. Compose with AND/OR/NOT.
Is an interchangeable algorithm for a domain goalPolicy/StrategyUse Strategy pattern. Name from domain ("OverbookingPolicy"), not pattern.

Default to Value Object. Only use Entity when identity matters independent of attributes. Value Objects are simpler, safer, and easier to test.

Entities

  • Define identity with a single, stable, unique identifier. Do not use mutable attributes as identity.
  • Implement equality and hashing based on identity only.
  • Keep Entities lean -- push attribute-heavy logic into Value Objects owned by the Entity.
  • An Entity's primary responsibility is maintaining identity continuity and enforcing invariants on its lifecycle transitions.

Value Objects

  • Immutable: no setters, no mutation. All operations return new instances.
  • Equality by attributes: two VOs with identical attributes are interchangeable.
  • Self-validating: reject invalid state at construction time. A VO that exists is valid.
  • Use VOs for: measurements, quantities, ranges, money, dates, addresses, coordinates, descriptions, identifiers (when identity itself is a value -- e.g. ISBN, SSN).
  • When an Entity has a cluster of related attributes (e.g., street/city/zip), extract a Value Object.

Domain Services

Use a Domain Service when an operation:

  1. Involves multiple Aggregates and does not naturally belong to any one of them.
  2. Is expressed as a verb phrase in the Ubiquitous Language (e.g., "transfer funds between accounts").
  3. Is stateless -- it depends only on its arguments and injected Repositories/Services.

Do not put domain logic in application Services. Application Services orchestrate (load Aggregate, call domain method, save); domain logic lives in Entities, VOs, and Domain Services.

Aggregates

Aggregates enforce consistency boundaries. These rules are non-negotiable:

Boundary Rules

  1. Every Aggregate has exactly one root Entity.
  2. External objects may hold references only to the root. Never expose internal objects.
  3. Internal objects may hold references to other Aggregate roots.
  4. Only the root may be retrieved from a Repository. Internal objects are reached by traversal.
  5. Deleting the root deletes everything inside the boundary.

Invariant Rules

  1. All invariants within the boundary are enforced on every state change -- the boundary is the transaction boundary.
  2. Invariants that span Aggregates use eventual consistency, not transactional consistency.

Sizing Rules

  1. Keep Aggregates small. Prefer a single Entity root with Value Objects. Add child Entities only when an invariant demands it.
  2. Reference other Aggregates by identity (store the ID), not by direct object reference.

Design Procedure

When defining an Aggregate:

  1. Identify the invariants. What rules must always be true?
  2. Find the smallest cluster of objects needed to enforce those invariants. That is your boundary.
  3. Choose the root -- the Entity that owns the invariants and is the entry point.
  4. Everything outside the boundary references the root by identity.

Repositories

  • Provide one Repository per Aggregate root. Never for internal objects.
  • The interface is pure domain language: find_by_tracking_id(tracking_id), not SELECT * FROM ....
  • No query technology leaks into the domain layer -- no SQL, no ORM query builders, no storage-specific types.
  • A Repository provides the illusion of an in-memory collection. Methods: add, remove, find_by_*.
  • Reconstitution (loading from storage) is distinct from creation (use a Factory for creation of new Aggregates).

Factories

  • Use a Factory when constructing an Aggregate requires assembling multiple parts or enforcing invariants that a simple constructor cannot express.
  • A Factory method can live on the Aggregate root (for creating related objects), on a standalone Factory, or on another domain object that naturally participates in creation.
  • Every object produced by a Factory must satisfy all invariants -- an Aggregate that exists is valid.
  • Do not use Factories for reconstitution from storage. Repositories handle that.

Modules

  • Name modules from the Ubiquitous Language, not from technical roles. shipping, billing, pricing -- not services, models, utils.
  • Low coupling between modules, high cohesion within.
  • Module boundaries tell a story about the domain. If you need to explain why two concepts are in the same module, they probably should not be.

Supple Design

Apply these patterns to make domain code easy to use and change:

Intention-Revealing Interfaces

  • Name every class and method to state what it does and why, not how. A caller should never need to read the implementation.
  • Method name = domain verb phrase. Class name = domain noun.
  • If a name requires a comment to explain, rename it.

Side-Effect-Free Functions

  • Separate queries (return a result, no side effects) from commands (change state, return nothing).
  • Place as much domain logic as possible in functions on Value Objects -- these are naturally side-effect-free.
  • When a command is necessary, keep it simple and do not return domain data from it.

Assertions

  • State post-conditions and invariants explicitly in docstrings or type contracts.
  • Tests should assert invariants, not just outputs. If an Aggregate has a rule "quantity must be positive", test that the rule holds after every operation that touches quantity.

Conceptual Contours

  • Decompose along the natural grain of the domain. Elements that change together belong together; elements that change independently should be separate.
  • If adding a feature requires modifying many unrelated classes, your contours are wrong.

Standalone Classes

  • Reduce dependencies to the minimum. Every dependency is a burden on understanding.
  • The ideal: a class that can be understood and tested by reading only its own file plus language primitives.

Closure of Operations

  • Where possible, define operations whose argument and return type match the type they are defined on: Money.add(Money) -> Money, Specification.and(Specification) -> Specification.
  • Closed operations create composable, self-contained algebras.

Making Implicit Concepts Explicit

When domain logic is buried in conditionals, boolean flags, or string comparisons, a concept is implicit. Surface it:

SmellConcept to extractImplementation
Complex conditional selecting/filtering objectsSpecificationObject with is_satisfied_by(candidate) -> bool. Compose with and_spec, or_spec, not_spec.
Business rule limiting values or combinationsConstraintNamed method or object that raises on violation.
If/else selecting between algorithmsPolicy/StrategyInterface + named implementations. Inject the active policy.
Multi-step process described by domain expertsDomain Service / ProcessNamed operation with steps expressed in domain terms.
A concept domain experts mention but code lacksMissing model elementAdd it. The model is wrong if it cannot express what domain experts say.

Strategic Design

Bounded Context

  • A model is valid only within its Bounded Context. The same real-world thing may be modelled differently in different contexts.
  • When you notice the same term meaning different things in different parts of the codebase, you have discovered a context boundary. Make it explicit.
  • Each Bounded Context has its own Ubiquitous Language, its own model, and its own module structure.

Context Map (Solo Dev Adaptation)

Even as a solo developer, map the boundaries between:

  • Your domain modules (which may have different models for related concepts).
  • External systems you integrate with (APIs, databases, libraries that impose their own model).
  • For each boundary, decide the relationship:
SituationPatternAction
You control both sides and they share conceptsShared KernelExtract shared model into a common module. Changes require updating both sides.
You depend on an external system you cannot changeAnti-Corruption LayerBuild a translation layer. Your domain never references external types directly.
External model is good enough and fighting it adds no valueConformistAdopt the external model as-is in your code.
Integration cost exceeds valueSeparate WaysDo not integrate. Duplicate if necessary.
You expose your model for others to consumeOpen Host + Published LanguageDefine a stable API/schema. Insulate your internal model from the published interface.

Anti-Corruption Layer

When wrapping an external system:

  1. Facade: Simplified interface to the external system's API.
  2. Adapter: Maps between your calling conventions and the external system's protocol.
  3. Translator: Maps between the external system's model and your domain model.

Your domain code calls the ACL. The ACL calls the external system. Domain types never appear in the external system's namespace and vice versa.

Core Domain Vs Generic Subdomain

  • Core Domain: the code that makes the application distinctive. If you removed it, the software would be generic. Invest design effort here. Apply supple design. Refactor toward deeper insight.
  • Generic Subdomain: necessary but not distinctive (e.g., money, date arithmetic, authentication). Separate into its own module. Use libraries or published models. Do not over-invest in design -- good enough is sufficient.

Decision test: "If I replaced this module with an off-the-shelf equivalent, would the application lose its distinctive value?" If no, it is a Generic Subdomain.

Layered Architecture

Separate domain logic from everything else. Minimal layers for a solo-dev codebase:

LayerResponsibilityDepends on
ApplicationOrchestration. Load Aggregates, call domain methods, save results.Domain
DomainAll domain logic. Entities, VOs, Services, Specifications, Repositories (interfaces).Nothing above it
InfrastructureImplements domain interfaces (Repository impls, external system clients).Domain (via interfaces)

The domain layer has zero dependencies on infrastructure, frameworks, or UI. It depends only on language primitives and its own types. Infrastructure implements domain-defined interfaces (dependency inversion).

Refactoring Toward Deeper Insight

  • When code is hard to extend, suspect the model first, not the code structure.
  • When domain experts describe a concept the code cannot express, add the concept to the model.
  • When a name feels wrong, it is wrong. Rename until the code reads like a domain conversation.
  • Prioritise refactoring in the Core Domain. A refactoring in the Core has more leverage than one in a Generic Subdomain.

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.