/symfony-hexagonal:symfony-domain-modelingfrom symfony-hexagonal
Guides creation of DDD domain model elements in Symfony: entities, aggregates, value objects, domain events, and exceptions with PHP 8.2-8.5 features.
Ships in symfony-hexagonal. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in Domain-Driven Design within Symfony hexagonal architecture. Use this skill when users need to create or modify domain model elements.
| Feature | Requires | Fallback |
|---|---|---|
final readonly class | PHP 8.2 | PHP 8.1: final class + public readonly properties |
public private(set) properties, property hooks | PHP 8.4 + Doctrine ORM 3.4 | private property + getter |
clone($this, ['amount' => $x]) | PHP 8.5 | new self(...) |
array_find(), array_any(), array_all() | PHP 8.4 | foreach loop |
Generate the fallback form unless the detected PHP constraint allows the newer syntax.
time() inside the entity/** @var list<DomainEvent> */namespace App\Domain\{Module}\Entity;
use App\Domain\Shared\Event\DomainEvent;
final class {Entity}
{
/** @var list<DomainEvent> */
private array $domainEvents = [];
private function __construct(
private {Entity}Id $id,
// typed properties using value objects
) {
}
public static function create({Entity}Id $id /*, params */): self
{
// validate invariants
$entity = new self($id /*, params */);
$entity->recordEvent(new {Entity}Created($id->value));
return $entity;
}
// Business methods that protect invariants
public function doAction(/* params */): void
{
// guard clause / invariant check
// state change
$this->recordEvent(new {ActionDone}($this->id->value));
}
/** @return list<DomainEvent> */
public function pullDomainEvents(): array
{
$events = $this->domainEvents;
$this->domainEvents = [];
return $events;
}
private function recordEvent(DomainEvent $event): void
{
$this->domainEvents[] = $event;
}
}
final readonly class (PHP 8.2+)equals() for comparisonnamespace App\Domain\{Module}\ValueObject;
use App\Domain\{Module}\Exception\Invalid{ValueObject}Exception;
final readonly class {ValueObject}
{
public function __construct(
public string $value,
) {
if (/* validation fails */) {
throw Invalid{ValueObject}Exception::forValue($value);
}
}
public function equals(self $other): bool
{
return $this->value === $other->value;
}
public function __toString(): string
{
return $this->value;
}
}
UserRegistered, OrderPlaced, PaymentFailedfinal readonly class) implementing App\Domain\Shared\Event\DomainEvent#[AsMessage] on domain events (it is a Symfony attribute): route them in messenger.yamlnamespace App\Domain\{Module}\Event;
use App\Domain\Shared\Event\DomainEvent;
final readonly class {PastTenseEvent} implements DomainEvent
{
public function __construct(
public string $aggregateId,
public \DateTimeImmutable $occurredOn,
// additional event-specific data
) {
}
public function aggregateId(): string
{
return $this->aggregateId;
}
public function occurredOn(): \DateTimeImmutable
{
return $this->occurredOn;
}
}
namespace App\Domain\{Module}\Exception;
final class {DomainException} extends \DomainException
{
public static function because{Reason}(string $context): self
{
return new self(sprintf('Descriptive message: %s', $context));
}
}
See references/ for detailed patterns:
entity-patterns.md - Full entity examples with aggregatesvalue-object-patterns.md - Common value object implementations, ID generation portdomain-event-patterns.md - Event design and dispatch patternsWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aligundogdu/symfony-hexagonal-skill --plugin symfony-hexagonal10 skills in this plugin
/symfony-api-responseSymfony REST API response standard {result, error, extra, status}: thin controllers, #[MapRequestPayload] / #[MapQueryString] request DTOs, ApiResponseTrait, exception subscriber that unwraps Messenger HandlerFailedException, validation error format, debug mode. Use when: API, endpoint, controller, response, error handling, JSON, REST, API response, exception subscriber, HTTP, request DTO/symfony-cqrs-handlersSymfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp/symfony-doctrine-persistenceDoctrine persistence for Symfony hexagonal architecture (ORM 2.x/3.x, DBAL 3/4, DoctrineBundle 2/3): repository adapters, XML mapping in Infrastructure, embeddables, enums, custom DBAL types, native lazy objects, migrations, transactions, read models with DBAL QueryBuilder, strict no-native-SQL rule. Use when: doctrine, repository, persistence, database, mapping, migration, ORM, entity manager, DBAL, transaction, query builder, pagination/symfony-hexagonal-architectureSymfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade/symfony-messenger-asyncSymfony Messenger async processing and Symfony Scheduler instead of cron: transports, routing (#[AsMessage] 7.2+), retry with backoff and jitter, failure transport, idempotency keys, DeduplicateStamp (7.3+), workers, supervisor, scheduled commands with stateful/locked schedules. Use when: messenger, async, queue, retry, scheduler, background job, worker, transport, message queue, cron, scheduled task, idempotency, deduplication/symfony-ports-adaptersSymfony ports and adapters: port interfaces in Domain, adapter implementations in Infrastructure, dependency injection, autowiring, services.yaml aliases, #[AsAlias], environment-specific and decorated adapters, in-memory test adapters. Use when: port, adapter, interface, repository interface, DI, autowiring, dependency injection, services.yaml, binding, decorator, AsAliasOther plugins' skills for the same job