ddd-aggregate-design

Reviews and designs DDD aggregates using Evans Rules, Vernon Rules, and Design by Contract.

Updated Jun 23, 2026
One-click install
npx skills add https://github.com/j5ik2o/marp-ai-base --skill ddd-aggregate-design-j5ik2o
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ddd-aggregate-design
Source: https://github.com/j5ik2o/marp-ai-base/tree/main/.agents/skills/ddd-aggregate-design
Command: npx skills add https://github.com/j5ik2o/marp-ai-base --skill ddd-aggregate-design-j5ik2o

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Designing aggregate boundaries in Domain-Driven Design is error-prone: teams create oversized aggregates causing lock contention, hold direct references between aggregates, leak encapsulation through public fields, and fail to enforce invariants. This Skill provides systematic guidance for aggregate design, code review, and refactoring based on established DDD rules. ## Core Features & Use Cases - Aggregate Design Guidance: Apply Evans Rules and Vernon's 4 Rules to define aggregate boundaries, enforce true invariants, keep aggregates small, and reference other aggregates by ID only. - Code Review Checklist: Detect encapsulation violations (public fields, direct mutation via push/append), missing invariant validation, missing domain events, and improper cross-aggregate references. - Language-Specific Patterns: Reference implementations for immutable aggregates in TypeScript (Props + spread), Scala (case class + copy), Rust (struct update syntax), and Python (frozen dataclass + replace). - Use Case: When deciding whether Post and Comment belong in the same aggregate, the Skill recommends separate aggregates per Vernon's small-aggregate rule, connected via ID references and eventual consistency through domain events. ## Quick Start Ask the AI to review your aggregate class or design a new aggregate following DDD aggregate design rules, for example by requesting a review of an Order class that directly references Customer.

Frequently Asked Questions about ddd-aggregate-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a DDD aggregate in TypeScript?

Design an immutable aggregate using a Props type with readonly fields and spread syntax for state updates. Use a private constructor that validates invariants, factory methods like create() and reconstruct(), and reference other aggregates by ID only.

Should two entities be in the same aggregate or separate aggregates?

Place entities in the same aggregate only when a true invariant must be transactionally consistent between them. Per Vernon's Rule 2, keep aggregates small to avoid lock contention; connect separate aggregates via ID references and eventual consistency with domain events.

What are Vernon's 4 Rules for aggregate design?

Vernon's rules are: model true invariants inside the consistency boundary, keep aggregates small, reference other aggregates by ID only, and use eventual consistency outside the boundary. They guide boundary decisions and concurrency behavior.

How do I make a mutable aggregate immutable?

Replace void-returning mutation methods with methods returning new instances: spread syntax in TypeScript, copy() in Scala, struct update syntax in Rust, or replace() with frozen dataclasses in Python. Validate invariants in the constructor so every new instance is checked.

When should I use optimistic locking on an aggregate?

Add a version number for optimistic locking only when concurrent update conflict detection is an actual requirement. The repository checks the version in the UPDATE statement's WHERE clause; without the requirement, the version field is unnecessary.

Does this approach work for languages other than TypeScript?

Yes, the Skill includes reference implementations for TypeScript, Scala, Rust, and Python. Each covers immutable aggregates, ID references, factory patterns, invariant validation, domain events, and optimistic locking with language-idiomatic constructs.