A three-week plan

← A three-week plan

Ashterix

docs(articles): English translation of From Magento to Symfony

en/articles/magento-to-symfony/practice/plan.md new file +60 −0

A three-week plan

The fastest way is to rewrite a familiar Magento module in Symfony. The end-to-end exercise below: an FAQ with categories, a JSON API for reading and editing, an import and a nightly cleanup. Each part of the module has its counterpart in Symfony.

Part of Vendor_Faq What to write in Symfony
db_schema.xml: faq_question, faq_category Entity\Question, Entity\Category, a migration
Model, ResourceModel, Collection, Api/* QuestionRepository with 3–4 methods
webapi.xml + Api/*Interface FaqController: GET /api/faq, GET /api/faq/{slug} + serialization groups
adminhtml: saving and deleting POST, PUT, DELETE with a DTO via #[MapRequestPayload] and Validator
acl.xml Firewall, roles, Voter
CSV import via a queue The app:faq:import command + Messenger
crontab.xml: cleanup #[AsCronTask]
system.xml: faq/general/enabled %env(bool:FAQ_ENABLED)%
Integration tests WebTestCase + KernelTestCase + Foundry

Week 1. Foundations: request, DI, controllers

  • The book "Symfony: The Fast Track", the chapters up to Doctrine.
  • Documentation: Routing, Controller, Service Container.
  • The request lifecycle diagram and all debug:* commands.

Exercise: a new project (symfony new or symfony/skeleton), the GET /api/faq and GET /api/faq/{slug} endpoints on hardcoded data, a decorator and a tagged pool of services.

Week 2. Data, forms, access

  • Doctrine: entities, associations, Unit of Work, QueryBuilder, migrations.
  • Validator, input DTOs, Security.
  • Profiler: find and fix an N+1.

Exercise: entities, migrations, fixtures, write endpoints with DTOs and validation, domain exceptions that a kernel.exception listener turns into HTTP responses with the right status.

Week 3. Async, API, tests, prod

  • Messenger, Scheduler, Cache, Serializer.
  • KernelTestCase, WebTestCase, Foundry.
  • Deployment: the prod environment, workers.

Exercise: CSV import via a queue, a nightly cleanup, a tagged cache, functional API tests, a prod build.

Checklist

Sixteen things worth doing with your own hands, not just reading about.

  • Created a project (symfony new or composer create-project symfony/skeleton) and ran it locally.
  • Can explain what happens between index.php and the controller: the kernel.* events.
  • Find services with debug:autowiring and debug:container.
  • Replaced an interface implementation via an alias or #[AsAlias].
  • Wrote a decorator where Magento would use a plugin.
  • Collected a set of implementations via a tag and #[AutowireIterator].
  • Created an entity with a ManyToOne association and generated a migration.
  • Can explain why flush() writes all changes, not a single entity.
  • Found an N+1 in the profiler and removed it with a fetch join.
  • Added an endpoint with an input DTO via #[MapRequestPayload] and checked the 422 response on invalid data.
  • Protected /admin with a role and wrote a Voter.
  • Turned a domain exception into an HTTP response with a kernel.exception listener.
  • Moved heavy work to Messenger and ran a worker.
  • Set up a recurring task in Scheduler.
  • Wrote a WebTestCase and a KernelTestCase with data from Foundry.
  • Built for prod: composer dump-env prod, cache:clear, migrations, worker restart.