# juanhdezz/tfg_gestion_ccia architecture

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

- Interactive diagram: https://gitdiagram.com/juanhdezz/tfg_gestion_ccia
- Repository: https://github.com/juanhdezz/tfg_gestion_ccia

## Overview

##### Main Components
- Web Client: Represents the user’s browser and the client-side interactions. The frontend is served via Blade templates (located in resources/views) and assets managed by Vite (see package.json, vite.config.js, resources/js/app.js, etc.).
- Web Server: The Apache server provided by XAMPP handles HTTP requests. This is the entry point for users (as per the README, they point their browser to the public folder).
- Laravel Application: The core of the system includes:
- Controllers (app/Http/Controllers) which process incoming requests, handle authentication (see the Auth controllers), manage resources (asignaturas, tutoria, usuarios, etc.), and return responses.
- Models (app/Models) that represent the application’s data structures and interact with the database.
- Middleware (app/Http/Middleware) handling aspects such as authorization and database switching.
- Routes (routes/web.php and routes/auth.php) which define URL endpoints and their corresponding controllers.
- Views (resources/views) for rendering UI.
- Database: The application interacts with a MySQL database (as instructed via phpMyAdmin in the README). The schema is maintained by migrations (database/migrations), and there are seeders to set up roles and permissions.

##### Understand the Flow and Interactions
- When a user accesses the application from their browser, the HTTP request is received by the Apache web server.
- The request is then routed to the Laravel application where:
- The routes (defined in the routes folder) determine which controller to invoke.
- The controllers process the request, often utilizing Models to fetch or update data.
- Middlewares (such as EnsureUserIsAdmin and DatabaseSwitcher) inspect and modify the requests/responses.
- Blade views in resources/views are returned as the response rendered for the user.
- Frontend assets (JavaScript, CSS) are built with Vite and served from the public/build folder.
- Data persistence is managed with a MySQL database, with schema managed via migrations and initial data loaded using seeders.

##### Architectural Patterns and Key Technologies
- MVC Pattern: The Laravel structure strongly adheres to the Model-View-Controller pattern.
- Service Providers: Custom providers (e.g., AppServiceProvider) wire up application services.
- Middleware: For cross-cutting concerns like authentication and request modification.
- Bundling: Vite for frontend asset compilation.
- Testing: Integration and unit tests (present in tests/Feature and tests/Unit) employ tools like PHPUnit and Pest.
- External Dependencies: Composer for PHP package management and Node.js/npm for JavaScript dependencies.
- Database Management: Migrations and seeders (also exporting capabilities seen in app/Exports).

##### Detailed Elements
- Each component should be labeled:
- “Client Browser (HTML/CSS/JS via Blade Templates)”
- “Web Server (Apache via XAMPP)”
- “Laravel Application” (then break down into sub-components):
- “Controllers” (with examples: AsignaturaController, Auth controllers, etc.)
- “Models” (e.g., Asignatura, User, etc.)
- “Middleware” (e.g., EnsureUserIsAdmin, DatabaseSwitcher)
- “Routes” (web.php, auth.php)
- “Views” (Blade templates for auth, dashboard, etc.)
- “Database (MySQL)” for data persistence.
- “Asset Management (Vite, Node.js)” for compiling and serving frontend assets.
- Request and Response flows between Client, Web Server, and Laravel Application.
- Internal interactions between Controllers and Models.
- Middleware intercepting requests.
- Bidirectional data flow between Laravel Application and Database.

- Optionally, include ancillary components like testing, Composer-based dependency management, and asset pipelines that ensure comprehensive coverage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        CBrowser["Client Browser (HTML/CSS/JS via Blade Templates)"]:::frontend
        Blade["Blade Templates"]:::frontend
        Assets["Frontend Assets"]:::frontend
    end

    %% Web Server
    WebServer["Apache Web Server"]:::server

    %% Laravel Application
    subgraph "Laravel Application"
        Routes["Routes"]:::laravel
        Middleware["Middleware"]:::laravel
        Controllers["Controllers"]:::laravel
        Models["Models"]:::laravel
        LaravelViews["Blade Views"]:::laravel
    end

    %% Database (MySQL)
    subgraph "Database (MySQL)"
        Migrations["Migrations"]:::database
        Seeders["Seeders (Roles&Permissions)"]:::database
    end

    %% Asset Management (Vite & Node.js)
    subgraph "Asset Management (Vite & Node.js)"
        ViteConfig["Vite Config"]:::asset
        JSApp["JS App"]:::asset
        JSBootstrap["JS Bootstrap"]:::asset
        PackageDeps["Package Dependencies"]:::asset
    end

    %% External Tools
    ExternalTools["External Tools (Composer&Node.js)"]:::external

    %% Connections
    CBrowser -->|"HTTP_Request"| WebServer
    CBrowser -->|"Loads"| Blade
    WebServer -->|"Routes_to"| Routes
    Routes -->|"TriggerMiddleware"| Middleware
    Routes -->|"InvokeController"| Controllers
    Middleware -->|"ProceedTo"| Controllers
    Controllers -->|"CRUDOperations"| Models
    Controllers -->|"RenderUI"| LaravelViews
    Models -->|"DataQuery"| Migrations
    Models -->|"DataQuery"| Seeders
    LaravelViews -->|"RenderTemplate"| Blade

    %% Asset Management flows
    ViteConfig -->|"CompileAssets"| JSApp
    JSApp -->|"BuildAssets"| JSBootstrap
    JSApp -->|"DeliversAssets"| Assets
    JSBootstrap -->|"DeliversAssets"| Assets
    PackageDeps -->|"Manages"| ViteConfig

    %% External Tools support
    ExternalTools -->|"Supports"| LaravelViews
    ExternalTools -->|"Supports"| PackageDeps

    %% Connections from Web Server to Laravel Application are already depicted via Routes

    %% Click Events
    click Blade "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/resources/views"
    click Assets "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/resources/js"
    click WebServer "https://github.com/juanhdezz/tfg_gestion_ccia/blob/main/public/index.php"
    click Routes "https://github.com/juanhdezz/tfg_gestion_ccia/blob/main/routes/web.php"
    click Middleware "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/app/Http/Middleware"
    click Controllers "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/app/Http/Controllers"
    click Models "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/app/Models"
    click LaravelViews "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/resources/views"
    click Migrations "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/database/migrations"
    click Seeders "https://github.com/juanhdezz/tfg_gestion_ccia/tree/main/database/seeders"
    click ViteConfig "https://github.com/juanhdezz/tfg_gestion_ccia/blob/main/vite.config.js"
    click JSApp "https://github.com/juanhdezz/tfg_gestion_ccia/blob/main/resources/js/app.js"
    click JSBootstrap "https://github.com/juanhdezz/tfg_gestion_ccia/blob/main/resources/js/bootstrap.js"
    click PackageDeps "https://github.com/juanhdezz/tfg_gestion_ccia/blob/main/package.json"

    %% Styles
    classDef frontend fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef server fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef laravel fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef asset fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef external fill:#C39BD3,stroke:#333,stroke-width:2px;
```
