Generates DDD Aggregates for PHP 8.4. Creates consistency boundaries with root entity, domain events, and invariant protection. Includes unit tests.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accThis skill uses the workspace's default tool permissions.
references/examples.mdreferences/templates.mdGenerate DDD-compliant Aggregates with root, domain events, and tests.
Path: src/Domain/Shared/Aggregate/
AggregateRoot.php — Base class with event recordingPath: src/Domain/{BoundedContext}/Entity/
{Name}.php — Main aggregate rootPath: src/Domain/{BoundedContext}/Entity/
{ChildName}.php — Child entity inside aggregatePath: src/Domain/{BoundedContext}/Event/
{Name}CreatedEvent.php{Name}{Action}Event.php for each behaviorPath: tests/Unit/Domain/{BoundedContext}/Entity/
| Component | Path |
|---|---|
| Base AggregateRoot | src/Domain/Shared/Aggregate/ |
| Aggregate Entity | src/Domain/{BoundedContext}/Entity/ |
| Child Entities | src/Domain/{BoundedContext}/Entity/ |
| Domain Events | src/Domain/{BoundedContext}/Event/ |
| Unit Tests | tests/Unit/Domain/{BoundedContext}/Entity/ |
| Component | Pattern | Example |
|---|---|---|
| Aggregate Root | {Name} | Order |
| Child Entity | {Parent}{Name} | OrderLine |
| Created Event | {Name}CreatedEvent | OrderCreatedEvent |
| State Event | {Name}{Action}Event | OrderConfirmedEvent |
abstract class AggregateRoot
{
private array $events = [];
protected function recordEvent(DomainEvent $event): void
{
$this->events[] = $event;
}
public function releaseEvents(): array
{
$events = $this->events;
$this->events = [];
return $events;
}
}
final class {Name} extends AggregateRoot
{
private {Name}Status $status;
private function __construct(
private readonly {Name}Id $id,
{properties}
) {
$this->status = {Name}Status::Draft;
}
public static function create({Name}Id $id, {params}): self
{
$aggregate = new self($id, {args});
$aggregate->recordEvent(new {Name}CreatedEvent(...));
return $aggregate;
}
public function {behavior}({params}): void
{
$this->ensureValidState();
// Apply change
$this->recordEvent(new {Name}{Behavior}Event(...));
}
}
final readonly class {ChildName}
{
public function __construct(
public {PropertyType} $property1,
public {PropertyType} $property2
) {}
public function total(): Money
{
return $this->unitPrice->multiply($this->quantity);
}
}
| Rule | Good | Bad |
|---|---|---|
| Transaction Boundary | One aggregate per transaction | Multiple aggregates |
| Reference | By ID only | Full entity reference |
| Size | Small, focused | Large with many collections |
| Invariants | Always valid | Can be in invalid state |
| Events | Record all state changes | No event recording |
| Anti-pattern | Problem | Solution |
|---|---|---|
| Large Aggregate | Performance issues | Split into smaller aggregates |
| Entity References | Tight coupling | Use IDs only |
| Public Setters | No invariant protection | Use behavior methods |
| Missing Events | Can't track history | Record event for each change |
| No Root | Multiple entry points | Single root entity |
For complete PHP templates and examples, see:
references/templates.md — AggregateRoot, Entity, Child Entity, Test templatesreferences/examples.md — Order aggregate with OrderLine, events, and testsProvides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.