How ifha/curso-laravel-10 works
Project Type and Purpose
• This is a full-stack Laravel 10 web application that provides both a web-based admin interface (Blade/Tailwind CSS) and a JSON API (Laravel controllers under Http/Controllers/Api).
• It implements a support ticket system where users can create “supports” and administrators can reply; it uses Redis for caching, sessions and queues, MySQL for persistence, and Docker for environment consistency.
File Structure Analysis
• Top-level frameworks and config:
• Dockerfiles and docker-compose.yml spin up containers for PHP (app), Nginx, MySQL, Redis, a queue worker, and a Vite hot-reload service.
• bootstrap/, config/, public/ and routes/ are standard Laravel directories.
• Application code under app/:
• Adapters, DTOs, Repositories (contracts and implementations), Services, Events & Listeners — indicating a layered architecture (Controller → Service → Repository → Model).
• Http/Controllers divided into Admin (Blade views) and Api (REST endpoints).
• Models represent Eloquent entities; Observers and Events handle domain logic.
• Frontend assets under resources/:
• Blade templates (resources/views) for UI.
• JS and CSS handled by Vite (resources/js, resources/css, vite.config.js).
• Background processing:
• app/Console handles Artisan commands.
• Queue worker container listens to Redis and processes email notifications (Mail/SupportRepliedMail).
Key Architectural Patterns
• MVC pattern for web: Routes → Controllers → Views + Models.
• Service-Repository pattern for business logic and data access abstraction.
• DTOs for input validation and data transfer.
• Event-Driven design: Events (SupportReplied) fire Listeners (SendMailWhenSupportReplied, UpdateStatusWhenSupportReplied).
• Asynchronous processing via Laravel Queues and Redis.
• Docker-based micro-containers for each concern (web server, PHP, queue, asset bundling).
Components
a. External Clients:
– Web Browser (users/admin)
– Mobile/3rd-party apps (optional, via JSON API)
b. Reverse Proxy / Web Server:
– Nginx container
c. Application Layer:
– PHP-FPM container running Laravel
– Vite container for asset compilation & hot reload
d. Business Logic Layer (within Laravel):
– HTTP Routing
– Controllers (Admin / API)
– Service Layer (SupportService, ReplySupportService)
– Repository Layer (Eloquent implementations)
– DTO & Request Validation
– Event Dispatcher & Listeners
e. Data Layer:
– MySQL container (supports, reply_supports, users, etc.)
– Redis container (cache, session store, queue backend)
f. Background Workers:
– Queue Worker container consuming jobs from Redis, dispatching email via Mailer
g. External Services:
– SMTP/Email provider (via config/mail.php)
Relationships and Interactions
1. Browser → Nginx → PHP-FPM → Laravel
2. Laravel Controllers invoke Services → Repositories → MySQL
3. Laravel uses Redis for cache/session and pushes jobs to Redis queue
4. Queue Worker pulls from Redis, executes Listeners to send emails or update statuses
5. Vite container watches resource files, compiles assets, and delivers hot-reload to Browser