Lesson 1 of 9 · 22m
The Symfony Mental Model: Kernel, Request, Response
Why Symfony is a request pipeline plus a service container, not a pile of magic — and how to debug it when the magic stops working.
Symfony earned its reputation in boring places: banks, publishers, logistics companies, government systems. It survives there because the framework is explicit about its lifecycle. A request enters, becomes an object, passes through events and controllers, and leaves as a response. Once you see that pipeline, most of Symfony stops being magic.
The lifecycle is small enough to memorize
public/index.php
-> Kernel::handle(Request)
-> routing / listeners / firewall / controller resolution
-> controller returns Response or value
-> response event
-> Response::send()HttpKernel is the center. It does not know your business logic; it coordinates contracts. Routing turns a URL into controller metadata, listeners can alter or replace responses, the controller does application work, and the response event gets the final word.
Controllers are coordinates, not dumping grounds
final class InvoiceController extends AbstractController
{
public function __construct(private InvoiceWriter $writer) {}
#[Route('/invoices', name: 'invoice_create', methods: ['POST'])]
public function create(Request $request, InvoiceInput $input): JsonResponse
{
$invoice = $this->writer->create($input);
return $this->json(['id' => $invoice->publicId], 201);
}
}A good controller translates HTTP into application intent and translates the result back into HTTP. It does not query five tables, render two emails, recalculate taxes, and write logs in the same method. If your controller needs a scroll bar, the boundary is wrong.
Attributes are metadata, not execution flow
Modern Symfony uses PHP attributes for routes, security, serialization, validation, and more. They are discovered and compiled. That matters: attributes are not runtime hooks firing by themselves. The framework reads them when building routes, voters, normalizers, or validators.
#[Route('/admin/reports', name: 'admin_reports')]
#[IsGranted('ROLE_REPORT_READER')]
public function index(): ResponseUse the error as a map
When Symfony throws ControllerDoesNotReturnResponseException or cannot resolve an argument, read it literally. It tells you which stage failed: routing, controller resolution, argument resolution, or response conversion. The stack trace is usually less useful than the exception name.
Field notes
bin/console debug:routeranswers most 'why is this 404?' questions faster than reading annotations.bin/console debug:event-dispatcher kernel.requestshows which listeners can interfere before the controller.- Do not put domain behavior in event listeners just because you can; listeners are cross-cutting infrastructure.
- Keep
public/index.phpboring. If application logic leaks there, nobody will find it during an incident. - Symfony is slower to learn than a micro-framework because it gives you architecture. In year three, that trade looks very different.
Was this lesson helpful?