/symfony-skills:layered-architecturefrom symfony-skills
Enforces Symfony layered architecture rules when generating controllers, services, repositories, and DTOs. Prevents entities in responses and repository access from controllers.
Ships in symfony-skills. 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.
Controller (#[Route]) ← HTTP only. No business logic. No entities in responses.
↓ DTOs
Service (application) ← All business logic. Orchestrates repositories. Owns the transaction.
↓ Entities / domain objects
Repository (Doctrine) ← Data access only. No business logic. Returns entities or read models.
↓ DQL / DBAL
Database
Dependencies point downward only. A repository never calls a service; a service never sees an Request.
Response.try/catch for domain errors — let an exception listener turn them into HTTP responses.// ✅ GOOD
#[Route('/orders', methods: ['POST'])]
public function create(#[MapRequestPayload] CreateOrderRequest $request): JsonResponse
{
$order = $this->orderService->createOrder($request);
return $this->json(OrderResponse::fromEntity($order), Response::HTTP_CREATED);
}
// ❌ BAD — business logic + direct repository + entity returned
#[Route('/orders', methods: ['POST'])]
public function create(Request $request, OrderRepository $orders): JsonResponse
{
$data = json_decode($request->getContent(), true);
if (empty($data['items'])) {
throw new \RuntimeException('No items'); // domain rule in controller
}
$order = new Order($data);
$orders->save($order); // controller talks to repository
return $this->json($order); // entity leaks out
}
EntityManagerInterface::flush() / wrapInTransaction()).ContainerInterface / service locator pulls.OrderService, not OrderAndPaymentService).Request / Response.// ✅ GOOD
final class OrderService
{
public function __construct(
private readonly OrderRepository $orders,
private readonly InventoryService $inventory,
private readonly EntityManagerInterface $em,
) {}
public function createOrder(CreateOrderRequest $request): Order
{
$this->inventory->reserve($request->items);
$order = Order::create($request->customerEmail);
foreach ($request->items as $item) {
$order->addItem($item->productId, $item->quantity);
}
$this->em->persist($order);
$this->em->flush();
return $order;
}
}
// ❌ BAD — service container pull, HTTP type in service
final class OrderService
{
public function __construct(private ContainerInterface $container) {}
public function createOrder(Request $request): Response { /* ... */ }
}
ServiceEntityRepository<Entity>.// ✅ GOOD
/** @extends ServiceEntityRepository<Order> */
final class OrderRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Order::class);
}
/** @return Order[] */
public function findActiveByCustomer(string $email): array
{
return $this->createQueryBuilder('o')
->andWhere('o.customerEmail = :email')
->andWhere('o.status = :status')
->setParameter('email', $email)
->setParameter('status', OrderStatus::Active)
->getQuery()
->getResult();
}
}
dto-and-validation).OrderResponse::fromEntity($order).readonly classes / promoted readonly properties — DTOs are immutable.// ✅ GOOD
final readonly class OrderResponse
{
/** @param LineItemResponse[] $items */
public function __construct(
public string $id,
public string $status,
public array $items,
) {}
public static function fromEntity(Order $order): self
{
return new self(
$order->getId()->toRfc4122(),
$order->getStatus()->value,
array_map(LineItemResponse::fromEntity(...), $order->getItems()->toArray()),
);
}
}
OrderResponse::fromEntity($order).Order::create(...)) or a mapper service.array_map(OrderResponse::fromEntity(...), $orders) — first-class callable syntax.config/services.yaml; rely on autowiring + autoconfiguration.#[Autowire] bound parameters or a typed config object — not scattered %env()% reads inside services.config/services.yaml, never inside a service class.Psr\Log\LoggerInterface — never error_log() / dump() in committed code.#[MapRequestPayload] validates the DTO automatically; custom rules via constraint validators.#[AsEventListener(KernelEvents::EXCEPTION)] listener — never try/catch in controllers for domain errors.ContainerInterface / uses $this->get() — use constructor injection of the concrete dependency.flush() and transaction logic in the controller — move it to the service.OrderAndInventoryService) — split by aggregate.json_decode($request->getContent()) — use #[MapRequestPayload] with a DTO.try/catches domain exceptions in the controller — let the exception listener map them.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub fatonh/symfony-skills --plugin symfony-skills17 skills in this plugin
/api-platform-resourcesUse when exposing data through API Platform 4 — defining #[ApiResource], operations, DTO resources, state providers/processors, serialization groups, filters, and pagination. Use when the task mentions API Platform, ApiResource, state processor, or exposing an entity as a REST/GraphQL endpoint.
/bundle-organizationUse when structuring a Symfony project's src/ directory, organizing code into modules, configuring services, or deciding where a class belongs. Covers the modular monolith layout, service configuration, and config/ conventions for Symfony 7 (Flex, no app bundle).
/console-commandsUse when creating or refactoring Symfony console commands — never extends Command. On Symfony 8.1+ put #[AsCommand] on a method of a service class (even for a single command); on 7.x use the invokable attribute class. Also covers typed CLI inputs via value resolvers and #[MapInput] DTOs. Use when the task mentions console command, #[AsCommand], bin/console, #[Argument], #[Option], or a CLI task.
/doctrine-migrationsUse when changing the database schema in Symfony — generating Doctrine migrations, writing reversible up()/down(), data migrations, and deploy-safe (zero-downtime) changes. Use when the task mentions migration, schema change, ALTER TABLE, or doctrine:migrations.
/doctrine-ormUse when creating Doctrine ORM 3 entities, associations, repositories, enums, or UUID identifiers in Symfony. Defines entity conventions, attribute mapping, fetch strategy, and repository structure. Use when the task mentions entity, Doctrine, repository, association, or mapping.
/doctrine-query-optimizationUse when writing Doctrine queries, fixing N+1 problems, paginating large result sets, building read models, or tuning DQL/query builder performance. Use when the task mentions N+1, slow query, pagination, DQL, hydration, or read model.
Other plugins' skills for the same job