# conovatec/observatorio-back architecture

> Architecture diagram of the GitHub repository conovatec/observatorio-back, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/conovatec/observatorio-back
- Repository: https://github.com/conovatec/observatorio-back

## Overview

##### Project Type & Purpose
- This is a monolithic, full-stack Laravel application exposing
- A server-rendered admin/UI layer (Blade + Livewire + Tailwind CSS + Alpine.js)
- A versioned JSON REST API (routes under /api/v1)
- Core features: CRUD on multiple domain entities (posts, categories, youth policies, etc.), user authentication/authorization (Laravel Fortify, Jetstream, Sanctum), pagination, filtering, sorting.

##### File Structure & Architectural Patterns
- MVC layers in app/: Models (Eloquent), Controllers (app/Http/Controllers), Views/Livewire components (resources/views + app/Http/Livewire).
- API layer under app/Http/Controllers/Api/V1 + Resources in app/Http/Resources/Api/V1.
- Request validation in app/Http/Requests/admin, custom Actions in app/Actions (Fortify & Jetstream hooks).
- Service providers (app/Providers) bootstrap framework features (Auth, Fortify, Jetstream).
- Database migrations/factories/seeders under database/.
- Docker+docker-compose for containerized PHP-FPM, webserver, DB.

##### Key Components
a. Clients & Interfaces (Presentation Layer)
- Browser/Admin User → Web UI (Blade + Livewire + Alpine.js)
- External Consumer (e.g., mobile app, Postman) → JSON REST API
b. Web & App Servers (Application Layer)
- Nginx/Apache container (docker)
- PHP-FPM container hosting Laravel
- Laravel middleware stack (routing, authentication, localization, CSRF)
- Controller + Livewire component handlers
- Fortify/Sanctum auth services
c. Data & Integrations (Data Layer)
- Primary database (MySQL/PostgreSQL)
- Filesystem storage for uploads (public/storage)
- Optional cache/queue (Redis, if configured)
- External SMTP/mail service
d. Supporting Services
- Laravel’s queue worker (supervisord in Docker)
- Scheduler (cron via docker start-container script)

