# sergiovegam41/lego architecture

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

- Interactive diagram: https://gitdiagram.com/sergiovegam41/lego
- Repository: https://github.com/sergiovegam41/lego

## Overview

##### Project type and purpose
- This is a full-stack, component-based PHP web framework (“Lego Framework”) packaged as a modular application.
- Purpose: Enable developers to build reusable, self-contained UI components (PHP+CSS+JS) and assemble them into web apps, with built-in routing, auth, database, caching, and asset management.

##### High-level file-structure analysis
- Top-level “public/index.php”: HTTP entrypoint served by Nginx + PHP-FPM.
- Core/: Framework engine – bootstrap, routing discovery, controller base classes, DTOs, response, service abstractions.
- App/: Consumer’s application code – Controllers (Auth, API), Models, Utilities (Redis client).
- Views/: Component library – organized under Core/ (framework UI pieces) and App/ (application-specific components), each folder with .php, .css, .js.
- Routes/: API, Web, Views routing definitions.
- database/: Migration & seed scripts (PostgreSQL), plus migrations.json.
- Dockerfile & docker-compose.yml: Container definitions for PHP, Postgres, MongoDB, Redis, PgAdmin.
- assets/ & public/: Static assets (CSS/JS/images) served directly.

##### Core architectural patterns
- Component-based MVC/MVP hybrid: Controllers handle HTTP ➔ call Services/Models ➔ return data to Views (Components).
- Convention-over-configuration: auto-discovery of routes & components via folder structure and attributes.
- Layered services: Core services (routing, auth), App services (business logic), Utils (Redis), Data access (Models), and templated components (Views).
- Micro-frontend feel: each UI component is self-contained.

