# alvaro-chambi/back architecture

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

- Interactive diagram: https://gitdiagram.com/alvaro-chambi/back
- Repository: https://github.com/alvaro-chambi/back

## Overview

##### Main Components
- HTTP/API Layer – Representing the public endpoints that interact with internal services. In the project, these are the controllers located under the “app/Http/Controllers” directory. Note that you have multiple subdirectories (e.g., API/Gen, API/Reports, API/Lookup, etc.) organized by domain or responsibility.
- Service/Business Logic Layer – Contains the core processes and rules. Check out the “app/Services” directory (e.g., CreateRaiApplicationService, ProcedureInspectionService) and the “app/StateMachines” directory that encapsulates distinct workflows like for IRAP and RAI. These describe the domain logic and workflows.
- Repository/Data Access Layer – This layer is abstracted in “app/Repositories” where the application’s repositories interface with the “app/Models” (and by extension, the database) to persist and retrieve data.
- External Services and Infrastructure – Include components like Passport (for API authentication), Laravel’s Task Scheduling, file storage (the “storage” directory and the public storage link), and third-party tools (Telescope, Swagger, Larastan, and IDE helper tools). Even though these may be initially configured outside the main application code, they play a critical role in authentication, debugging, and auxiliary operations.

##### Emphasized Architectural Patterns and Design Principles
- Layered Architecture: Make it explicit that there are clear separations between Controllers, Services (Business Logic), Repositories (Data Access), and the Database.
- Domain-Driven Design Elements: The existence of state machines and services (with “Ruleset” files and “State” classes) indicates a business process that adapts to state and workflow rules.
- Dependency Injection and Inter-module Communication: Note how Controllers invoke Services which, in turn, rely on Repositories, encouraging clear separations of concern.
- Extensibility: The heavy use of modular directories (e.g., separate folders for API, Domain, and Lookup functionalities) shows the system is designed for scalability and maintainability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Clients["Clients/Consumers"]:::infra
    Clients -->|"sends request"| HAP["HTTP API Gateway"]:::api

    %% HTTP/API Layer
    subgraph "HTTP/API Layer"
        HAP["HTTP API Gateway"]:::api
        CTR["Controllers"]:::api
        MW["Middleware (Auth&Security)"]:::infra
        HAP --> CTR
        CTR --> MW
    end

    %% Business/Service Layer
    subgraph "Business Logic Layer"
        SER["Services"]:::service
        SM["State Machines"]:::service
    end
    CTR -->|"invokes"| SER
    CTR -->|"triggers"| SM

    %% Repository/Data Access Layer
    subgraph "Repository/Data Access Layer"
        REP["Repositories"]:::data
        MOD["Models"]:::data
        SER -->|"calls"| REP
        SM -->|"utilizes"| REP
        REP -->|"manages"| MOD
    end

    %% Database Layer
    subgraph "Database Layer"
        MIG["Migrations (PostgreSQL16)"]:::data
        ERD["ERD Diagrams"]:::data
        MOD -->|"persists to"| MIG
        MIG -->|"documents"| ERD
    end

    %% Auxiliary Components
    FS["File Storage"]:::infra
    ST["Scheduled Tasks"]:::infra
    DEV["Developer Tools"]:::infra
    EMAIL["Email/Notification Service"]:::infra
    SER -->|"handles emails"| EMAIL
    SER -->|"stores files"| FS
    SER -->|"schedules"| ST

    %% Click Events
    click CTR "https://github.com/alvaro-chambi/back/tree/master/app/Http/Controllers"
    click SER "https://github.com/alvaro-chambi/back/tree/master/app/Services"
    click SM "https://github.com/alvaro-chambi/back/tree/master/app/StateMachines"
    click REP "https://github.com/alvaro-chambi/back/tree/master/app/Repositories"
    click MOD "https://github.com/alvaro-chambi/back/tree/master/app/Models"
    click MIG "https://github.com/alvaro-chambi/back/tree/master/database/migrations"
    click ERD "https://github.com/alvaro-chambi/back/tree/master/docs"
    click FS "https://github.com/alvaro-chambi/back/tree/master/storage"
    click MW "https://github.com/alvaro-chambi/back/tree/master/app/Http/Middleware"
    click ST "https://github.com/alvaro-chambi/back/blob/master/app/Console/Kernel.php"
    click DEV "https://github.com/alvaro-chambi/back/blob/master/config/telescope.php"
    click EMAIL "https://github.com/alvaro-chambi/back/tree/master/app/Mail"

    %% Styles
    classDef api fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef service fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef data fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef infra fill:#d3d3d3,stroke:#000,stroke-width:2px;
```
