RESTful backend for managing a game database, built with modern PHP practices and a DDD-inspired structure.
This project is designed as a study and portfolio application focusing on:
- Clean architecture
- Secure authentication and encryption
- Containerized development
- Scalable environment configuration
- REST API
- JWT Authentication
- Redis caching
- Database migrations with Phinx
- Encryption (Sodium / Defuse)
- Docker-first development
- PSR-4 and PSR-12 compliant
- Unit testing with PHPUnit
- Environment variables
- Centralized error logging
- PHP 8.4
- Nginx
- MariaDB
- Redis
- Docker
- Composer
- PHPUnit
- Phinx
- Dotenv
The project loosely follows DDD principles:
- Domain
- Application
- Infrastructure
- Presentation
🚧 Active development.
GPL-3.0
The project uses layered environment files:
.env
.env.{environment}.{machine}
Example .env:
ENVIRONMENT=development
MACHINE=local
This requires a matching file:
.env.development.local
Copy all keys from .env.example into your environment file and fill in the values.
NGINX_PORT="80"
NGINX_EXPOSE_PORT="8081"
NGINX_PORT: internal container port
NGINX_EXPOSE_PORT: host port mapped to container
API_CONSUMERS_ADDRESSES="http://localhost:8082,http://localhost:8083"
API_CONSUMERS_ADDRESSES_SEPARATOR=","
REPOSITORY_ROOT_USERNAME="backend_root"
REPOSITORY_ROOT_PASSWORD="secret"
REPOSITORY_HOST="database"
REPOSITORY_DATABASE="gamebase"
REPOSITORY_USERNAME="user"
REPOSITORY_PASSWORD="password"
REPOSITORY_PORT="3306"
REPOSITORY_CHARSET="utf8mb4"
REPOSITORY_EXPOSE_PORT="3307"
Choose one method:
ENCRYPTION_METHOD="sodium"
Available:
sodiumdefuse
You may keep the default values, but generating your own keys is recommended.
Enter the PHP container:
docker exec -it gamebase-backend-php bash
Generate Defuse key:
php config/defuse_key.php
Generate Sodium key:
php config/sodium_key.php
Copy the values into:
DEFUSE_PHP_ENCRYPTION_KEY="insert here"
SODIUM_CRYPTO_SECRETBOX_KEY="insert here"
JWT_SECRET="your-secret-key"
REDIS_SCHEME=redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_EXPOSE_PORT=6380
Phinx does not create databases automatically.
You can create it manually or run:
docker exec -it gamebase-backend-php bash
php config/pdo_create_database.php
This creates the database defined in:
REPOSITORY_DATABASE
docker compose --env-file .env.{environment}.{machine} up -d
Enter the PHP container:
docker exec -it gamebase-backend-php bash
Run:
startup.sh
All commands are defined in composer.json.
Formatting follows PSR-12 from PHP-FIG.
composer lint:fix
Fixes issues using php-cs-fixer.
composer format
Shows PSR-12 violations using phpcs.
composer format:fix
Fixes PSR-12 issues using phpcbf.
composer phpunit:test
Examples:
composer phpunit:test:all
composer phinx migrate
composer phinx seed:run
Gamebase Backend is a modern PHP REST API demonstrating:
- DDD structure
- secure authentication
- encryption strategies
- containerized infrastructure
- scalable environment configuration