# lperamo/otra architecture

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

- Interactive diagram: https://gitdiagram.com/lperamo/otra
- Repository: https://github.com/lperamo/otra

## Overview

##### Main Components
- Web Layer:
– Controllers (found in src/controllers and specifically error and profiler controllers)
– Routing mechanisms (src/Router.php and related console routing tasks)
– View/Template Engine (src/views and src/templating)
- Core Framework Classes:
– Base Controller (src/Controller.php, src/MasterController.php)
– Core Models (src/Model.php, src/OtraException.php)
– Session management (src/Session.php)
– Logger (src/Logger.php)
- Database Abstraction:
– Database connection and abstraction classes from src/bdd (Pdomysql.php, Sql.php)
- Console/CLI Subsystem:
– Extensive set of CLI tools in src/console (including tasks for creating actions, bundles, models, modules, deployments, database operations, etc.)
- Utilities and Tools:
– Various helper scripts and tools for file operations, debugging, and code formatting (in src/tools and related directories)
- Configuration & Deployment:
– Configuration files in src/init and doc/configuration
– Deployment scripts (src/console/deployment with tasks like clearCache, deploy, genAssets, etc.)
- External Dependencies/Libraries:
– Symfony YAML component and Google Closure Compiler (noted in README) which feed into configuration parsing and asset optimization respectively.

##### Relationships and Interactions
- Web Requests Flow:
– Client requests are directed to the front controller (src/init/web/index.php) which uses the Router (src/Router.php) to forward the request to the appropriate Controller.
– Controllers interact with Models (src/Model.php) and use Views (src/views) to generate responses.
- CLI/Console Flow:
– The bin/otra.php script or the various console entry-points in src/console launch tasks that automate code generation (creating models, bundles, controllers, etc.), manage deployments, or handle database operations.
– These CLI tasks are broken down further into various “architecture” submodules (as seen in src/console/architecture) which follow a modular design.
- Database Interaction:
– The framework wraps database access via classes in src/bdd, ensuring that requests from controllers or console tasks interact with the database through a unified interface.
- Templating and Assets:
– Templating components (e.g., src/templating/HtmlMinifier.php) and asset-related deployment tasks indicate that there’s a processing chain transforming source code, CSS/JS assets, and views before rendering them.
- External Integrations:
– Usage of Symfony YAML for configuration management.
– Google Closure Compiler for optimizing JavaScript assets in the deployment pipeline.

##### Architectural Patterns
- MVC Pattern:
– Present a clear separation between Models, Views, and Controllers.
- Layered Architecture:
– Separate layers for presentation (controllers/views), business logic (services and database management), and tooling (CLI/console tasks).
- Modular/Task-Based Design:
– The architecture of CLI tools is modular: separate tasks for creation, deployment, and database management indicate that each function is encapsulated in its own set of scripts and helper classes.
- Extensibility and Reusability:
– The extensive use of configuration files and CLI code generation tasks highlights the design’s goal to be flexible and easily scalable.

##### Relevant Technologies and Libraries
- PHP as the main runtime language
- Composer (composer.json/lock) for dependency management
- Symfony YAML component for configuration parsing
- Google Closure Compiler for JavaScript optimization
- PHPUnit (as seen in tests with phpunit*.xml files) for testing various components

##### General Advice
- Don’t try to include every single file; focus on high-level components and group related scripts into broader modules (e.g., group all “architecture” console tasks together).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Web Layer Subgraph
    subgraph "Web Layer"
        direction TB
        WC["HTTP Request (Client)"]:::external
        R["Router"]:::component
        WCtl["Web Controllers"]:::component
        BC["Base Controller"]:::component
        MC["Master Controller"]:::component
        M["Model"]:::component
        OE["OtraException"]:::component
        V["Views"]:::component
        TE["Templating Engine"]:::component
        S["Session Management"]:::component
        L["Logger"]:::component
        DBA["Database Abstraction"]:::component
        PD["Pdomysql"]:::db
        SQ["Sql"]:::db
    end

    %% Console/CLI Subsystem Subgraph
    subgraph "Console/CLI Subsystem"
        direction TB
        CLI["CLI Tools"]:::tool
        DPL["Deployment Scripts"]:::tool
        CFG["Configuration Files"]:::tool
        CDOC["Configuration Documentation"]:::note
        TL["Utilities and Tools"]:::tool
    end

    %% External Dependencies Subgraph
    subgraph "External Dependencies"
        direction TB
        SY["Symfony YAML"]:::externalDep
        GCC["Google Closure Compiler"]:::externalDep
        CMP["Composer"]:::externalDep
    end

    %% Web Layer Connections
    WC -->|"HTTPrequest"| R
    R -->|"dispatches"| WCtl
    WCtl -->|"extends"| BC
    WCtl -->|"extends"| MC
    WCtl -->|"calls"| M
    M -->|"handles"| OE
    WCtl -->|"renders"| V
    V -->|"processedby"| TE
    WCtl -->|"manages"| S
    WCtl -->|"logs"| L
    M -->|"DBquery"| DBA
    DBA --> PD
    DBA --> SQ

    %% CLI Subsystem Connections
    CLI -->|"executes"| DPL
    CLI -->|"reads"| CFG
    CLI -->|"utilizes"| TL
    CFG --> CDOC

    %% External Dependencies Connections
    CFG -.->|"parses"| SY
    DPL -.->|"optimizesWith"| GCC
    R ---|"dependency"| CMP
    CLI ---|"dependency"| CMP

    %% Click Events - Web Layer
    click WCtl "https://github.com/lperamo/otra/tree/master/src/controllers"
    click R "https://github.com/lperamo/otra/blob/master/src/Router.php"
    click TE "https://github.com/lperamo/otra/tree/master/src/templating"
    click V "https://github.com/lperamo/otra/tree/master/src/views"
    click BC "https://github.com/lperamo/otra/blob/master/src/Controller.php"
    click MC "https://github.com/lperamo/otra/blob/master/src/MasterController.php"
    click M "https://github.com/lperamo/otra/blob/master/src/Model.php"
    click OE "https://github.com/lperamo/otra/blob/master/src/OtraException.php"
    click S "https://github.com/lperamo/otra/blob/master/src/Session.php"
    click L "https://github.com/lperamo/otra/blob/master/src/Logger.php"
    click PD "https://github.com/lperamo/otra/blob/master/src/bdd/Pdomysql.php"
    click SQ "https://github.com/lperamo/otra/blob/master/src/bdd/Sql.php"

    %% Click Events - Console/CLI Subsystem
    click CLI "https://github.com/lperamo/otra/tree/master/src/console"
    click TL "https://github.com/lperamo/otra/tree/master/src/tools"
    click CFG "https://github.com/lperamo/otra/tree/master/src/init/config"
    click CDOC "https://github.com/lperamo/otra/tree/master/doc/configuration"
    click DPL "https://github.com/lperamo/otra/tree/master/src/console/deployment"

    %% Classes
    classDef external fill:#FDEDEC,stroke:#E74C3C,stroke-width:2px;
    classDef component fill:#EBF5FB,stroke:#3498DB,stroke-width:2px;
    classDef tool fill:#E8F8F5,stroke:#1ABC9C,stroke-width:2px;
    classDef db fill:#FDF2E9,stroke:#F39C12,stroke-width:2px;
    classDef externalDep fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef note fill:#F2F3F4,stroke:#95A5A6,stroke-width:2px;
```
