Project structure

← Project structure

Ashterix

docs(articles): Magento and Symfony project trees with hierarchy, checked against the official structure

en/articles/magento-to-symfony/basics/structure.md +96 βˆ’37

Project structure

A new project: symfony new faq --webapp (Symfony CLI) or composer create-project symfony/skeleton faq for a minimal set. Flex adds packages together with their config: composer require orm creates config/packages/doctrine.yaml and the DATABASE_URL variable.

Magento Β· module tree

app/
  code/Vendor/Faq/
    registration.php
    etc/module.xml  di.xml  events.xml
    etc/frontend/routes.xml
    etc/adminhtml/system.xml  menu.xml
    etc/acl.xml  webapi.xml  crontab.xml
    etc/db_schema.xml
    Api/  Api/Data/
    Model/  Model/ResourceModel/
    Controller/  Block/  ViewModel/
    view/frontend/layout/  templates/  web/
  etc/env.php  config.php
bin/magento
generated/
pub/index.php  pub/static/
var/  vendor/

Symfony Β· application tree

bin/console
config/
  bundles.php
  packages/      doctrine.yaml  security.yaml
                 messenger.yaml  monolog.yaml …
  routes.yaml
  services.yaml
migrations/
public/index.php
src/
  Kernel.php
  Controller/  Entity/  Repository/
  Dto/  Message/  MessageHandler/
  EventListener/  Security/
translations/
tests/
var/cache/  var/log/
vendor/
.env  .env.local  .env.test

Magento Β· project tree with a module

<magento-root>/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ code/
β”‚   β”‚   └── Vendor/
β”‚   β”‚       └── Faq/
β”‚   β”‚           β”œβ”€β”€ registration.php
β”‚   β”‚           β”œβ”€β”€ composer.json
β”‚   β”‚           β”œβ”€β”€ Api/
β”‚   β”‚           β”‚   └── Data/
β”‚   β”‚           β”œβ”€β”€ Block/
β”‚   β”‚           β”œβ”€β”€ Controller/
β”‚   β”‚           β”œβ”€β”€ Model/
β”‚   β”‚           β”‚   └── ResourceModel/
β”‚   β”‚           β”œβ”€β”€ Observer/
β”‚   β”‚           β”œβ”€β”€ Plugin/
β”‚   β”‚           β”œβ”€β”€ Setup/
β”‚   β”‚           β”œβ”€β”€ ViewModel/
β”‚   β”‚           β”œβ”€β”€ etc/
β”‚   β”‚           β”‚   β”œβ”€β”€ module.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ di.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ events.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ acl.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ webapi.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ crontab.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ db_schema.xml
β”‚   β”‚           β”‚   β”œβ”€β”€ frontend/
β”‚   β”‚           β”‚   β”‚   └── routes.xml
β”‚   β”‚           β”‚   └── adminhtml/
β”‚   β”‚           β”‚       β”œβ”€β”€ menu.xml
β”‚   β”‚           β”‚       └── system.xml
β”‚   β”‚           β”œβ”€β”€ i18n/
β”‚   β”‚           └── view/
β”‚   β”‚               └── frontend/
β”‚   β”‚                   β”œβ”€β”€ layout/
β”‚   β”‚                   β”œβ”€β”€ templates/
β”‚   β”‚                   └── web/
β”‚   └── etc/
β”‚       β”œβ”€β”€ config.php
β”‚       └── env.php
β”œβ”€β”€ bin/
β”‚   └── magento
β”œβ”€β”€ generated/
β”œβ”€β”€ pub/
β”‚   β”œβ”€β”€ index.php
β”‚   └── static/
β”œβ”€β”€ var/
└── vendor/

Symfony Β· application tree

<project>/
β”œβ”€β”€ bin/
β”‚   └── console
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ bundles.php
β”‚   β”œβ”€β”€ preload.php
β”‚   β”œβ”€β”€ routes.yaml
β”‚   β”œβ”€β”€ services.yaml
β”‚   β”œβ”€β”€ packages/
β”‚   β”‚   β”œβ”€β”€ cache.yaml
β”‚   β”‚   β”œβ”€β”€ framework.yaml
β”‚   β”‚   β”œβ”€β”€ doctrine.yaml
β”‚   β”‚   β”œβ”€β”€ messenger.yaml
β”‚   β”‚   β”œβ”€β”€ monolog.yaml
β”‚   β”‚   └── security.yaml
β”‚   └── routes/
β”‚       └── framework.yaml
β”œβ”€β”€ migrations/
β”œβ”€β”€ public/
β”‚   └── index.php
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Kernel.php
β”‚   β”œβ”€β”€ Controller/
β”‚   β”œβ”€β”€ Entity/
β”‚   β”œβ”€β”€ Repository/
β”‚   β”œβ”€β”€ EventListener/
β”‚   β”œβ”€β”€ Message/
β”‚   β”œβ”€β”€ MessageHandler/
β”‚   β”œβ”€β”€ Security/
β”‚   └── Dto/
β”œβ”€β”€ templates/
β”œβ”€β”€ translations/
β”œβ”€β”€ tests/
β”œβ”€β”€ var/
β”‚   β”œβ”€β”€ cache/
β”‚   └── log/
β”œβ”€β”€ vendor/
β”œβ”€β”€ .env
β”œβ”€β”€ .env.dev
β”œβ”€β”€ .env.test
β”œβ”€β”€ .env.local
β”œβ”€β”€ composer.json
└── symfony.lock
  • Magento: only registration.php and etc/module.xml are required, the other module folders appear when you need them. app/etc/config.php lists enabled modules, env.php holds the DB, cache and environment keys, generated/ holds the generated Factory, Proxy and Interceptor classes.
  • Symfony: symfony/skeleton creates bin/, config/ (bundles.php, preload.php, routes.yaml, services.yaml, packages/cache.yaml, packages/framework.yaml), public/index.php, src/Kernel.php and src/Controller/, .env and .env.dev with APP_SECRET. Everything else comes from packages (Flex recipes: doctrine.yaml, migrations/, src/Entity/, templates/, .env.test) and MakerBundle commands (make:message, make:listener, make:voter). Dto/ is a project convention, and you create .env.local yourself; it is not committed.

Laying out src/ by technical layers (Controller, Entity…) is only a starting template. For a large project you can group by domain (src/Faq/…, src/Catalog/…), the framework doesn't restrict this: services.yaml registers everything in src/, and Doctrine looks for entities wherever you point it in doctrine.yaml.