Sitemap

Symfony Through a Fan’s Eyes: A Simple Guide

3 min readNov 22, 2024

--

Let’s say you’re a loyal Symfony fan, and you get the chance to talk about it to a PHP developer who’s choosing their next framework. This is your opportunity to convert them into a Symfony fan, just like you are! So, let’s explain Symfony clearly and highlight its strengths without overwhelming them or making it seem complicated.

MVC

Symfony is based on MVC architecture. The Model manages your data and business logic, the View takes care of the user interface, and the Controller handles requests and connects the two. This structure makes applications easier to manage, scale, and maintain over time.

Symfony Structure

Symfony Structure

assets/
It contains your frontend assets (CSS, JS, files) that are processed or compiled by Webpack Encore or Asset Mapper.

bin/
Holds executable files, such as (bin/console), used for running commands and managing the application.

var/
It stores temporary data like cache files, logs …etc.

PS: it’s automatically managed.

config/
It’s exactly like the “Setting” button on your phone. It stores all configuration files for the application, such as services, routes, and security settings, bundles …etc. These configurations can be modified per every environment (dev, prod or test).

migrations/
Contains migration files for managing database schema that have been generated automatically by Doctrine.

public/
The document root for your app files. It contains the index.php file (entry point), along with static public assets like images, JavaScript, and CSS files that are directly accessible via URLs.

PS: Be sure to ignore the folder where user-uploaded files are stored (e.g., uploads/) in your .gitignore file to avoid accidentally overwriting or losing your users’ data during deployments.

src/
The core of your app. This folder contains all the PHP code, including controllers, entities, services, forms, event listeners and more. Here where you are gonna spend 90% of your time of development.

templates/
Contains Twig files for your app’s front-end views.

tests/
Contains your automated tests, organized by functional and unit tests.

translations/
Stores translation files for supporting multiple languages in your app, often in .yaml or .xlf formats.

vendor/
Contains third-party dependencies installed via Composer.

PS: Don’t modify this folder, it’s managed automatically. Also, avoid pushing it to GitHub, as it’s already ignored in .gitignore file.

.env File
Not a folder, but worth mentioning. This file stores environment-specific variables, such as database credentials and API keys.

Environments

In Symfony we have 3 environments that should be changed regularly based on your use. So, in your local laptop use “Dev”, while testing it use “Test”, in production use “prod”.

Doctrine

With Doctrine, you’re free from writing raw SQL queries. It leverages the power of ORM (Object-Relational Mapping), making database management both efficient and fun. Just learn the ORM basics, and building databases will feel like a breeze!

Twig

If you prefer not to use APIs or frontend frameworks like Angular, Twig templates are more than enough for most of your needs.

PS 1: You can integrate React or Vue.js components directly within Symfony.
PS 2: Using Stimulus and Turbo bundles adds powerful features seamlessly, similar to external frameworks.

Happy coding 😊

--

--

Lubna Altungi
Lubna Altungi

Written by Lubna Altungi

Full stack web developer "If you write, you can turn your lessons into your legacy"

No responses yet

Write a response