aggregate-root

Implement DDD aggregates with domain events and testing patterns in PHP.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/dairectiv/dairectiv --skill aggregate-root
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: aggregate-root
Source: https://github.com/dairectiv/dairectiv/tree/main/.claude/skills/aggregate-root
Command: npx skills add https://github.com/dairectiv/dairectiv --skill aggregate-root

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides developers to implement Domain-Driven Design aggregates with rich behavior, ensuring robust invariants, state transitions, and comprehensive tests.

Core Features & Use Cases

  • Rich Domain Model: Encapsulates business logic within aggregates to prevent anemic designs.
  • Domain Events & Invariants: Provides patterns for emitting events on state changes and guarding invariants.
  • Testing Guidance: Includes exhaustive testing strategies for lifecycle, behavior, and events.

Quick Start

Review the aggregate-root example and adapt its structure to your domain to create a new aggregate or modify an existing one, then implement tests following the guidance.

Frequently Asked Questions about aggregate-root

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

FAQPage Schema
How do I implement DDD aggregates in PHP without creating an anemic domain model?

To implement DDD aggregates in PHP without an anemic domain model, encapsulate business logic within the aggregate root. This approach enforces invariants and state transitions directly inside the entity, preventing anemic designs.

How do you handle domain events and enforce invariants in a PHP aggregate root?

Handling domain events and enforcing invariants in a PHP aggregate root requires emitting events upon state changes while guarding business rules. This encapsulates behavior and guarantees state transitions remain valid across the domain model.

What is the best way to test aggregate behavior and lifecycle in domain-driven design?

The best way to test aggregate behavior and lifecycle in domain-driven design is applying exhaustive testing strategies. This includes verifying invariant enforcement, state transitions, and asserting that domain events are emitted correctly.

Does this domain-driven design pattern work for evolving existing PHP aggregates?

Yes, the domain-driven design pattern works for evolving existing PHP aggregates. It provides guidance for modifying current structures, handling new domain events, and writing comprehensive tests to ensure behavioral consistency.

When should I not use a rich domain model for my PHP aggregates?

You should not use a rich domain model for PHP aggregates when your application requires only simple CRUD operations without complex business logic, as enforcing invariants and domain events adds unnecessary architectural overhead.