# ifha/curso-laravel-10 architecture

> Architecture diagram of the GitHub repository ifha/curso-laravel-10, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ifha/curso-laravel-10
- Repository: https://github.com/ifha/curso-laravel-10

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Browser["Web Browser"]:::external
    Mobile["Mobile/3rd-party App"]:::external
    SMTP["SMTP/Email Provider"]:::external

    %% Docker Containers Cluster
    subgraph "Docker Services"
        direction TB
        Compose["Docker Compose"]:::container
        Nginx["Nginx\nReverse Proxy"]:::container
        PHPFPM["PHP-FPM\nLaravel App"]:::container
        Vite["Vite\nAsset Compiler"]:::container
        MySQL["MySQL\nDatabase"]:::datastore
        Redis["Redis\nCache/Session/Queue"]:::datastore
        Worker["Queue Worker\nContainer"]:::container
    end

    %% Laravel Internals
    subgraph "Laravel Application Internals"
        direction TB
        subgraph "HTTP Routing Layer"
            WebRoutes["routes/web.php"]:::layer
            ApiRoutes["routes/api.php"]:::layer
        end
        subgraph "Controllers"
            direction TB
            AdminSupportCtrl["Admin/SupportController"]:::layer
            AdminReplyCtrl["Admin/ReplySupportController"]:::layer
            ApiSupportCtrl["API/SupportController"]:::layer
            ApiReplyCtrl["API/ReplySupportApiController"]:::layer
            AuthCtrl["API/AuthController"]:::layer
        end
        subgraph "Business Logic"
            direction TB
            SupportService["SupportService"]:::layer
            ReplyService["ReplySupportService"]:::layer
            subgraph "Repository Layer"
                SupportRepo["SupportEloquentORMRepository"]:::layer
                ReplyRepo["ReplySupportEloquentORMRepository"]:::layer
            end
            subgraph "Contracts"
                SupportContract["SupportRepository"]:::layer
                ReplyContract["ReplySupportRepository"]:::layer
            end
        end
        subgraph "Validation & DTOs"
            direction TB
            CreateSupportReq["StoreUpdateSupportRequest"]:::layer
            CreateReplyReq["StoreReplySupportRequest"]:::layer
            CreateSupportDTO["CreateSupportDTO"]:::layer
            UpdateSupportDTO["UpdateSupportDTO"]:::layer
            CreateReplyDTO["CreateReplyDTO"]:::layer
        end
        subgraph "Events & Listeners"
            SupportRepliedEvt["SupportReplied Event"]:::async
            SendMailListener["SendMailWhenSupportReplied"]:::async
            UpdateStatusListener["UpdateStatusWhenSupportReplied"]:::async
        end
        Mail["SupportRepliedMail"]:::async
    end

    %% HTTP / Asset Flow
    Browser -->|HTTP| Nginx
    Nginx -->|FastCGI| PHPFPM
    PHPFPM --> WebRoutes
    PHPFPM --> ApiRoutes
    Browser -->|HTTPS| Vite
    Vite -->|Hot-Reload| Browser

    %% Controller to Service
    WebRoutes --> AdminSupportCtrl
    WebRoutes --> AdminReplyCtrl
    ApiRoutes --> ApiSupportCtrl
    ApiRoutes --> ApiReplyCtrl
    ApiRoutes --> AuthCtrl

    AdminSupportCtrl --> SupportService
    AdminReplyCtrl --> ReplyService
    ApiSupportCtrl --> SupportService
    ApiReplyCtrl --> ReplyService
    AuthCtrl --> SupportService

    %% Service to Repository
    SupportService --> SupportContract
    SupportService --> SupportRepo
    ReplyService --> ReplyContract
    ReplyService --> ReplyRepo

    %% Validation and DTO
    AdminSupportCtrl --> CreateSupportReq
    AdminSupportCtrl --> CreateSupportDTO
    AdminReplyCtrl --> CreateReplyReq
    AdminReplyCtrl --> CreateReplyDTO
    ApiSupportCtrl --> CreateSupportDTO
    ApiSupportCtrl --> UpdateSupportDTO
    ApiReplyCtrl --> CreateReplyDTO

    %% Data Layer
    SupportRepo --> MySQL
    ReplyRepo --> MySQL
    PHPFPM -->|Cache/Session| Redis
    PHPFPM -->|Queue Push| Redis

    %% Event Flow
    ReplyService --> SupportRepliedEvt
    SupportRepliedEvt --> SendMailListener
    SupportRepliedEvt --> UpdateStatusListener
    SendMailListener -->|Email Job| Redis
    UpdateStatusListener -->|Status Job| Redis

    %% Worker Processing
    Worker -->|Pull Jobs| Redis
    Worker --> SendMailListener
    Worker --> UpdateStatusListener
    Worker --> Mail
    Mail --> SMTP

    %% Click Events
    click Compose "https://github.com/ifha/curso-laravel-10/blob/main/docker-compose.yml"
    click Nginx "https://github.com/ifha/curso-laravel-10/blob/main/docker/nginx/laravel.conf"
    click PHPFPM "https://github.com/ifha/curso-laravel-10/tree/main/Dockerfile"
    click PHPFPM "https://github.com/ifha/curso-laravel-10/tree/main/app/"
    click PHPFPM "https://github.com/ifha/curso-laravel-10/blob/main/bootstrap/app.php"
    click PHPFPM "https://github.com/ifha/curso-laravel-10/blob/main/public/index.php"
    click Vite "https://github.com/ifha/curso-laravel-10/blob/main/vite.config.js"
    click Vite "https://github.com/ifha/curso-laravel-10/blob/main/resources/js/app.js"
    click Vite "https://github.com/ifha/curso-laravel-10/blob/main/resources/css/app.css"
    click WebRoutes "https://github.com/ifha/curso-laravel-10/blob/main/routes/web.php"
    click ApiRoutes "https://github.com/ifha/curso-laravel-10/blob/main/routes/api.php"
    click AdminSupportCtrl "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Controllers/Admin/SupportController.php"
    click AdminReplyCtrl "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Controllers/Admin/ReplySupportController.php"
    click ApiSupportCtrl "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Controllers/Api/SupportController.php"
    click ApiReplyCtrl "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Controllers/Api/ReplySupportApiController.php"
    click AuthCtrl "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Controllers/Api/Auth/AuthController.php"
    click SupportService "https://github.com/ifha/curso-laravel-10/blob/main/app/Services/SupportService.php"
    click ReplyService "https://github.com/ifha/curso-laravel-10/blob/main/app/Services/ReplySupportService.php"
    click SupportContract "https://github.com/ifha/curso-laravel-10/blob/main/app/Repositories/Contracts/SupportRepository.php"
    click ReplyContract "https://github.com/ifha/curso-laravel-10/blob/main/app/Repositories/Contracts/ReplySupportRepository.php"
    click SupportRepo "https://github.com/ifha/curso-laravel-10/blob/main/app/Repositories/Contracts/Eloquent/SupportEloquentORMRepository.php"
    click ReplyRepo "https://github.com/ifha/curso-laravel-10/blob/main/app/Repositories/Contracts/Eloquent/ReplySupportEloquentORMRepository.php"
    click CreateSupportDTO "https://github.com/ifha/curso-laravel-10/blob/main/app/DTO/Supports/CreateSupportDTO.php"
    click UpdateSupportDTO "https://github.com/ifha/curso-laravel-10/blob/main/app/DTO/Supports/UpdateSupportDTO.php"
    click CreateReplyDTO "https://github.com/ifha/curso-laravel-10/blob/main/app/DTO/Supports/Replies/CreateReplyDTO.php"
    click CreateSupportReq "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Requests/StoreUpdateSupportRequest.php"
    click CreateReplyReq "https://github.com/ifha/curso-laravel-10/blob/main/app/Http/Requests/StoreReplySupportRequest.php"
    click SupportRepliedEvt "https://github.com/ifha/curso-laravel-10/blob/main/app/Events/SupportReplied.php"
    click SendMailListener "https://github.com/ifha/curso-laravel-10/blob/main/app/Listeners/SendMailWhenSupportReplied.php"
    click UpdateStatusListener "https://github.com/ifha/curso-laravel-10/blob/main/app/Listeners/UpdateStatusWhenSupportReplied.php"
    click Mail "https://github.com/ifha/curso-laravel-10/blob/main/app/Mail/SupportRepliedMail.php"

    %% Styles
    classDef container fill:#D5E8D4,stroke:#82B366;
    classDef datastore fill:#FFF2CC,stroke:#D6B656;
    classDef external fill:#DAE8FC,stroke:#6C8EBF;
    classDef layer fill:#F8CECC,stroke:#B85450;
    classDef async fill:#E1D5E7,stroke:#9673A6;
```
