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

1 + # A three-week plan
2 +
3 + 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.
4 +
5 + | Part of Vendor_Faq | What to write in Symfony |
6 + |---|---|
7 + | db_schema.xml: faq_question, faq_category | Entity\Question, Entity\Category, a migration |
8 + | Model, ResourceModel, Collection, Api/* | QuestionRepository with 3–4 methods |
9 + | webapi.xml + Api/*Interface | FaqController: `GET /api/faq`, `GET /api/faq/{slug}` + serialization groups |
10 + | adminhtml: saving and deleting | `POST`, `PUT`, `DELETE` with a DTO via `#[MapRequestPayload]` and Validator |
11 + | acl.xml | Firewall, roles, Voter |
12 + | CSV import via a queue | The app:faq:import command + Messenger |
13 + | crontab.xml: cleanup | #[AsCronTask] |
14 + | system.xml: faq/general/enabled | %env(bool:FAQ_ENABLED)% |
15 + | Integration tests | WebTestCase + KernelTestCase + Foundry |
16 +
17 + ## Week 1. Foundations: request, DI, controllers
18 +
19 + - The book "Symfony: The Fast Track", the chapters up to Doctrine.
20 + - Documentation: Routing, Controller, Service Container.
21 + - The [request lifecycle](../basics/lifecycle.md) diagram and all `debug:*` commands.
22 +
23 + **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.
24 +
25 + ## Week 2. Data, forms, access
26 +
27 + - Doctrine: entities, associations, Unit of Work, QueryBuilder, migrations.
28 + - Validator, input DTOs, Security.
29 + - Profiler: find and fix an N+1.
30 +
31 + **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.
32 +
33 + ## Week 3. Async, API, tests, prod
34 +
35 + - Messenger, Scheduler, Cache, Serializer.
36 + - KernelTestCase, WebTestCase, Foundry.
37 + - Deployment: the prod environment, workers.
38 +
39 + **Exercise:** CSV import via a queue, a nightly cleanup, a tagged cache, functional API tests, a prod build.
40 +
41 + ## Checklist
42 +
43 + Sixteen things worth doing with your own hands, not just reading about.
44 +
45 + - [ ] Created a project (`symfony new` or `composer create-project symfony/skeleton`) and ran it locally.
46 + - [ ] Can explain what happens between `index.php` and the controller: the `kernel.*` events.
47 + - [ ] Find services with `debug:autowiring` and `debug:container`.
48 + - [ ] Replaced an interface implementation via an alias or `#[AsAlias]`.
49 + - [ ] Wrote a decorator where Magento would use a plugin.
50 + - [ ] Collected a set of implementations via a tag and `#[AutowireIterator]`.
51 + - [ ] Created an entity with a ManyToOne association and generated a migration.
52 + - [ ] Can explain why `flush()` writes all changes, not a single entity.
53 + - [ ] Found an N+1 in the profiler and removed it with a fetch join.
54 + - [ ] Added an endpoint with an input DTO via `#[MapRequestPayload]` and checked the 422 response on invalid data.
55 + - [ ] Protected `/admin` with a role and wrote a Voter.
56 + - [ ] Turned a domain exception into an HTTP response with a `kernel.exception` listener.
57 + - [ ] Moved heavy work to Messenger and ran a worker.
58 + - [ ] Set up a recurring task in Scheduler.
59 + - [ ] Wrote a WebTestCase and a KernelTestCase with data from Foundry.
60 + - [ ] Built for prod: `composer dump-env prod`, `cache:clear`, migrations, worker restart.