phil / websymfony
A Symfony web application template built on MicroSymfony: accounts, security headers, an administration, Pico CSS, tests and quality gates.
Package info
github.com/parler-haut-interagir-librement/WebSymfony
Type:project
pkg:composer/phil/websymfony
Requires
- php: >=8.5
- ext-ctype: *
- ext-dom: *
- ext-iconv: *
- ext-libxml: *
- ext-mbstring: *
- ext-simplexml: *
- ext-xml: *
- doctrine/dbal: ^4.6
- doctrine/doctrine-bundle: ^3.4
- doctrine/doctrine-migrations-bundle: ^4.0
- doctrine/migrations: ^3.10
- doctrine/orm: ^3.8
- doctrine/persistence: ^4.2
- easycorp/easyadmin-bundle: ^5.10
- gedmo/doctrine-extensions: ^3.22
- knplabs/knp-menu: ^3.8
- knplabs/knp-menu-bundle: ^3.8
- league/commonmark: ^2.10
- nelmio/cors-bundle: ^2.6
- nelmio/security-bundle: ^3.9
- sentry/sentry-symfony: ^5.17
- stof/doctrine-extensions-bundle: ^1.15
- symfony/asset: ^8.2
- symfony/asset-mapper: ^8.2
- symfony/cache-contracts: ^3.8
- symfony/console: ^8.2
- symfony/dependency-injection: ^8.2
- symfony/doctrine-bridge: ^8.2
- symfony/dotenv: ^8.2
- symfony/filesystem: ^8.2
- symfony/flex: ^2.12
- symfony/form: ^8.2
- symfony/framework-bundle: ^8.2
- symfony/http-foundation: ^8.2
- symfony/http-kernel: ^8.2
- symfony/intl: ^8.2
- symfony/monolog-bundle: ^4.1
- symfony/options-resolver: ^8.2
- symfony/password-hasher: ^8.2
- symfony/rate-limiter: ^8.2
- symfony/routing: ^8.2
- symfony/runtime: ^8.2
- symfony/security-bundle: ^8.2
- symfony/security-core: ^8.2
- symfony/security-csrf: ^8.2
- symfony/security-http: ^8.2
- symfony/stimulus-bundle: ^3.8
- symfony/string: ^8.2
- symfony/translation: ^8.2
- symfony/twig-bundle: ^8.2
- symfony/ux-turbo: ^3.8
- symfony/validator: ^8.2
- symfony/web-link: ^8.2
- symfony/yaml: ^8.2
- twig/extra-bundle: ^3.31
- twig/markdown-extra: ^3.31
- twig/twig: ^3.31
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.9
- brianium/paratest: ^7.30
- ergebnis/phpunit-slow-test-detector: ^2.29
- phil/dev-tools: ^0.2.1@alpha
- phpunit/phpunit: ^13.4
- shipmonk/composer-dependency-analyser: ^1.8
- symfony/browser-kit: ^8.2
- symfony/css-selector: ^8.2
- symfony/debug-bundle: ^8.2
- symfony/maker-bundle: ^1.68
- symfony/panther: ^2.4
- symfony/requirements-checker: ^2.0
- symfony/stopwatch: ^8.2
- symfony/web-profiler-bundle: ^8.2
- zenstruck/foundry: ^2.17
Suggests
None
Provides
None
Conflicts
README
About ๐
โProclaim Honestly, Interact Liberallyโ WebSymfony is a Symfony 8.2 web application template on steroids, ready to use: everything MicroSymfony gives, plus what a web site needs from its first day โ member accounts, security headers, an administration, a menu, English and French โ, with the same tests and quality gates.
WebSymfony is built on MicroSymfony, the PHIL version of strangebuzz/MicroSymfony, created and maintained by COil of Strangebuzz. It keeps its name, its layout, its look (Pico CSS) and its spirit. It uses no PHIL package at run time: the PHIL tools โ the PHIL UX kit, phil-ux and the PHIL bundles โ start with WebSkeleton.
Table of Contents ๐
- Documentation
- Demo
- Quick-start
- Requirements
- Stack
- What it adds to MicroSymfony
- Accounts and security
- Tasks
- Quality gates
- Notes
- What it doesn't ship
- References
- Others โProclaim Honestly, Interact Liberallyโ Skeletons
- Contributing
- Security
- Credits
- License
- Built with WebSymfony
Documentation
| Document | What it covers |
|---|---|
| Extension points | What an application built from the template changes first: the accounts, the pages and the menu, the administration, the security headers, the tasks and the exceptions to the gates. |
The tasks and the quality gates are described in vendor/phil/dev-tools/doc/, once the dependencies are installed.
Demo ๐
A demo of WebSymfony will run in the browser on ph-il.ca, with the other templates of PHIL.
Quick-start โก
Create a new project from the latest release:
composer create-project phil/websymfony my-project && cd my-project
The repository is also a GitHub template repository: the "Use this template" button creates a new repository from the main branch, whose commits all pass the continuous integration.
With the Symfony binary ๐ธ๏ธ
You need the Symfony binary and
Castor. The database is a SQLite file in var/:
castor start
Open https://127.0.0.1:8000 (if port 8000 is free). The fixtures create two accounts:
admin (password admin-password), which reaches the administration, and member (password member-password);
never load them where the site is public. castor stop stops the server and
deletes the database.
With FrankenPHP and PostgreSQL ๐ง
You need Docker. compose.yaml serves the application with
FrankenPHP in worker mode, which boots the kernel once and serves request after request,
and restarts its workers when a file changes; the database is PostgreSQL 17:
castor up
Open https://localhost. castor down stops the services. The image of docker/Dockerfile is
for development: an application deployed from this template brings its own deployment.
With MySQL ๐ฌ
MySQL is the other database the template supports. In compose.yaml, replace the database service with a
mysql:8.4 image and set DATABASE_URL to:
mysql://app:app@database:3306/app?serverVersion=8.4&charset=utf8mb4
With the Symfony binary, set the same variable in .env.local, with the host of your server. The migration is written
in the SQL of the database it runs on, so it needs no change.
Requirements
- PHP 8.5 or later, with the extensions of
composer.json, and Castor - The Symfony binary, or Docker
- The Xdebug or PCOV extension for the code coverage report
Stack ๐
- PHP 8.5
- Symfony 8.2, with Symfony Security
- Doctrine ORM 3 (DBAL 4), on SQLite, PostgreSQL or MySQL, with the Doctrine extensions
- Twig 3 and Symfony forms
- AssetMapper, Stimulus 3.2 and Turbo 8, without Node.js
- Pico CSS 2
- EasyAdmin 5
- PHPUnit 13
- FrankenPHP in worker mode, through Docker Compose
What it adds to MicroSymfony ๐
| Feature | Where |
|---|---|
| Sign-up, sign-in and sign-out, an account page | src/Controller/Security, AccountAction |
Users with hashed passwords and roles, ROLE_ADMIN above ROLE_USER |
User, security.yaml |
Entities found wherever they live in src/, with no mapping to write, by auto_discover_entities |
doctrine.yaml |
An administration for ROLE_ADMIN, with the list of users |
src/Controller/Admin |
| Security headers and a Content Security Policy with a nonce, by NelmioSecurityBundle | nelmio_security.yaml |
Cross-origin requests on /api/ only, by NelmioCorsBundle |
nelmio_cors.yaml |
| A main menu built by KnpMenu | MainMenuBuilder |
| English and French, chosen from the browser's language | translations, translation.yaml |
| Dates set by the Timestampable extension | stof_doctrine_extensions.yaml |
Errors sent to Sentry in production, when SENTRY_DSN is set |
sentry.yaml |
| The PHIL identity: logo, copyright, light and dark themes | base.html.twig |
Everything MicroSymfony has stays: the examples, the five test suites, Castor, the quality gates, Docker Compose.
Accounts and security ๐
- Passwords are hashed by the
autohasher; the session keeps a crc32c of the hash, never the hash, so a changed password still signs the other sessions out. - The firewall checks the user again each time it is refreshed from the session (
user_checker_on_refresh): a disabled or changed account is signed out on its next request. - The sign-in, the sign-up and the sign-out carry a CSRF token; the sign-out is a POST.
- Five failed sign-ins a minute per user name and IP address, through
login_throttling. - Impersonation is off; when it is turned on, only by POST with a CSRF token.
/accountasks forROLE_USER,/adminforROLE_ADMIN.
Tasks ๐งฐ
castor lists every task. The main ones:
| Task | What it does |
|---|---|
castor start, castor stop |
The Symfony binary's web server with SQLite, its migrations and its fixtures. |
castor up, castor down |
FrankenPHP in worker mode and PostgreSQL, with Docker Compose. |
castor load-fixtures |
The SQLite database reset, migrated and filled. |
castor test |
Every PHPUnit suite but E2E; --filter and --options pass on to PHPUnit. |
castor test:unit, test:integration, test:api, test:functional |
One suite. |
castor test:e2e |
The E2E suite in a real browser, Chrome driven by Panther: it proves that the JavaScript of the pages runs under the Content Security Policy. Chrome and chromedriver must be on the PATH, or let vendor/bin/bdi detect drivers download the driver into drivers/ after composer require --dev dbrekelmans/bdi. Neither castor test, castor coverage, castor ci nor the continuous integration runs it. |
castor test:suite <name> |
One suite of phpunit.dist.xml, by its name. |
castor test:next |
The tests on the next PHP version, in its Docker image. |
castor test:schema |
The migrations on a fresh SQLite database, then its schema compared with the Doctrine mapping. |
castor coverage |
The HTML coverage report in var/coverage/, and its threshold. |
castor infection |
Mutation testing. |
castor taint |
The taint analysis of Psalm: no untrusted input reaches HTML, SQL, a shell or a file unescaped. |
castor lint |
Every lint and the static analysis. |
castor fix |
Rector, PHP-CS-Fixer, Twig-CS-Fixer, Biome and composer-normalize. |
castor ci |
The continuous integration, locally: coverage, every lint, then test:schema. |
castor hooks |
The git hooks: the fast checks on the staged files before each commit. |
Every task but the servers, go-prod, go-dev, purge, load-fixtures, test:schema, lint:doctrine and
check-requirements comes from phil/dev-tools: castor.php imports
vendor/phil/dev-tools/resources/castor/tasks.php and sets the suites, the coverage threshold of 100 % and the YAML
paths in its PHIL_CASTOR constant, where lint_also adds lint:doctrine to castor lint and ci_also adds
test:schema to castor ci. A task of the application's own is added to castor.php under a name of its own, and
named in the test_also, lint_also, fix_also or ci_also setting to run with the aggregate tasks; the tasks and
settings are described in vendor/phil/dev-tools/doc/castor.md.
The functional suite holds RouteSmokeTest, from
Phil\DevTools\Testing\RouteSmokeTesting: every GET route answers under 500, a new route included as soon as it
exists. A route whose parameters have no default is left out, unless smokeRouteParameters() gives values for them.
Quality gates ๐ฆ
The checks come from phil/dev-tools, the shared tooling of PHIL,
adapted to an application. Each tool is installed in its own vendor-bin/<tool>/ directory by the
Composer bin plugin, so that its dependencies never meet the
application's. The thin configuration files at the root (phpstan.neon, rector.php, .php-cs-fixer.dist.php,
arkitect.php) call the shared ones; phil-dev.php holds what is particular to the application, each exception with
its reason.
| Task | Checks |
|---|---|
castor lint:composer |
The dependency analysis (a class used without its package required), composer audit, composer-unused and composer-normalize. |
castor lint:php |
PHP-CS-Fixer: @Symfony, @Symfony:risky, strict types and strict comparisons. |
castor lint:twig |
lint:twig, then the code style of the templates. |
castor lint:js |
Biome on the Stimulus controllers. |
castor lint:yaml, lint:container, lint:doctrine |
The YAML files (config/ among them), the container and the Doctrine mapping. |
castor stan |
PHPStan at the maximum level, with type coverage at 100 %, a cognitive complexity limit and forbidden calls. |
castor lint:rector |
Rector has nothing left to change. |
castor lint:architecture |
Arkitect on the shape of the classes; Deptrac on the libraries src/ may use, listed in phil-dev.php. |
Notes ๐
Symfony UX
Turbo forms are disabled in assets/app.js. To enable them for a form, add the data-turbo="true"
attribute to it, or set Turbo.setFormMode to on to enable them everywhere. In both cases, the controller has to be
adapted.
YAML configuration files
The configuration of Symfony and of the bundles is in YAML, under config/: config/packages/*.yaml, with
when@dev, when@test and when@prod blocks for what changes by environment, config/routes.yaml,
config/routes/*.yaml and config/services.yaml. A Flex recipe adds its files in the same format. Only
config/bundles.php and config/preload.php stay PHP. castor lint:yaml checks every file of config/, and
castor lint:container checks the container they build.
# config/packages/security.yaml security: role_hierarchy: ROLE_ADMIN: [ROLE_USER] access_control: - { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/account, roles: ROLE_USER }
What it doesn't ship ๐
- No deployment file: each application brings its own.
- No PHIL package at run time: the PHIL UX kit, phil-ux and the PHIL bundles come with WebSkeleton.
- No e-mail: the sign-up asks for no confirmation and there is no password reset; add symfonycasts/verify-email-bundle and symfonycasts/reset-password-bundle when the site sends mail.
References ๐
- Introducing the MicroSymfony application template (strangebuzz.com)
- MicroSymfony 8: ready for the LTS promise (strangebuzz.com)
- Initializing your Symfony project with solid foundations (strangebuzz.com)
- Organizing your Symfony project tests (strangebuzz.com)
- A better ADR pattern for your Symfony controllers (strangebuzz.com)
- Castor, a journey across the sea of task runners (jolicode.com)
- PHPStan 2.0 Released With Level 10 and Elephpants! (phpstan.org)
- You should be using PHPStan's bleeding edge (backendtea.com)
- A Good Naming Convention for Routes, Controllers and Templates? (jolicode.com)
- Front-end application development, Symfony-style(s) (dunglas.dev)
- The Symfony Framework Best Practices (symfony.com)
Others โProclaim Honestly, Interact Liberallyโ Skeletons ๐ฉป
- MicroSymfony (
phil/microsymfony): the micro template WebSymfony is built on, with no database, Pico CSS, Stimulus and Turbo, Castor, the tests and quality gates. - WebSkeleton (
phil/webskeleton): WebSymfony and the PHIL tools, organised in DDD (Domain, Application, Infrastructure):- the PHIL UX kit for the Symfony UX Toolkit and
phil/ux-css, the phil-ux stylesheet; - PHIL bundles:
phil/ddd-bundle,phil/doctrine-behaviours-bundle, and, by a documented step,phil/identity-client-bundlefor member accounts andphil/ux-easyadmin-bundlefor an administration in the colours of PHIL UX; - French and English, routes prefixed
/frand/en, French by default.
- the PHIL UX kit for the Symfony UX Toolkit and
- ApiSymfony (
phil/apisymfony): an API with API Platform, Castor, the tests and quality gates.
Contributing
See CONTRIBUTING and the Code of Conduct.
Security ๐งฏ
See SECURITY.
Credits ๐
- Philippe Gamache, maintainer, for Parler Haut, Interagir Librement
- COil, author of strangebuzz/MicroSymfony, and its contributors
- All the contributors of WebSymfony
License
The MIT License, with the attribution to the original repository it asks for: ยฉ Strangebuzz.com, and ยฉ Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See the license file.
Built with WebSymfony ๐ ๏ธ
- WebSkeleton, which lists the sites built with it.