mcpbeat

Domain Driven Design

techygarg/domain-driven-design

Apply DDD tactical patterns when working with domain code. Enforces aggregate design, value objects over primitives, entity identity rules, and bounded context boundaries. Use when creating or modifying domain models, designing aggregates, working in the domain layer, or when the user mentions 'domain', 'aggregate', 'value object', 'entity', 'bounded context', or 'DDD'.

4k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
169
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/techygarg/lattice --skill domain-driven-design

The instruction itself

6 sections, as written by the author

Domain-Driven Design

Config Resolution

Skill support project-custom. Resolution:

  • Look .lattice/config.yaml repo root
  • If found, check paths.ddd_principles custom doc path
  • If custom path exist, read doc, check YAML frontmatter mode:
  • mode: override (or no mode): Custom doc full precedence.

Use instead embed default. Must comprehensive -- sole reference.

  • mode: overlay: Read embed ./references/defaults.md first, then apply

custom doc section on top. Section custom replace match

section default (match by heading). New section append after default.

  • If no config, no path, or path not found, read ./references/defaults.md
  • Language adaptation: If paths.language_idioms exist in config, read "Type System & Object Model" section and adapt entity, value object, and aggregate implementation patterns to language constructs (e.g., struct vs class, trait vs interface, data class vs record). Language idioms take precedence over pseudocode defaults.

Self-Validation Checklist

STOP after generating each component. Verify ALL before proceeding. STOP: If any check fails, fix before presenting. If check is a judgment call with multiple valid approaches (see Ambiguity Signals), flag — present options and reasoning rather than silently choosing.

  • ENTITY VS VALUE OBJECT: Each domain object — business track individual instance over time? Yes → entity with identity. No → value object with immutable and self-validate.
  • AGGREGATE BOUNDARY: Transactional invariant require this object inside aggregate? If not → separate aggregate reference by ID.
  • RICH BEHAVIOR: Entity have method enforce business rule, guard state transition, raise event? If entity just data holder → move logic from service into entity.
  • VALUE OBJECT COVERAGE: Scan primitive type should be value object — string email, number amount, raw UUID as identifier → wrap value object with validate.
  • AGGREGATE COHESION: List business rule root enforce. Each internal entity participate least one invariant? If not → belong own aggregate.
  • DOMAIN EVENTS: Domain event raise for state transition other aggregate react, change trigger notification, audit/compliance requirement? Don't raise event internal change nothing react.
  • DOMAIN SERVICE: Stateless logic span multiple entity place domain service rather than application service? Avoid I/O and infrastructure call?
  • FACTORY: Complex aggregate creation encapsulate factory method (Order.create(...)) or standalone factory class? Initial creation and reconstitution from persistence handle separate?

Active Anti-Pattern Scan

After verify checklist above, scan output these specific anti-pattern. If find any, fix before present code.

  • [ ] Anemic Domain Model: Entity data holder only getter/setter; all logic live service → move business rule into entity and value object
  • [ ] Primitive Obsession: Raw string for email, number for money, UUID for ID → wrap value object with validate and behavior
  • [ ] God Aggregate: Aggregate many entity, slow load, high contention → decompose keep only what share transactional invariant
  • [ ] Cross-Aggregate Transaction: Service update two aggregate one transaction → use domain event eventual consistency
  • [ ] Leaking Domain Logic: Business rule in controller, application service, or infrastructure → extract domain object or domain service
  • [ ] Misidentified Entity/Value Object: Entity without lifecycle, or value object with identity track → apply identity test

Ambiguity Signals

  • Aggregate Boundary Size: Small aggregate (more event, eventual consistency) vs large aggregate (simple transaction, immediate consistency). Neither inherent correct — depend contention pattern and invariant scope.
  • Entity vs Value Object: Some concept (like Address or Money) may or may not need identity depend domain complexity. Apply identity test, but acknowledge when borderline.
  • Domain Service vs Entity Method: Logic span multiple entity could live domain service or be method on primary entity. Choice depend which entity "own" invariant.
  • Object Creation Pattern: Factory method on aggregate root, standalone factory class, builder pattern, or plain constructor — depend assembly complexity and team convention. Don't prescribe pattern; ask which approach team prefer.

Scope Statement

Skill operate within single repo, single bounded context (e.g., one API -- Order, User, Pricing). Cover tactical DDD pattern only -- not strategic DDD (no context map, no microservice topology, no bounded context integration).

If task appear span multiple bounded context (e.g., Order feature call Shipping logic), flag before proceed: "This task touches [Context A] and [Context B]. Cross-context integration is strategic DDD — outside this skill's scope. Would you like to scope to one context, or proceed knowing cross-context coordination is your responsibility?"

framework:architecture provide structural envelope -- where code live, which layer exist, which direction dependency flow. This skill define how craft domain *within* envelope: rich model, invariant, aggregate boundary, ubiquitous language.

See ./references/defaults.md for aggregate design rules, entity/value object/domain service/domain event/repository/creation patterns with code examples, inline anti-pattern warnings, and decomposition guide.

How to use it

Copy the folder

Take techygarg/domain-driven-design from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.