Symfony knowledge

From dykyi-roman/awesome-claude-code · View interactive version

Symfony knowledge is an AI agent skill from the GitHub repository dykyi-roman/awesome-claude-code. Symfony framework knowledge base. Provides architecture, DDD integration, persistence, DI, security, messenger, workflow, events, infrastructure components, testing, and antipatterns for Symfony PHP projects.

How to use this skill

Skill file

Symfony Knowledge Base

Quick reference for Symfony framework patterns, DDD integration, and PHP implementation guidelines for auditing and generating Symfony-based applications.

Core Principles

Quick Checklists

DDD-Compatible Symfony Project

Clean Architecture in Symfony

Common Violations Quick Reference

| Violation | Where to Look | Severity |

|-----------|---------------|----------|

| Doctrine attributes in Domain entities | Domain/**/*.php with #[ORM\ | Critical |

| Symfony Request/Response in Application layer | Application/**/*.php | Critical |

| Business logic in Controller | Controllers with if/switch on domain state | Warning |

| Fat Controller (multiple actions) | Controllers with 2+ public methods | Warning |

| Entity used as DTO across layers | Entity passed to templates/serializers directly | Warning |

| Service Locator via ContainerInterface | $container->get() in services | Critical |

| Doctrine EventListener with domain logic | EventListener classes with business rules | Warning |

| Hard-coded service IDs | $container->get('service.id') | Warning |

| UserInterface in Domain | Domain/**/*.php with implements UserInterface | Critical |

| Missing Messenger retry strategy | messenger.yaml without retry_strategy | Warning |

| Business logic in Workflow listener | Guard/transition listeners with domain rules | Warning |

| Symfony EventDispatcher in Domain | Domain/**/*.php with use Symfony\Contracts\EventDispatcher | Critical |

| Direct infrastructure in Application | Application/**/*.php with CacheInterface, LockFactory | Warning |

PHP 8.4 Symfony Patterns

Invokable Controller (Single Action)

<?php
declare(strict_types=1);
namespace App\Order\Presentation\Api;

use App\Order\Application\Command\CreateOrderCommand;
use App\Order\Application\UseCase\CreateOrderUseCase;
use Symfony\Component\HttpFoundation\{JsonResponse, Request, Response};
use Symfony\Component\Routing\Attribute\Route;

#[Route('/api/orders', methods: ['POST'])]
final readonly class CreateOrderAction
{
    public function __construct(private CreateOrderUseCase $createOrder) {}

    public function __invoke(Request $request): JsonResponse
    {
        $data = $request->toArray();
        $orderId = $this->createOrder->execute(new CreateOrderCommand(
            customerId: $data['customer_id'],
            items: $data['items'],
        ));

        return new JsonResponse(['id' => $orderId->value], Response::HTTP_CREATED);
    }
}

Use Case (Application Service)

<?php
declare(strict_types=1);
namespace App\Order\Application\UseCase;

use App\Order\Domain\Entity\Order;
use App\Order\Domain\Repository\OrderRepositoryInterface;
use App\Shared\Domain\EventDispatcherInterface;

final readonly class CreateOrderUseCase
{
    public function __construct(
        private OrderRepositoryInterface $orders,
        private EventDispatcherInterface $events,
    ) {}

    public function execute(CreateOrderCommand $command): OrderId
    {
        $order = Order::create($command->customerId, $command->items);
        $this->orders->save($order);

        foreach ($order->releaseEvents() as $event) {
            $this->events->dispatch($event);
        }

        return $order->id();
    }
}

Messenger Command Handler

<?php
declare(strict_types=1);
namespace App\Order\Application\Handler;

use App\Order\Application\Command\ConfirmOrderCommand;
use App\Order\Domain\Repository\OrderRepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler(bus: 'command.bus')]
final readonly class ConfirmOrderHandler
{
    public function __construct(private OrderRepositoryInterface $orders) {}

    public function __invoke(ConfirmOrderCommand $command): void
    {
        $order = $this->orders->findById($command->orderId);
        $order->confirm();
        $this->orders->save($order);
    }
}

References

For detailed information, load these reference files:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.