@@ -8,27 +8,40 @@ These instructions guide Copilot to generate code that aligns with **Laravel 12*
88
99## ✅ Project Overview
1010
11- This is a modern Laravel 12 Blog API built with PHP 8.4, featuring a clean architecture, comprehensive testing, and Docker-based development environment. The API serves as the backend for a blog platform with authentication, role-based permissions, and content management capabilities .
11+ This is a modern ** Laravel 12 Blog API** built with ** PHP 8.4** , featuring a clean architecture, comprehensive testing, Docker-based development environment, and advanced code quality tools . The API serves as a production-ready backend for a blog platform with authentication, role-based permissions, content management, and automated quality assurance .
1212
1313### Technology Stack
14- - ** Laravel Framework** : 12.0+ (latest)
14+ - ** Laravel Framework** : 12.0+ (latest features )
1515- ** PHP** : 8.4+ (with strict typing enabled)
16- - ** Database** : MySQL 8.0
17- - ** Cache/Session** : Redis
18- - ** Authentication** : Laravel Sanctum (API tokens)
16+ - ** Database** : MySQL 8.0 (development) + MySQL 8.0 (testing - isolated environment)
17+ - ** Cache/Session** : Redis (development) + Redis (testing - isolated environment)
18+ - ** Authentication** : Laravel Sanctum (API tokens with abilities )
1919- ** Testing** : Pest PHP 3.8+ (BDD-style testing framework)
20- - ** Static Analysis** : Larastan 3.0+ (PHPStan for Laravel)
20+ - ** Static Analysis** : Larastan 3.0+ (PHPStan level 10 for Laravel)
2121- ** Code Formatting** : Laravel Pint (PHP-CS-Fixer preset)
22- - ** API Documentation** : Scramble (OpenAPI/Swagger documentation)
23- - ** Containerization** : Docker & Docker Compose
24-
25- ### Key Packages
26- - ` laravel/sanctum ` : API authentication
27- - ` dedoc/scramble ` : OpenAPI documentation generation
28- - ` pestphp/pest ` : Testing framework
29- - ` larastan/larastan ` : Static analysis
30- - ` laravel/pint ` : Code formatting
22+ - ** API Documentation** : Scramble (OpenAPI/Swagger automatic generation)
23+ - ** Containerization** : Docker & Docker Compose (multi-service architecture)
24+ - ** Quality Analysis** : SonarQube integration (optional)
25+ - ** Git Tools** : Husky hooks, semantic commits, automated validation
26+
27+ ### Key Development Features
28+ - ** Semantic Commit Enforcement** : Automated commit message validation with Conventional Commits
29+ - ** Automated Testing Pipeline** : Isolated Docker test environment with 80% coverage requirement
30+ - ** Code Quality Gates** : Pre-commit linting, pre-push testing, PHPStan level 10 analysis
31+ - ** Multi-Environment Setup** : Separate containers for development, testing, and quality analysis
32+ - ** Make-based Workflow** : Standardized commands for all development operations
33+ - ** Git Hook Automation** : Automatic code quality checks and commit message formatting
34+
35+ ### Key Packages & Tools
36+ - ` laravel/sanctum ` : API authentication with token abilities
37+ - ` dedoc/scramble ` : Automatic OpenAPI documentation generation
38+ - ` pestphp/pest ` : BDD-style testing framework
39+ - ` larastan/larastan ` : Static analysis (PHPStan for Laravel)
40+ - ` laravel/pint ` : Code formatting and style enforcement
3141- ` laravel/pail ` : Real-time log monitoring
42+ - ** Husky** : Git hooks management
43+ - ** Commitizen** : Interactive semantic commit interface
44+ - ** SonarQube** : Comprehensive code quality analysis (optional)
3245
3346---
3447
@@ -255,38 +268,209 @@ Key relationships:
255268
256269## ✅ Copilot Behavior Preferences
257270
258- - Generate modern, ** strictly typed** PHP code.
259- - Favor readable, maintainable code over cleverness.
260- - Avoid legacy Laravel patterns (e.g., facade overuse, logic-heavy views).
261- - Suggest proper class placement.
262- - Suggest tests alongside features.
263-
264- ### Project-Specific Preferences
265- - ** Code Quality** : Always include ` declare(strict_types=1); ` in all PHP files
266- - ** Documentation** : Use Scramble attributes for API documentation
267- - ** Architecture** : Implement service layer pattern with interfaces
268- - ** Error Handling** : Use specific exception types with proper HTTP responses
269- - ** Database** : Use proper Eloquent relationships with type hints
270- - ** Development** : Consider Docker environment when suggesting commands or configurations
271- - ** Testing** : Write Pest PHP tests using BDD-style describe/it blocks
272- - ** Static Analysis** : Ensure code passes Larastan level 10 analysis
273-
274- ### Common Development Commands
271+ ### Code Generation Standards
272+ - Generate modern, ** strictly typed** PHP code with ` declare(strict_types=1); `
273+ - Favor readable, maintainable code over cleverness
274+ - Avoid legacy Laravel patterns (e.g., facade overuse, logic-heavy views)
275+ - Suggest proper class placement within the established project structure
276+ - Suggest comprehensive tests alongside features using Pest PHP
277+
278+ ### Command Execution Preferences
279+ - ** Always use Makefile commands** instead of direct Docker or Composer commands
280+ - ** Prefer standardized workflows** : Use ` make local-setup ` for initial setup
281+ - ** Use proper development commands** : ` make test ` , ` make lint ` , ` make analyze ` for quality checks
282+ - ** Leverage semantic commits** : Suggest ` make commit ` for guided commit process
283+ - ** Consider Docker environment** : All commands should work within the containerized setup
284+
285+ ### Development Workflow Integration
286+ - ** Understand the Make-based workflow** and suggest appropriate ` make ` commands
287+ - ** Recommend quality gates** : Always mention running tests and linting before commits
288+ - ** Consider the automated pipeline** : Suggest commands that work with Git hooks
289+ - ** Respect environment separation** : Understand development vs testing container differences
290+ - ** Support troubleshooting** : Use ` make help ` , ` make status ` , ` make health ` for guidance
291+
292+ ### Project-Specific Command Suggestions
293+ When suggesting development tasks, always use the established Makefile commands:
294+
295+ #### For Setup & Environment
275296``` bash
276- # Docker environment
277- make docker-setup-all # Complete setup
278- make docker-dev # Start development
279- make docker-test # Run all tests
280- make docker-lint # Run code formatting
281- make docker-analyze # Run static analysis
282-
283- # Database operations
284- make docker-artisan ARGS=" migrate"
285- make docker-artisan ARGS=" migrate:fresh --seed"
297+ make local-setup # Complete development environment setup
298+ make sonarqube-setup # Optional quality analysis setup
299+ make docker-up # Start development containers
300+ make status # Check environment status
286301```
287302
288- ### Environment Configuration
289- - ** Development** : Docker-based with MySQL 8.0, Redis, and PHP 8.4
290- - ** API Base URL** : http://localhost:8081
303+ #### For Development Workflow
304+ ``` bash
305+ make commit # Interactive semantic commits
306+ make test # Run test suite
307+ make lint # Code formatting
308+ make analyze # Static analysis
309+ make artisan ARGS=" ..." # Laravel commands
310+ ```
311+
312+ #### For Troubleshooting
313+ ``` bash
314+ make help # Show all available commands
315+ make health # Check application health
316+ make logs # View container logs
317+ make shell # Access container shell
318+ ```
319+
320+ ### Project-Specific Development Guidelines
321+
322+ #### Code Quality Standards
323+ - ** Always include** ` declare(strict_types=1); ` in all PHP files
324+ - ** Use Scramble attributes** for API documentation (` #[Group] ` , ` #[ResponseField] ` , etc.)
325+ - ** Implement service layer pattern** with interfaces for testability
326+ - ** Use specific exception types** with proper HTTP response codes
327+ - ** Write comprehensive tests** using Pest PHP with BDD-style describe/it blocks
328+ - ** Ensure PHPStan level 10** compliance for maximum static analysis strictness
329+
330+ #### Development Environment Integration
331+ - ** Always use Docker commands** through Makefile for consistency
332+ - ** Prefer ` make ` commands** over direct Docker Compose for standardized workflow
333+ - ** Use automated testing environment** with ` make test ` for isolated, repeatable tests
334+ - ** Leverage Git hooks** for automated quality checks on commits and pushes
335+ - ** Use semantic commits** with ` make commit ` for standardized commit messages
336+
337+ #### Testing & Quality Assurance
338+ - ** Write Pest PHP tests** using describe/it blocks for better organization
339+ - ** Maintain 80%+ test coverage** as enforced by the test pipeline
340+ - ** Use separate test environment** with isolated database and Redis instances
341+ - ** Run comprehensive quality checks** with SonarQube integration when available
342+ - ** Validate code with multiple tools** : Pint (formatting), PHPStan (static analysis), Pest (testing)
343+
344+ #### API Development Standards
345+ - ** Follow RESTful conventions** with proper HTTP methods and status codes
346+ - ** Use Laravel Sanctum** for API authentication with ability-based tokens
347+ - ** Implement proper authorization** using Laravel Policies and Gates
348+ - ** Document APIs with Scramble** for automatic OpenAPI/Swagger generation
349+ - ** Use API Resource classes** for consistent JSON response formatting
350+ - ** Version APIs properly** with ` /api/v1/ ` prefix structure
351+
352+ #### Database & Performance
353+ - ** Use Eloquent relationships** with proper type hints and eager loading
354+ - ** Implement proper database constraints** and foreign key relationships
355+ - ** Use Redis for caching** and session management in Docker environment
356+ - ** Apply database migrations** with proper rollback strategies
357+ - ** Use seeders for test data** in both development and testing environments
358+
359+ #### Project Structure Compliance
360+ - ** Follow the established directory structure** as defined in the project overview
361+ - ** Use Enums for type safety** (UserRole, ArticleStatus, NotificationType, etc.)
362+ - ** Implement service layer architecture** with dependency injection
363+ - ** Use Form Request classes** for input validation
364+ - ** Apply single responsibility principle** in Controllers, Services, and Actions
365+
366+ #### Troubleshooting & Maintenance
367+ - ** Use ` make help ` ** to view all available commands with descriptions
368+ - ** Check container health** with ` make status ` and ` make health ` commands
369+ - ** Access logs** via ` make logs ` for debugging container issues
370+ - ** Use shell access** with ` make shell ` or ` make test-shell ` for direct container interaction
371+ - ** Clean up resources** with ` make docker-cleanup ` for complete environment reset
372+
373+ ### Project Setup & Development Commands
374+
375+ #### Main Setup Commands (One-time setup)
376+ ``` bash
377+ # Complete local development environment setup
378+ make local-setup # Sets up Docker containers, dependencies, Git hooks, and semantic commit tools
379+
380+ # Optional: Add SonarQube code quality analysis
381+ make sonarqube-setup # After local-setup, adds comprehensive code quality analysis
382+ ```
383+
384+ #### Daily Development Workflow
385+ ``` bash
386+ # Semantic commits with validation
387+ make commit # Interactive semantic commit (guided process)
388+ make validate-commit # Validate commit message format
389+
390+ # Testing
391+ make test # Run complete test suite (automated Docker environment)
392+ make test-coverage # Run tests with coverage report (minimum 80% required)
393+
394+ # Code quality
395+ make lint # Run Laravel Pint code formatting
396+ make lint-dirty # Lint only changed files (faster)
397+ make analyze # Run PHPStan static analysis (level 10)
398+
399+ # Development tools
400+ make artisan ARGS=" ..." # Run any artisan command (e.g., make artisan ARGS="migrate --seed")
401+ ```
402+
403+ #### Container Management
404+ ``` bash
405+ # Environment control
406+ make docker-up # Start development containers
407+ make docker-down # Stop development containers
408+ make docker-restart # Restart development environment
409+ make docker-cleanup # Complete cleanup (containers, images, volumes)
410+
411+ # Utilities
412+ make status # Check container status and access points
413+ make health # Check application health and readiness
414+ make logs # View container logs
415+ make shell # Access main container shell
416+ make test-shell # Access test container shell
417+ ```
418+
419+ #### SonarQube Quality Analysis (Optional)
420+ ``` bash
421+ # SonarQube setup and management
422+ make sonarqube-start # Start SonarQube server
423+ make sonarqube-setup-token # Setup authentication token
424+ make sonarqube-analyze # Run comprehensive code quality analysis
425+ make sonarqube-dashboard # Open SonarQube dashboard
426+ make sonarqube-stop # Stop SonarQube server
427+ ```
428+
429+ ### Environment Configuration & Access Points
430+
431+ #### Development Environment
432+ - ** Main API** : http://localhost:8081
433+ - ** Health Check** : http://localhost:8081/api/health
291434- ** API Documentation** : http://localhost:8081/docs/api
292- - ** Testing** : Separate Docker environment with clean database state
435+ - ** MySQL Development** : localhost:3306 (laravel_user/laravel_password)
436+ - ** Redis** : localhost:6379
437+
438+ #### Testing Environment (Automated)
439+ - ** MySQL Test** : localhost:3307 (separate test database)
440+ - ** Redis Test** : localhost:6380 (separate test cache)
441+ - ** Coverage Reports** : reports/coverage/index.html
442+ - ** Coverage XML** : reports/coverage.xml
443+
444+ #### Optional Quality Analysis
445+ - ** SonarQube Dashboard** : http://localhost:9000 (admin/admin)
446+
447+ ### Container Architecture
448+ The project uses Docker Compose with multiple services:
449+ - ** laravel_blog_api** : Main application (Nginx + PHP-FPM) on port 8081
450+ - ** laravel_blog_api_mysql** : Development database on port 3306
451+ - ** laravel_blog_api_redis** : Cache and session store on port 6379
452+ - ** laravel_blog_api_queue** : Background job processor
453+ - ** Test Environment** : Separate containers for isolated testing
454+ - ** SonarQube** : Optional code quality analysis server
455+
456+ ### Development Workflow Best Practices
457+
458+ #### Semantic Commits
459+ The project enforces semantic commit messages following Conventional Commits:
460+ - Use ` make commit ` for interactive guided commits
461+ - Automated validation with Git hooks
462+ - Supports: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert
463+ - Examples: ` feat(auth): add user registration endpoint ` , ` fix(api): resolve token validation `
464+
465+ #### Git Hooks & Automation
466+ - ** pre-commit** : Runs linting on changed files
467+ - ** pre-push** : Runs tests with PHPStan analysis
468+ - ** prepare-commit-msg** : Formats commit messages
469+ - ** Husky integration** : Node.js-based commit tools
470+
471+ #### Quality Gates
472+ - ** Minimum 80% test coverage** enforced
473+ - ** PHPStan level 10** static analysis
474+ - ** Laravel Pint** code formatting
475+ - ** Pest PHP** BDD-style testing
476+ - ** SonarQube integration** for comprehensive analysis
0 commit comments