Getting started with Symfony 4: Structure

December 7, 2018
Framework Structure

Every framework has its own directory structure. Some of them may be similar to other ones. For example, Laravel looks similar to Symfony, since it’s based on Symfony framework, but on the other hand, CodeIgniter does not look similar to any of the two I mention above.

For better view of how the structures looks from these frameworks, take a look at the image bellow.

Symfony Laravel CodeIgniter Structure
Symfony, Laravel, CodeIgniter Directory Structure

Since this post is all about Symfony, it is worth of mentioning that Symfony 2 has a small difference in directory structure, comparing to the Symfony 3, same goes for the Symfony 4. 

The Symfony 3 directory structure introduced a more standard Unix-like directory structure, with less sub-directories. Symfony 4 keeps going in that direction.

After you have started your Symfony 4 project (if not, read post on Symfony Introduction), let’s take a better look at the Symfony 4 directory structure, and see the purpose of each directory. 

 bin/  directory has the console file inside. To know what the console can do, just write inside the terminal  bin/console  and you will have lists of all bin/console commands available. 

Symfony list commands
bin/console available commands

Windows users have to write  php bin/console , since it is just a PHP file.

 config/  holds all configuration files. Previously (Symfony 3) these files were located in  app/config/ . Configuration files can be written in PHP, XML or YAML.

 public/  is the document root, where you hold all publicly accessible files. There is one file index.php which is basically a front controller. This means that it will get executed on every request.

 src/  holds all PHP files (classes). This is the directory where you will spend most of your time, building bundles, models, controllers etc. 

 templates/  By default, templates can live in two different locations. templates/ is one of them. This directory can contain application-wide base templates as well as templates that override third party bundle templates. To get better understanding, take a look at Symfony documentation on Template Naming and Locations.

 tests/  will hold our unit and funcitonal test, done in any testing framework (Example: PHPUnit).

 translations/  If you have enabled and configured Symfony’s translation service, this is the directory which you are going to use to store translation files for each supported locale that translate each message in your application. Here you can learn more about translation service.

 var/  directory is used for temporary files. 

 vendor/  is a place where the Symfony is located, including the 3rd party libraries, which were downloaded by composer (libraries from composer.json file). 

To get even more details about Symfony directory structure, please read this great article from Fabien Potencier.

You Might Also Like


  • Reply Nicolas December 9, 2018 at 22:20

    Well when you see symfony, lav and codeigniter shown like this, you actually get better understanding how sf and lav are similar to each other while codeigniter is not

  • Reply Jen75 December 11, 2018 at 18:55

    How to use symfony translations? By adding files in translations or?

  • Leave a Reply