feruz / yii2-starter-v1
Yii 2 Advanced Project Starter kids
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Type:project
pkg:composer/feruz/yii2-starter-v1
Requires
- php: >=8.3.0
- php-amqplib/php-amqplib: ^3.5
- predis/predis: ^2.2
- symfony/yaml: ^6.3
- yiisoft/yii2: ~2.0.49
- yiisoft/yii2-bootstrap5: ~2.0.2
- yiisoft/yii2-redis: ~2.0.0
- yiisoft/yii2-symfonymailer: ~2.0.3
Requires (Dev)
- codeception/codeception: ^5.0.0
- codeception/module-asserts: ^3.0.0
- codeception/module-filesystem: ^3.0.0
- codeception/module-yii2: ^1.1.0
- phpunit/phpunit: ~9.5.0
- symfony/browser-kit: ^6.0
- yiisoft/yii2-debug: ~2.1.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.2.0
This package is auto-updated.
Last update: 2025-12-03 18:30:16 UTC
README
Complete Yii2 Advanced Template starter kit with Docker support, including API protection, monitoring, and microservices architecture.
๐ Features
- Yii2 Advanced Template with API application
- Docker-based development and production environment
- PHP 8.3 with PHP-FPM
- Nginx web server with optimized configuration
- PostgreSQL 15 database
- Redis 7 for caching and sessions
- RabbitMQ 3.12 message broker
- Supervisor for background workers
- API Protection:
- Priority-based rate limiting (Token Bucket)
- Adaptive throttling (CPU/Memory based)
- Circuit breaker pattern
- Load shedding
- Monitoring:
- PHP-FPM metrics
- Application metrics
- Alert system (Telegram, Email, Slack)
- Health checks
- Outbox Pattern for reliable event publishing
- Prometheus & Grafana support (optional)
๐ Prerequisites
- Docker 20.10+
- Docker Compose 2.0+
- Make (optional, for convenience commands)
๐ ๏ธ Quick Start
1. Clone and Initialize
# Clone the repository git clone <repository-url> cd yii2-advanced-docker # Copy environment file cp .env.example .env # Edit .env file with your configuration nano .env # Initialize and start services make init make up
Or without Make:
cp .env.example .env
docker-compose build
docker-compose up -d
docker-compose exec php-fpm php yii migrate --interactive=0
2. Access Services
- Frontend: http://localhost:8080
- Backend: http://localhost:8081
- API: http://localhost:8082
- API Health: http://localhost:8082/health
- RabbitMQ Management: http://localhost:15672 (guest/guest)
- Prometheus: http://localhost:9090 (with monitoring profile)
- Grafana: http://localhost:3000 (admin/admin, with monitoring profile)
3. Health Check
curl http://localhost:8082/health
๐ Project Structure
yii2-advanced-docker/
โโโ api/ # API application
โ โโโ config/ # API configuration
โ โโโ controllers/ # API controllers
โ โโโ web/ # Web root
โโโ common/ # Shared components
โ โโโ components/ # Protection components
โ โโโ behaviors/ # Behaviors
โ โโโ models/ # Models
โ โโโ config/ # Common config
โโโ console/ # Console commands
โ โโโ controllers/ # Workers
โโโ docker/ # Docker configuration
โ โโโ php-fpm/ # PHP-FPM config
โ โโโ nginx/ # Nginx config
โ โโโ postgresql/ # PostgreSQL config
โ โโโ redis/ # Redis config
โ โโโ rabbitmq/ # RabbitMQ config
โโโ migrations/ # Database migrations
โโโ scripts/ # Utility scripts
โโโ docker-compose.yml # Main compose file
โโโ Makefile # Convenience commands
โโโ README.md
๐ง Configuration
Environment Variables
Key environment variables (see .env.example for full list):
# Database DB_DSN=pgsql:host=pgsql;dbname=yii2advanced DB_USERNAME=yii2 DB_PASSWORD=secret # Redis REDIS_HOST=redis REDIS_PORT=6379 # RabbitMQ RABBITMQ_HOST=rabbitmq RABBITMQ_USER=guest RABBITMQ_PASSWORD=guest # Rate Limiting RATE_LIMIT_USER_CAPACITY=100 RATE_LIMIT_USER_REFILL_RATE=10 # Throttling THROTTLE_CPU_THRESHOLD=70 THROTTLE_MEMORY_THRESHOLD=80 # Alerts ALERT_TELEGRAM_TOKEN=your_token ALERT_TELEGRAM_CHAT_ID=your_chat_id ALERT_EMAILS=admin@example.com
Alert Configuration
Edit common/config/alerts.yml to configure alert rules:
alerts: fpm_warning: severity: warning channels: - log - telegram throttle: 300 # seconds
๐ Running Workers
Workers are automatically started by Supervisor in the PHP-FPM container:
- Outbox Processor (2 instances) - Publishes events to RabbitMQ
- FPM Monitor - Monitors PHP-FPM health
- Metrics Collector - Collects application metrics
- Alert Checker - Checks alert conditions
View worker logs:
make logs-workers # or docker-compose exec php-fpm tail -f /var/log/supervisor/*.log
๐ Monitoring
View Metrics
curl http://localhost/api/monitoring/metrics
View FPM Status
curl http://localhost/api/monitoring/fpm-status
Alert History
docker-compose exec php-fpm php yii alert/history
๐งช Testing
Create Test Order
curl -X POST http://localhost:8082/order/create \ -H "Content-Type: application/json" \ -d '{ "user_id": 1, "total_amount": 99.99, "items": [ {"id": 1, "name": "Product 1", "price": 49.99, "quantity": 1}, {"id": 2, "name": "Product 2", "price": 50.00, "quantity": 1} ] }'
List Orders
curl http://localhost:8082/order/index
Test Rate Limiting
for i in {1..100}; do curl http://localhost:8082/order/index; done
๐ณ Docker Commands
Using Makefile
make help # Show available commands make up # Start all services make down # Stop all services make restart # Restart all services make logs # Tail all logs make shell # Shell into PHP container make migrate # Run migrations make composer-install # Install dependencies make monitoring # Start with monitoring stack
Using Docker Compose Directly
docker-compose up -d # Start services docker-compose down # Stop services docker-compose ps # List services docker-compose logs -f # Tail logs docker-compose exec php-fpm sh # Shell into PHP
๐จ Development
Run Migrations
make migrate # or docker-compose exec php-fpm php yii migrate
Create Migration
make migrate-create name=create_users_table
Install Dependencies
make composer-install # or docker-compose exec php-fpm composer install
Access Database
make shell-db # or docker-compose exec pgsql psql -U yii2 -d yii2advanced
๐ Production Deployment
1. Update Environment
cp .env.example .env.production
# Edit .env.production with production settings
2. Build Production Images
docker-compose -f docker-compose.yml -f docker-compose.prod.yml build
3. Deploy
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
4. Security Checklist
- Change all default passwords
- Configure HTTPS/SSL certificates
- Set proper file permissions
- Configure firewall rules
- Enable security headers in Nginx
- Set up log rotation
- Configure backup strategy
- Set up monitoring alerts
๐ Troubleshooting
Services Won't Start
# Check logs docker-compose logs # Rebuild containers docker-compose down docker-compose build --no-cache docker-compose up -d
Database Connection Issues
# Check database is running docker-compose ps pgsql # Test connection docker-compose exec php-fpm php yii migrate --interactive=0
Permission Issues
# Fix permissions docker-compose exec php-fpm chown -R www:www /var/www
Worker Not Running
# Check supervisor status docker-compose exec php-fpm supervisorctl status # Restart workers docker-compose exec php-fpm supervisorctl restart all
๐ Documentation
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the BSD-3-Clause License.
๐ Acknowledgments
- Yii2 Framework Team
- Docker Community
- All contributors
Built with โค๏ธ using Yii2 and Docker