Architecture
Context
A Symfony site in two parts: a public front end to browse trainings and playlists, and a protected back office to manage everything. It runs on my VPS, and GitHub Actions keeps it up to date on its own.
What was there
The starting Symfony project is unfinished. The MVC architecture is in place and the Doctrine entities exist, but a good part of the controllers and business logic is still to be written.
The request
Complete the public site (catalogue, playlists) and add a secure back office to manage trainings, playlists and categories. Then put the whole thing online.
What I built
-
Playlists: count and sort
A column shows how many trainings each playlist holds, sortable both ways. The same count appears on the detail page.
-
Back office
Adding, editing and deleting trainings, playlists and categories, with Symfony forms. Every deletion asks for confirmation.
-
Authentication
The admin area sits behind a login form handled by the Symfony Security component.
-
Videos
Each training shows its YouTube video from its id.
-
Tests and documentation
PHPUnit tests, documentation generated with phpDocumentor and published on its own subdomain.
-
Continuous deployment
A GitHub Actions workflow connects to the VPS over SSH on every push to main:
git pull,composer installin production mode, cache cleared, ownership handed back towww-data.
Code excerpts
Code copied as is from the repositories:
name: Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: deploy sur le vps
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cd /var/www/mediatek
git pull origin main
composer install --no-dev --optimize-autoloader
php bin/console cache:clear --env=prod
chown -R www-data:www-data /var/www/mediatek
public function findAllOrderByFormationsCount($ordre): array{
$playlists = $this->findAll();
$nbrFormations = [];
foreach($playlists as $p){
$nbrFormations[] = count($p->getFormations());
}
if($ordre == 'ASC'){
array_multisort($nbrFormations, SORT_ASC, $playlists);
}else{
array_multisort($nbrFormations, SORT_DESC, $playlists);
}
return $playlists;
}
ORDER BY COUNT(f.id) is what's missing.
In hindsight
What I would
do differently.
Reread today with a more systems and database minded eye. None of this kept the project from working, but all of it would matter in production.
-
#1
Sorting by number of trainings
It loads every playlist, counts their trainings in PHP, then sorts the array. A single query with
COUNT(),GROUP BYandORDER BYwould do the work in the database, without loading every training into memory. -
#2
Deploying with git pull
The server pulls the repository directly: if
composer installfails halfway, the site is left in a broken state. I would build each release in its own folder, then switch a symbolic link, with a one-command rollback. -
#3
Migrations
The workflow does not run
doctrine:migrations:migrate, so a schema change has to be applied by hand in production. I would add it to the pipeline, right after a database backup. -
#4
The admin account
It is defined in
security.yaml. For several administrators, a User entity in the database with hashed passwords is cleaner, and the committed.envhas to leave the repository.
Stack
Backend
PHP 8.4
Symfony 6.4
Doctrine ORM
PHPUnit
phpDocumentor
Frontend
Twig
HTML / CSS
JavaScript
Data
MySQL
Doctrine Migrations
Infra
OVH VPS
Ubuntu
nginx
PHP-FPM
GitHub Actions
Tools
Composer
Symfony CLI
Git
Demo
The video only loads when you click it, so there is no YouTube cookie until you ask for one.
BTS SIO framework
The framework competencies this project puts to work.
B1IT service support and delivery
B1.2Handle incidents and requests for support and changesB1.3Develop the organisation's online presenceB1.4Work in project modeB1.5Make an IT service available to users
B2Application design and development (SLAM)
B2.1.1Model an application solutionB2.1.3Develop an application solutionB2.1.4Design and build a user interfaceB2.2.1Gather, analyse and update information about an application solutionB2.2.4Update technical and user documentationB2.2.5Design and run tests for the updated componentsB2.3.1Design or adapt a databaseB2.3.2Carry out operations on a database