/symfony-hexagonal:symfony-ports-adaptersfrom symfony-hexagonal
Guides implementing Ports & Adapters pattern in Symfony: port interfaces in Domain, adapter implementations in Infrastructure, DI/autowiring config, services.yaml aliases, #[AsAlias], decorators, and in-memory test adapters.
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 the Ports & Adapters pattern within Symfony hexagonal architecture.
| Feature | Requires | Fallback |
|---|---|---|
alias: in services.yaml | all versions | - |
when@test: / when@dev: blocks | Symfony 5.3 | services_test.yaml |
#[AsAlias(PortInterface::class)] on the adapter | Symfony 6.3 | YAML alias |
#[AsAlias(..., when: 'test')] | Symfony 7.3 | when@test: YAML block |
#[AsDecorator(decorates: ...)] | Symfony 6.1 | decorates: in YAML |
Repeatable #[AsDecorator] | Symfony 7.4 | one decorator per class |
Default to YAML aliases: they work on every version and keep all bindings visible in one file.
Ports are interfaces that define contracts for external dependencies. They live in Domain/{Module}/Port/ (shared ones in Domain/Shared/Port/).
UserRepositoryInterface, not DoctrineUserRepositoryRequest, Collection, UploadedFile, Uuid, ...)| Port Type | Example |
|---|---|
| Repository (write) | UserRepositoryInterface |
| Read repository | UserReadRepositoryInterface |
| External Service | PaymentGatewayInterface |
| Notification | NotificationServiceInterface |
| File Storage | FileStorageInterface |
| Identity | IdGeneratorInterface |
| Security | PasswordHasherInterface |
namespace App\Domain\{Module}\Port;
use App\Domain\{Module}\Entity\{Entity};
use App\Domain\{Module}\ValueObject\{Entity}Id;
interface {Entity}RepositoryInterface
{
public function save({Entity} $entity): void;
public function findById({Entity}Id $id): ?{Entity};
}
Adapters implement ports using specific technologies. They live in Infrastructure/{Module}/.
Doctrine{Entity}Repository, Stripe{Payment}Gatewayfinal readonly class when possiblenamespace App\Infrastructure\{Module}\Persistence;
use App\Domain\{Module}\Port\{Entity}RepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
final readonly class Doctrine{Entity}Repository implements {Entity}RepositoryInterface
{
public function __construct(
private EntityManagerInterface $entityManager,
) {
}
// implement all port methods
}
# config/services.yaml
services:
# Bind ports to adapters
App\Domain\User\Port\UserRepositoryInterface:
alias: App\Infrastructure\User\Persistence\DoctrineUserRepository
App\Domain\Payment\Port\PaymentGatewayInterface:
alias: App\Infrastructure\Payment\ExternalService\StripePaymentGateway
App\Domain\Notification\Port\NotificationServiceInterface:
alias: App\Infrastructure\Notification\ExternalService\SymfonyMailerAdapter
Attribute alternative (Symfony 6.3+), on the adapter:
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
#[AsAlias(UserRepositoryInterface::class)]
final readonly class DoctrineUserRepository implements UserRepositoryInterface { /* ... */ }
See references/ for detailed guides:
port-adapter-examples.md - Full examples for various port typesdi-configuration.md - Advanced DI configuration 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-domain-modelingSymfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status/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, deduplicationOther plugins' skills for the same job