##### Main components & relationships
a. Client Layer
- Browser (HTML/CSS/JS) requests to Nginx (or Docker-NGINX).
b. Web Server & Runtime
- Nginx → PHP-FPM → public/index.php → Core/bootstrap
c. Routing Layer
- Core/Services/ApiRouteDiscovery reads Routes/*.php → dispatch to App/Controllers or Core/Controller
d. Controller Layer
- Controllers (App/Controllers/Auth, other controllers) orchestrate requests: validate via DTOs, call Services/Core/AuthServicesCore, Util/RedisClient.
e. Service/Model Layer
- Core models (ResponseDTO, StatusCodes), App models (User, UserSession), database access.
- Database adapters: PostgreSQL (primary), MongoDB (if used), Redis (session/cache).
f. View Component Layer
- Components under Views/Core and Views/App render HTML + include CSS/JS.
- Assets served from /assets or public directory.
g. External Services
- PostgreSQL container, MongoDB container, Redis container, PgAdmin for management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser (HTML/CSS/JS)"]:::client
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Nginx["Nginx / Docker-NGINX"]:::infra
        PHPFPM["PHP 8.1 (FPM)"]:::infra
        Index["public/index.php"]:::infra
    end

    %% Framework Bootstrap & Routing
    subgraph "Framework Bootstrap & Routing"
        Bootstrap["Core/bootstrap.php"]:::infra
        RouteDiscovery["ApiRouteDiscovery Service"]:::infra
        WebRoutes["Routes/Web.php"]:::infra
        ApiRoutes["Routes/Api.php"]:::infra
        ViewRoutes["Routes/Views.php"]:::infra
    end

    %% Controller Layer
    subgraph "Controller Layer"
        CoreController["CoreController Base"]:::app
        CoreViewController["CoreViewController Base"]:::app
        AuthController["AuthGroupsController"]:::app
    end

    %% Service & Model Layer
    subgraph "Service & Model Layer"
        AuthService["AuthServicesCore"]:::app
        RedisClient["RedisClient"]:::app
        UserModel["User Model"]:::app
        UserSessionModel["UserSession Model"]:::app
        ResponseDTO["ResponseDTO"]:::app
        StatusCodes["StatusCodes"]:::app
        ScriptDTO["ScriptCoreDTO"]:::app
        Helpers["LegoHelpers & Providers"]:::app
    end

    %% View Component Layer
    subgraph "View Component Layer"
        CoreComponent["CoreComponent"]:::ui
        CoreModule["CoreModuleComponent"]:::ui
        AutomationComp["AutomationComponent"]:::ui
        HomeComp["HomeComponent"]:::ui
        HeaderComp["HeaderComponent"]:::ui
        MainComp["MainComponent"]:::ui
        MenuComp["MenuComponent"]:::ui
        MenuItemComp["MenuItemComponent"]:::ui
        LoginComp["LoginComponent"]:::ui
        SharedAssets["select.css"]:::ui
        StaticAssets["assets/css, js, images"]:::ui
    end

    %% Data Stores
    subgraph "Data Stores"
        Postgres["PostgreSQL 13"]:::data
        MongoDB["MongoDB"]:::data
        RedisStore["Redis 6"]:::data
    end

    %% Connections
    Browser --> Nginx
    Nginx --> PHPFPM
    PHPFPM --> Index
    Index --> Bootstrap
    Bootstrap --> RouteDiscovery

    RouteDiscovery --> WebRoutes
    RouteDiscovery --> ApiRoutes
    RouteDiscovery --> ViewRoutes

    ViewRoutes --> CoreViewController
    WebRoutes --> CoreController
    ApiRoutes --> CoreController
    Index --> CoreController

    CoreController --> AuthController
    AuthController --> AuthService
    AuthController --> RedisClient
    AuthController --> ResponseDTO
    AuthController --> StatusCodes
    AuthController --> ScriptDTO
    AuthController --> Helpers
    AuthController --> RedisStore
    AuthController --> MongoDB

    AuthService --> UserModel
    AuthService --> UserSessionModel
    UserModel --> Postgres
    UserSessionModel --> Postgres

    CoreViewController --> CoreComponent
    CoreViewController --> CoreModule
    CoreComponent --> AutomationComp
    CoreComponent --> HomeComp
    HomeComp --> HeaderComp
    HomeComp --> MainComp
    HomeComp --> MenuComp
    MenuComp --> MenuItemComp
    CoreViewController --> LoginComp

    AutomationComp --> StaticAssets
    HomeComp --> StaticAssets
    HeaderComp --> StaticAssets
    MainComp --> StaticAssets
    MenuComp --> StaticAssets
    MenuItemComp --> StaticAssets
    LoginComp --> StaticAssets
    SharedAssets --> HomeComp

    %% Click Events
    click Index "https://github.com/sergiovegam41/lego/blob/main/public/index.php"
    click Bootstrap "https://github.com/sergiovegam41/lego/blob/main/Core/bootstrap.php"
    click RouteDiscovery "https://github.com/sergiovegam41/lego/blob/main/Core/Services/ApiRouteDiscovery.php"
    click WebRoutes "https://github.com/sergiovegam41/lego/blob/main/Routes/Web.php"
    click ApiRoutes "https://github.com/sergiovegam41/lego/blob/main/Routes/Api.php"
    click ViewRoutes "https://github.com/sergiovegam41/lego/blob/main/Routes/Views.php"
    click CoreController "https://github.com/sergiovegam41/lego/blob/main/Core/Controller/CoreController.php"
    click CoreViewController "https://github.com/sergiovegam41/lego/blob/main/Core/Controller/CoreViewController.php"
    click AuthController "https://github.com/sergiovegam41/lego/blob/main/App/Controllers/Auth/Controllers/AuthGroupsController.php"
    click AuthService "https://github.com/sergiovegam41/lego/blob/main/Core/Services/AuthServicesCore.php"
    click UserModel "https://github.com/sergiovegam41/lego/blob/main/App/Models/User.php"
    click UserSessionModel "https://github.com/sergiovegam41/lego/blob/main/App/Models/UserSession.php"
    click ResponseDTO "https://github.com/sergiovegam41/lego/blob/main/Core/Models/ResponseDTO.php"
    click StatusCodes "https://github.com/sergiovegam41/lego/blob/main/Core/Models/StatusCodes.php"
    click ScriptDTO "https://github.com/sergiovegam41/lego/blob/main/Core/Dtos/ScriptCoreDTO.php"
    click RedisClient "https://github.com/sergiovegam41/lego/blob/main/App/Utils/RedisClient.php"
    click CoreComponent "https://github.com/sergiovegam41/lego/blob/main/Core/Components/CoreComponent/CoreComponent.php"
    click CoreModule "https://github.com/sergiovegam41/lego/blob/main/Core/Components/CoreComponent/CoreModuleComponent.php"
    click AutomationComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Automation/AutomationComponent.php"
    click HomeComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Home/HomeComponent.php"
    click HeaderComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Home/Components/HeaderComponent/HeaderComponent.php"
    click MainComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Home/Components/MainComponent/MainComponent.php"
    click MenuComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Home/Components/MenuComponent/MenuComponent.php"
    click MenuItemComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Home/Components/MenuComponent/features/MenuItemComponent/MenuItemComponent.php"
    click LoginComp "https://github.com/sergiovegam41/lego/blob/main/Views/Core/Login/LoginComponent.php"
    click SharedAssets "https://github.com/sergiovegam41/lego/blob/main/Views/shared/butons/select.css"
    click StaticAssets "https://github.com/sergiovegam41/lego/tree/main/assets/css"
    click StaticAssets "https://github.com/sergiovegam41/lego/tree/main/assets/js"
    click StaticAssets "https://github.com/sergiovegam41/lego/tree/main/assets/images"

    %% Styles
    classDef infra fill:#cce5ff,stroke:#004085
    classDef client fill:#e2e3e5,stroke:#6c757d
    classDef app fill:#d4edda,stroke:#155724
    classDef ui fill:#fff3cd,stroke:#856404
    classDef data fill:#e2e3e5,stroke:#6c757d
```
