A modern web application skeleton based on Slim 4, using the MVC architecture. This project is ideal for quickly starting the development of an API or a web application with a robust stack.
- Framework: Slim 4.15 (PSR-7, PSR-15, PSR-17)
- PHP Version: 8.4+ required
- Dependency Injection Container: PHP-DI 7.0 with autowiring
- ORM: Doctrine ORM 3.5 with DBAL 4.4
- Database: SQLite by default (supports MySQL, PostgreSQL via configuration)
- Template Engine: Twig 3.4
- API Support: RESTful API skeleton with JSON rendering
- Logging: Monolog 3.9 with multiple handlers
- Console: Symfony Console 6.4 with custom commands
- Code Quality: PHP Insights 2.13 & Rector 2.2
- Debugging: Tracy integrated via slim-tracy
- Sessions: Odan Session 6.4 with secure storage
- Migrations: Doctrine Migrations 3.9
- Environment: vlucas/phpdotenv 5.6 for configuration (supports
.envfiles, system environment variables, and mandatory variables usingenv_required(['VAR1', 'VAR2']) - Proxy Support: Built-in proxy detection middleware
- PHP 8.4 or higher
- Composer 2.0 or higher
- SQLite extension (or MySQL/PostgreSQL for production)
- Required PHP extensions: json, pdo, pdo_sqlite
Use Composer to install the project:
composer create-project semhoun/slim-skeleton-mvc [your-app]- Copy the
.env.examplefile to.env:
cp .env.example .env-
By default, the application uses a SQLite database located in
var/database.sqlite. For production, configure your database and other settings in the.envfile or via environment variables. -
Initialize the database:
./console migrations:migrate- (Optional) Generate Doctrine proxies:
./console orm:generate-proxiesYou can use the PHP built-in development server:
composer startOr use the console command:
./console serveThe application will be accessible at http://localhost:8080.
# Clear application cache
./console cache:clear
# Initialize cache
./console cache:init
# Generate Doctrine proxies
./console orm:generate-proxies
# Run development server
./console serve
# List all available commands
./console listRun unit tests:
composer testCheck code quality with PHP Insights:
composer insights-checkApply automatic Rector fixes:
composer rector-fixFix code style issues:
composer insights-fixRun pre-commit checks (code style + rector + dos2unix):
composer pre-commitA compose.yml file is provided to facilitate deployment. Here is a configuration example:
services:
slim:
image: semhoun/webserver
ports:
- "8080:80"
volumes:
- .:/www
environment:
- APP_ENV=dev
- DEBUG_MODE=trueTo launch the environment with Docker:
docker compose up -d- Ensure that the
varfolder has write permissions (for cache, logs, database) - Default credentials: admin / admin (change in production!)
- The project includes an error rendering system (HTML/JSON) based on the
Acceptheader - API routes are prefixed with
/api(configurable inconfig/settings/_base_.php)
This project is licensed under the MIT License. See the LICENSE file for more details.
See the CHANGELOG.md file for version history and upcoming changes.