# vgalvoso/phpeasy architecture

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

- Interactive diagram: https://gitdiagram.com/vgalvoso/phpeasy
- Repository: https://github.com/vgalvoso/phpeasy

## Overview

##### Project Type and Purpose
- PHPEasy is a lightweight, API-centric PHP “mini-framework” for building REST APIs and full-stack web apps with minimal abstraction.
- It uses file-based routing: files in the View folder map to URL routes; files in the api folder map to REST endpoints.

##### High-Level Components
- Client Layer
– Web Browser (renders Views + static assets)
– API Consumer (e.g., AJAX, Postman)
- Web Server Layer
– Apache/Nginx + .htaccess rewrite rules
– Front Controller (index.php)
- Framework Core
– Core/Config.php (configuration loader)
– Core/Database.php + Core/DAL.php (DB abstraction)
– Core/Helper.php (routing, session, response helpers)
– Core/Validator.php (input validation)
- Presentation Layer
– View/*.php (server-rendered pages)
– public/css/mystyle.css, public/js/vanscript.js (static assets)
- API Layer
– api/*.php (REST APIs implemented as get(), post(), patch(), delete(), etc.)
- Data Store
– MySQL / MSSQL / SQLite (configured in Core/Database.php)

##### Component Relationships and Data Flows
1. Client → Web Server: HTTP requests for pages, assets, or API endpoints
2. Web Server → Front Controller (index.php): for view routes
3. Front Controller → Core/Helper (to load appropriate View file) → Response → Client
4. Client AJAX/API Consumer → Web Server → api/*.php → Core/Helper\startAPI()
5. API Handler → Core/DAL → Database → Core/Helper\response() → Client
6. Static asset requests → Web Server → public/css, public/js directly served

##### Architectural Patterns & Design Principles
- File-Based Routing: routes derive directly from file structure under View/ and api/
- Procedural-Plus-Modular: minimal OOP (DAL class) combined with procedural functions for handlers
- Separation of Concerns:
– Presentation (View/)
– Business/API logic (api/)
– Core utilities (Core/)
– Static resources (public/)
- Lightweight DAL vs. full ORM for performance
- Composer for dependency/autoloading

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Clients"
        Browser["Web Browser"]:::external
        APIConsumer["API Consumer"]:::external
    end

    subgraph "Web Server & Routing"
        WebServer["Apache/Nginx"]:::server
        HTACCESS[".htaccess"]:::server
        Index["index.php"]:::server
    end

    subgraph "PHPEasy Framework"
        subgraph "Core Modules"
            Config["Core/Config.php"]:::core
            DatabaseCore["Core/Database.php"]:::core
            DAL["Core/DAL.php"]:::core
            Helper["Core/Helper.php"]:::core
            Validator["Core/Validator.php"]:::core
        end

        subgraph "Presentation Layer"
            HomeView["View/index.php"]:::presentation
            DashView["View/dashboard.php"]:::presentation
            LoginFailed["View/login/login_failed.php"]:::presentation
            NotFound["View/not_found.php"]:::presentation
        end

        subgraph "API Layer"
            APILogin["api/login.php"]:::presentation
            APIUsers["api/users.php"]:::presentation
        end

        subgraph "Static Assets"
            CSS["public/css/mystyle.css"]:::presentation
            JS["public/js/vanscript.js"]:::presentation
        end

        subgraph "Composer Autoload"
            ComposerJSON["composer.json"]:::server
            ComposerLock["composer.lock"]:::server
        end
    end

    DB["MySQL/SQLite"]:::database

    %% Client to Web Server
    Browser -->|"HTTPGET/View"| WebServer
    APIConsumer -->|"APIcall/REST"| WebServer

    %% Routing
    WebServer -->|rewrite| HTACCESS
    HTACCESS -->|route| Index

    %% View Flow
    Index -->|"loadRoute"| Helper
    Helper -->|"includeView"| HomeView
    Helper -->|"includeView"| DashView
    Helper -->|"includeView"| LoginFailed
    Helper -->|"includeView"| NotFound
    HomeView -->|"HTMLResponse"| Browser
    DashView -->|"HTMLResponse"| Browser
    LoginFailed -->|"HTMLResponse"| Browser
    NotFound -->|"HTMLResponse"| Browser

    %% Static Assets
    Browser -->|"GETCSS"| CSS
    Browser -->|"GETJS"| JS
    CSS -->|"serve"| Browser
    JS -->|"serve"| Browser

    %% API Flow
    APIConsumer -->|APIcall| APILogin
    APIConsumer -->|APIcall| APIUsers
    APILogin -->|"startAPI()"| Helper
    APIUsers -->|"startAPI()"| Helper
    Helper -->|"validateInput()"| Validator
    Validator -->|"validatedData"| DAL
    DAL -->|"buildQuery"| DatabaseCore
    DatabaseCore -->|"SQLquery"| DB
    DB -->|"resultset"| DatabaseCore
    DatabaseCore -->|"data"| DAL
    DAL -->|"responseData"| Helper
    Helper -->|"JSONResponse"| APILogin
    Helper -->|"JSONResponse"| APIUsers
    APILogin -->|"JSON"| APIConsumer
    APIUsers -->|"JSON"| APIConsumer

    %% Click events
    click Index "https://github.com/vgalvoso/phpeasy/blob/master/index.php"
    click HTACCESS "https://github.com/vgalvoso/phpeasy/blob/master/.htaccess"
    click Config "https://github.com/vgalvoso/phpeasy/blob/master/Core/Config.php"
    click DatabaseCore "https://github.com/vgalvoso/phpeasy/blob/master/Core/Database.php"
    click DAL "https://github.com/vgalvoso/phpeasy/blob/master/Core/DAL.php"
    click Helper "https://github.com/vgalvoso/phpeasy/blob/master/Core/Helper.php"
    click Validator "https://github.com/vgalvoso/phpeasy/blob/master/Core/Validator.php"
    click HomeView "https://github.com/vgalvoso/phpeasy/blob/master/View/index.php"
    click DashView "https://github.com/vgalvoso/phpeasy/blob/master/View/dashboard.php"
    click LoginFailed "https://github.com/vgalvoso/phpeasy/blob/master/View/login/login_failed.php"
    click NotFound "https://github.com/vgalvoso/phpeasy/blob/master/View/not_found.php"
    click APILogin "https://github.com/vgalvoso/phpeasy/blob/master/api/login.php"
    click APIUsers "https://github.com/vgalvoso/phpeasy/blob/master/api/users.php"
    click CSS "https://github.com/vgalvoso/phpeasy/blob/master/public/css/mystyle.css"
    click JS "https://github.com/vgalvoso/phpeasy/blob/master/public/js/vanscript.js"
    click ComposerJSON "https://github.com/vgalvoso/phpeasy/blob/master/composer.json"
    click ComposerLock "https://github.com/vgalvoso/phpeasy/blob/master/composer.lock"

    %% Styles
    classDef external fill:#e0f7fa,stroke:#006064,color:#006064
    classDef server fill:#eceff1,stroke:#607d8b,color:#37474f
    classDef core fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef presentation fill:#ffe0b2,stroke:#e65100,color:#e65100
    classDef database fill:#c8e6c9,stroke:#2e7d32,color:#2e7d32
```
