design-ddd-aggregates
Skill4 starsChanged 3 months agoMITView on GitHub
WHEN/WHERE/WHO: [Scheduling: Developers, database designers, or agents designing the object-oriented domain layer of a system.] HOW: [Structural: Use this SKILL to strictly apply Vaughn Vernon's 4 Rules of Aggregate Design to shape entities and value objects.] WHY: [Scheduling: Designing small aggregates referenced by ID ensures transactional safety and high performance, preventing massive God Objects.]
In this repository61 other files it gives its agents.
- activate-personalSkill
- analyze-with-tactics-questionnairesSkill
- apply-agile-testing-quadrantsSkill
- apply-architectural-tacticsSkill
- apply-attribute-driven-designSkill
- apply-fundamentals-of-data-visualizationSkill
- apply-oopsi-modelSkill
- apply-screenplay-patternSkill
- apply-specification-by-exampleSkill
- blog-topic-discoverSkill
- build-agent-memory-systemsSkill
- build-business-objectives-modelSkill
- build-data-dictionarySkill
- build-feature-treeSkill
- comment-alive-test-driven-developmentSkill
- conduct-event-stormingSkill
- create-ecosystem-mapSkill
- create-living-documentationSkill
- create-skill-from-bookSkill
- CREATING-SKILL-TEMPLATESkill
- define-architectural-driversSkill
- define-bounded-contextsSkill
- define-ubiquitous-languageSkill
- design-agentic-screenplay-modelSkill
- design-agent-perception-layersSkill
- design-agent-planningSkill
- design-agent-reward-functionsSkill
- design-agents-using-patternsSkill
- design-architecture-viewpointsSkill
- design-autonomous-ai-interfacesSkill
- design-tool-use-sandboxingSkill
- document-architectural-decisionsSkill
- document-legacy-codebaseSkill
- doc-with-usage-exampleSkill
- draft-srs-documentSkill
- elicit-requirements-modelsSkill
- evolve-skill-with-wikiSkill
- extract-business-rulesSkill
- facilitate-example-mappingSkill
- facilitate-user-story-mappingSkill
- implement-agent-observabilitySkill
- implement-agent-reflectionSkill
- improve-existing-skillSkill
- improve-user-storySkill
- managing-ai-projectsSkill
- orchestrate-multi-agent-collaborationSkill
- prioritize-requirementsSkill
- review-c4-modelSkill
- review-data-engineeringSkill
- save-as-skillSkill
- scaffold-cmake-cxx-sanitize-gtest-envSkill
- skill-commonSkill
- task-commit-triggerSkill
- test-case-with-demoSkill
- test-case-with-readmeSkill
- test-driven-developmentSkill
- UnitTesting-convert2CaTDDSkill
- update-my-resumeSkill
- update-spec-contextSkill
- validate-requirements-criteriaSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 8 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
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
- Distinctive: line 13
When this skill is activated, first load skill-common and apply the shared conventions it defines: canonical section order, frontmatter …
- Distinctive: line 46
Transfer Check: Verify the workflow still works for entity-heavy domains and for systems that require eventual consistency across multiple …
- Distinctive: line 47
Stop Rule: If the proposed entities or invariants are unclear, stop and ask before shaping aggregates.
- Distinctive: line 53
RULE 4: Eventual Consistency: If modifying Aggregate A requires modifying Aggregate B, do not update both in the same database transaction.
- Distinctive: line 62
Remove any nested entities that do not strictly participate in the invariants.
- Very specific: line 67
If the Aggregate holds a reference to another Aggregate Root (e.g., Order contains a Customer object), replace it with a reference by …
- Distinctive: line 87
Verify no Aggregate holds an object reference to another Aggregate.
- Distinctive: line 88
Verify the Aggregate is as small as possible.
- Distinctive: line 89
Verify that any cross-aggregate updates rely on Domain Events and eventual consistency, not massive single transactions.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Design DDD Aggregates (Tactical Design)
Common Contract (Load First)
When this skill is activated, first load skill-common and apply the shared conventions it defines: canonical section order, frontmatter rules, anti-pattern guidance, and the Review In Mind loop in review-in-mind. This skill adds only domain-specific rules below.
Who
Developers, Backend Engineers, and AI Agents designing the persistence layer and domain entities of an application.
What
Apply the strict Tactical Design rules of Domain-Driven Design (DDD) to group Entities and Value Objects into consistency boundaries called Aggregates, governed by an Aggregate Root.
When
Invoke this skill when designing database schemas, ORM mappings, or object-oriented domain classes.
Trigger phrases: "Design the aggregates for...", "Review this domain model for DDD compliance", "Refactor this entity into an aggregate".
Where
Applies to backend codebases, domain models, entity definitions, and database schema designs.
Why
Without strict rules, object graphs grow infinitely. If Order has a list of OrderItems, and OrderItem has a reference to Product, and Product has a reference to Category... loading an Order might pull half the database into memory. Furthermore, if two users edit the same massive object graph, transaction locks cause performance bottlenecks. Aggregates act as strict transaction boundaries to solve this.
Inputs
- Proposed Entities/Data Model (required): The nouns in the system (e.g., User, Post, Comment).
- Business Rules/Invariants (required): The rules that must always be true (e.g., "A post cannot have more than 100 comments").
Output (Logical Evidence)
- A refined domain model with clear boundaries between Aggregate Roots, Entities, and Value Objects.
- Adherence to the 4 rules of Aggregate Design.
Optimization Readiness
- Failure Signals: Aggregates are too large, cross-aggregate object references remain, invariants are diluted, or eventual consistency is ignored in favor of giant transactions.
- Evidence To Collect: Proposed aggregates, invariant lists, identity references, domain events, and examples where shrinking the aggregate reduced coupling.
- Safe Mutation Boundaries: Refine invariant-hunting prompts, aggregate-shrinking guidance, identity-reference rules, and event-planning cues without changing the core aggregate design constraints.
- Acceptance Criteria: Accept revisions only if every aggregate is small, invariants are explicit, cross-aggregate references use IDs, and cross-boundary updates rely on events.
- Rejected Revision Handling: Record object-graph sprawl, direct aggregate references, and monolithic transaction patterns so they are not repeated.
- Transfer Check: Verify the workflow still works for entity-heavy domains and for systems that require eventual consistency across multiple aggregates.
- Stop Rule: If the proposed entities or invariants are unclear, stop and ask before shaping aggregates.
Constraints (Logical Boundaries)
- RULE 1: Model True Invariants. An aggregate is a transaction boundary. Only data that must be strictly, transactionally consistent at the exact same millisecond should be inside the same aggregate.
- RULE 2: Design Small Aggregates. An aggregate should contain only the Root Entity and the minimal number of nested Entities/Value Objects needed to enforce the invariants.
- RULE 3: Reference by Identity. Aggregates must NOT hold object references (pointers) to other aggregates. They must only hold the ID (String/UUID) of the other aggregate.
- RULE 4: Eventual Consistency. If modifying Aggregate A requires modifying Aggregate B, do not update both in the same database transaction. Aggregate A must publish a Domain Event, which Aggregate B listens to and updates itself in a separate transaction.
How (Structural Workflow)
Phase 1: Identify the Root and Invariants
- Analyze the proposed data model and business rules.
- Identify the Aggregate Root (the primary entity that external objects interact with).
- Identify the True Invariants (business rules that cannot be violated, even for a millisecond).
Phase 2: Shrink the Aggregate
- Remove any nested entities that do not strictly participate in the invariants.
- Convert nested entities into Value Objects if they have no identity and are entirely replaceable.
Phase 3: Enforce Identity References
- Scan the Aggregate's properties.
- If the Aggregate holds a reference to another Aggregate Root (e.g.,
Ordercontains aCustomerobject), replace it with a reference by identity (e.g.,Ordercontains acustomerIdstring).
Phase 4: Plan Eventual Consistency
- Review workflows that span multiple Aggregates.
- Design the Domain Events (e.g.,
OrderPlaced) that the primary Aggregate will publish. - Design the listeners/policies on the other Aggregates that will react to these events.
Resources
- Aggregate Design Rules
Review In Mind (ReviewInMindGenie)
Execute the common review loop in review-in-mind before delivering.
Review lens for this skill:
- Does each aggregate enforce its invariants through a single root, with entities/value objects inside?
- Are references between aggregates by ID only, with explicit consistency boundaries?
- Are oversized aggregates split and transient objects excluded?
Validation
- Verify no Aggregate holds an object reference to another Aggregate.
- Verify the Aggregate is as small as possible.
- Verify that any cross-aggregate updates rely on Domain Events and eventual consistency, not massive single transactions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