##### Relationships & Data Flows
- Web UI flow:
Browser —(HTTP)→ Nginx → Laravel Router → Controller / Livewire → Eloquent Model → Database
←– JSON or HTML response
- REST API flow:
API Client —(HTTP JSON)→ Nginx → Laravel Router (/api/v1) → API Controller → Resource Transformer → Model → Database
←– JSON response
- Authentication:
Login/Register endpoints (Fortify) → Issues Sanctum tokens / session cookies → Middleware guards follow-on requests
- Storage:
File uploads → Laravel Storage → local disk or cloud driver
- Queue/Scheduler:
Dispatch jobs from controllers/actions → Queue worker → Job handlers → possible events/notifications

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Presentation Layer"
        Browser["Browser/Admin User"]:::presentation
        External["API Client (e.g., Mobile, Postman)"]:::api
        WebUI["Web UI (Blade + Livewire + Alpine.js)"]:::presentation
        LivewireComp["Livewire Components"]:::presentation
        APIEndpoint["JSON REST API (/api/v1)"]:::api
    end

    subgraph "Core Application" 
        Middleware["HTTP Middleware Stack"]:::core
        Auth["Auth Services (Fortify, Sanctum, Jetstream)"]:::core
        ControllersAdmin["Admin Controllers"]:::core
        APIControllers["API Controllers"]:::core
        ResourceTrans["API Resource Transformers"]:::core
        Eloquent["Eloquent Models"]:::core
    end

    subgraph "Infrastructure"
        Nginx["Nginx/Apache (docker)"]:::infra
        PHPFPM["PHP-FPM (docker)"]:::infra
        Queue["Queue Worker (supervisord)"]:::infra
        Scheduler["Scheduler (cron)"]:::infra
    end

    subgraph "Data & External Services"
        Database(("Database\n(MySQL/PostgreSQL)")):::data
        Storage(("Filesystem Storage\n(public/storage)")):::data
        Cache(("Cache/Queue (Redis)")):::data
        Mail(("SMTP/Mail Service")):::data
    end

    %% Presentation to Core
    Browser -->|"HTTP GET/POST"| WebUI
    WebUI -->|"AJAX/WebSocket"| LivewireComp
    LivewireComp --> Nginx
    External -->|"HTTP JSON"| APIEndpoint
    APIEndpoint --> Nginx

    %% Infra to Core
    Nginx --> PHPFPM
    PHPFPM --> Middleware
    Middleware --> Auth
    Auth --> ControllersAdmin
    Auth --> APIControllers

    %% Controllers flows
    ControllersAdmin -->|"calls"| Eloquent
    APIControllers -->|"calls"| ResourceTrans
    ResourceTrans -->|"transforms & calls"| Eloquent

    %% Data layer interactions
    Eloquent --> Database
    ControllersAdmin -->|"dispatch"| Queue
    Queue --> ControllersAdmin
    Scheduler -->|"triggers jobs in"| ControllersAdmin
    ControllersAdmin --> Storage
    ControllersAdmin --> Mail
    ControllersAdmin --> Cache

    %% API response back
    APIControllers -->|"JSON response"| APIEndpoint
    APIEndpoint --> External

    %% UI response back
    ControllersAdmin -->|"HTML/JSON response"| Nginx
    Nginx --> WebUI
    WebUI --> Browser

    %% Click Events
    click WebUI "https://github.com/conovatec/observatorio-back/tree/master/resources/views/admin"
    click LivewireComp "https://github.com/conovatec/observatorio-back/tree/master/app/Http/Livewire/Admin"
    click APIControllers "https://github.com/conovatec/observatorio-back/tree/master/app/Http/Controllers/Api/V1"
    click ResourceTrans "https://github.com/conovatec/observatorio-back/tree/master/app/Http/Resources/Api/V1"
    click APIEndpoint "https://github.com/conovatec/observatorio-back/blob/master/routes/api-v1.php"
    click ControllersAdmin "https://github.com/conovatec/observatorio-back/tree/master/app/Http/Controllers/admin"
    click Middleware "https://github.com/conovatec/observatorio-back/tree/master/app/Http/Middleware"
    click Eloquent "https://github.com/conovatec/observatorio-back/tree/master/app/Models/admin"
    click Eloquent "https://github.com/conovatec/observatorio-back/blob/master/app/Models/User.php"
    click Auth "https://github.com/conovatec/observatorio-back/tree/master/app/Actions/Fortify"
    click Auth "https://github.com/conovatec/observatorio-back/tree/master/app/Actions/Jetstream"
    click Auth "https://github.com/conovatec/observatorio-back/blob/master/app/Providers/FortifyServiceProvider.php"
    click Auth "https://github.com/conovatec/observatorio-back/blob/master/app/Providers/JetstreamServiceProvider.php"
    click Auth "https://github.com/conovatec/observatorio-back/blob/master/config/sanctum.php"
    click Auth "https://github.com/conovatec/observatorio-back/blob/master/config/fortify.php"
    click Nginx "https://github.com/conovatec/observatorio-back/blob/master/docker-compose.yml"
    click Queue "https://github.com/conovatec/observatorio-back/blob/master/docker/7.4/supervisord.conf"
    click Scheduler "https://github.com/conovatec/observatorio-back/tree/master/docker/7.4/start-container"
    click Storage "https://github.com/conovatec/observatorio-back/tree/master/storage/app/public"
    click Mail "https://github.com/conovatec/observatorio-back/blob/master/config/mail.php"

    %% Styles
    classDef presentation fill:#2196f3,stroke:#000,color:#fff;
    classDef api fill:#4caf50,stroke:#000,color:#fff;
    classDef core fill:#ff9800,stroke:#000,color:#fff;
    classDef infra fill:#9e9e9e,stroke:#000,color:#fff;
    classDef data fill:#ffeb3b,stroke:#000,color:#000;
```
