symfony-knowledge

Symfony framework knowledge base. Provides architecture, DDD integration, persistence, DI, security, messenger, workflow, events, infrastructure components, testing, and antipatterns for Symfony PHP projects.

59 stars

Best use case

symfony-knowledge is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Symfony framework knowledge base. Provides architecture, DDD integration, persistence, DI, security, messenger, workflow, events, infrastructure components, testing, and antipatterns for Symfony PHP projects.

Teams using symfony-knowledge should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/symfony-knowledge/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/symfony-knowledge/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/symfony-knowledge/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How symfony-knowledge Compares

Feature / Agentsymfony-knowledgeStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Symfony framework knowledge base. Provides architecture, DDD integration, persistence, DI, security, messenger, workflow, events, infrastructure components, testing, and antipatterns for Symfony PHP projects.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Symfony Knowledge Base

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

## Core Principles

- **Bundle System** — Symfony's plugin mechanism. Third-party code is installed as bundles; application code lives outside bundles in `src/`.
- **Symfony Flex** — Automates bundle installation via recipes. Standard dirs: `config/`, `src/`, `public/`, `var/`, `migrations/`, `tests/`, `templates/`.
- **Kernel** — Entry point that boots the container, registers bundles, loads configuration. Must remain thin — no business logic.

## Quick Checklists

### DDD-Compatible Symfony Project

- [ ] Domain layer has zero Symfony imports
- [ ] Doctrine mapping uses XML or PHP config (not entity attributes)
- [ ] Controllers are invokable (single action per class)
- [ ] Messenger handles commands and queries via separate buses
- [ ] Value Objects use custom Doctrine types
- [ ] Repository interfaces in Domain, implementations in Infrastructure
- [ ] `services.yaml` binds interfaces to implementations
- [ ] Domain events are dispatched, not Doctrine lifecycle events
- [ ] Authorization uses Voters delegating to domain Specifications
- [ ] Workflow guards delegate to domain Specifications (no inline business logic)
- [ ] Domain defines its own `EventDispatcherInterface` (not Symfony's)
- [ ] Infrastructure components (Cache, HTTP Client) accessed via domain ports

### Clean Architecture in Symfony

- [ ] No `use Symfony\` in Domain or Application layers
- [ ] No `use Doctrine\` in Domain layer
- [ ] Use Cases accept Command/Query DTOs, not Request objects
- [ ] Controllers only map HTTP to Use Case calls
- [ ] EventSubscribers do not contain business logic
- [ ] Compiler passes do not encode domain rules

## 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
<?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
<?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
<?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:

- `references/architecture.md` — Bundle system, Flex recipes, standard vs DDD-aligned directory layout
- `references/ddd-integration.md` — Domain purity, Messenger CQRS, Domain Events, Value Objects with Doctrine
- `references/routing-http.md` — Invokable controllers, EventSubscribers, attribute routing, validation
- `references/persistence.md` — Doctrine ORM mapping, repositories, migrations, keeping Doctrine out of Domain
- `references/dependency-injection.md` — services.yaml, auto-wiring, tagged services, compiler passes, interface binding
- `references/testing.md` — WebTestCase, KernelTestCase, functional tests, fixtures, Messenger handler testing
- `references/security.md` — UserInterface adapter, Voters with Specifications, firewalls, password hashing, auth events
- `references/messenger-advanced.md` — Multiple buses, transports, retry strategy, DLQ, middleware, workers, serialization
- `references/workflow.md` — StateMachine for aggregates, enum places, guards with Specifications, audit trail
- `references/event-system.md` — EventDispatcher patterns, kernel events, domain event dispatching, PSR-14
- `references/infrastructure-components.md` — Cache, Lock, RateLimiter, HTTP Client, Serializer, Scheduler with DDD ports
- `references/antipatterns.md` — Fat controllers, entity as DTO, Doctrine in Domain, Service Locator, detection patterns

Related Skills

yii-knowledge

59
from dykyi-roman/awesome-claude-code

Yii framework knowledge base. Provides Yii3 modular architecture, DDD integration, PSR-7/PSR-15 compliance, persistence, DI, security (RBAC, auth), event system (PSR-14), queue/jobs, infrastructure components (cache, rate limiter, HTTP client), testing, and antipatterns for Yii PHP projects.

testing-knowledge

59
from dykyi-roman/awesome-claude-code

Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.

task-progress-knowledge

59
from dykyi-roman/awesome-claude-code

TaskCreate pattern guidelines for progress tracking in coordinator agents

stability-patterns-knowledge

59
from dykyi-roman/awesome-claude-code

Stability Patterns knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Circuit Breaker, Retry, Rate Limiter, Bulkhead, and resilience audits.

solid-knowledge

59
from dykyi-roman/awesome-claude-code

SOLID principles knowledge base for PHP 8.4 projects. Provides quick reference for SRP, OCP, LSP, ISP, DIP with detection patterns, PHP examples, and antipattern identification. Use for architecture audits and code quality reviews.

scalability-knowledge

59
from dykyi-roman/awesome-claude-code

Scalability knowledge base. Provides vertical vs horizontal scaling, stateless design, session management, connection pooling, capacity planning, and PHP-FPM tuning for scalability audits.

saga-pattern-knowledge

59
from dykyi-roman/awesome-claude-code

Saga Pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for saga orchestration, choreography, and distributed transaction audits.

replication-sharding-knowledge

59
from dykyi-roman/awesome-claude-code

Replication and Sharding knowledge base. Provides read/write splitting at application level, connection wrapper patterns, replica lag handling, and query routing for database scaling audits.

psr-coding-style-knowledge

59
from dykyi-roman/awesome-claude-code

PSR-1 and PSR-12 coding standards knowledge base for PHP 8.4 projects. Provides quick reference for basic coding standard and extended coding style with detection patterns, examples, and antipattern identification. Use for code style audits and compliance reviews.

psr-autoloading-knowledge

59
from dykyi-roman/awesome-claude-code

PSR-4 autoloading standard knowledge base for PHP 8.4 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.

outbox-pattern-knowledge

59
from dykyi-roman/awesome-claude-code

Outbox Pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for transactional outbox, polling publisher, and reliable messaging audits.

observability-knowledge

59
from dykyi-roman/awesome-claude-code

Observability knowledge base. Provides three pillars (logs, metrics, traces), structured logging, distributed tracing, metrics collection (RED/USE), SLI/SLO/SLA definitions for observability audits and generation.