# script-php/easyapp architecture

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

- Interactive diagram: https://gitdiagram.com/script-php/easyapp
- Repository: https://github.com/script-php/easyapp

## Overview

##### Project type and purpose
- EasyAPP is a PHP-based, monolithic MVC framework plus application scaffold.
- Purpose: provide a lightweight, easy-to-maintain structure for any PHP website.

##### File structure
- Top ­level “index.php” and “.htaccess”: front-controller pattern, all HTTP requests funnel here.
- “system/”: core framework code (Autoloader, Controller base classes, Framework modules for Config, Db, Request, Response, Event, etc.).
- “app/”: application-specific MVC layers:
- app/config.php – global settings
- app/controller – HTTP action handlers
- app/model – business-logic/data models
- app/view – HTML templates
- app/language – i18n strings
- app/helper.php – utility functions
- “assets/”: public static files (JS, CSS, images).
- “storage/”: runtime data (cache, logs, sessions, uploads).
- “composer.json/lock”: external libraries.
- “tests/”: automated unit and integration tests structure.

##### Key insights from README
- Clean, maintainable code with no spaghetti.
- Lightweight footprint, PHP 7.0+ requirement.

##### Main components
a. External clients & transport
- Browser or HTTP client → Web server (Apache/Nginx)
- .htaccess rewrite to /index.php
b. PHP runtime & autoloader
- Autoloader (system/Autoloader.php)
c. Framework core (system/Framework components)
- Request → Router → Controller dispatcher
- Config loader
- Db layer (system/Framework/Db.php)
- Event bus (system/Framework/Event.php)
- Language loader
- Loader (view/template engine)
- Response builder
d. Application layer (app/)
- Controllers
- Models
- Views (templates)
- Helpers & language files
e. Data stores & storage
- Relational database (MySQL, PostgreSQL, etc.) via Db abstraction
- Local filesystem (storage/cache, logs, sessions, uploads)
f. External dependencies
- Composer-installed libraries (system/Vendor + vendor/)
- Mail service (system/Framework/Mail.php)
- Image processor (system/Framework/Image.php)

##### Relationships & data flow
1. Client issues HTTP request → Web server
2. .htaccess routes to index.php → Autoloader loads core classes
3. Framework bootstraps: Config, Registry, Event system
4. Request parsed → Router chooses Controller & Action
5. Controller invokes Models (Db queries) and Helpers
6. Data enriched via Events or Language loader
7. Controller passes data to View → Template rendered
8. Response sent back to client
9. During steps, storage is used for sessions, cache, logs, uploads

##### Architectural patterns & principles
- Front Controller (all requests through index.php)
- MVC separation (Controllers, Models, Views)
- Dependency Registry / Service Locator
- Event-driven hooks
- Autoloading & PSR-like structure
- Layered file storage for cache/logs/sessions

##### Detail level
- Call out the front-controller (.htaccess → index.php → Autoloader).
- Test harness separately if desired (tests/ folder invoking Controllers & Models).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients & Services
    subgraph "External Services"
        classDef external fill:#c2f0c2,stroke:#333
        Browser["Browser/HTTP Client"]:::external
        DB["Relational Database"]:::external
        MailService["Mail Service"]:::external
    end

    %% Web Server & PHP Runtime
    subgraph "Web Server & PHP Runtime"
        classDef runtime fill:#d0e1f9,stroke:#333
        WS["Web Server<br>(Apache/Nginx)"]:::external
        HT[".htaccess"]:::runtime
        Index["index.php"]:::runtime
        Auto["Autoloader"]:::core
        click HT "https://github.com/script-php/easyapp/blob/main//.htaccess"
        click Index "https://github.com/script-php/easyapp/blob/main//index.php"
        click Auto "https://github.com/script-php/easyapp/blob/main//system/Autoloader.php"
    end

    %% Framework Core
    subgraph "Framework Core"
        classDef core fill:#c2d9ff,stroke:#333
        Framework["Framework.php"]:::core
        ControllerBase["Controller.php"]:::core
        DefaultDispatch["Default.php"]:::core
        Registry["Registry.php"]:::core
        Proxy["Proxy.php"]:::core
        Request["Request.php"]:::core
        RouterAction["Action.php"]:::core
        Url["Url.php"]:::core
        Response["Response.php"]:::core
        ConfigLoader["Config.php"]:::core
        EventBus["Event.php"]:::core
        LanguageLoader["Language.php"]:::core
        Loader["Load.php"]:::core
        Db["Db.php"]:::core
        Tables["Tables.php"]:::core
        MailCore["Mail.php"]:::core
        ImageCore["Image.php"]:::core
        Util["Util.php"]:::core
        FileHelper["File.php"]:::core
        Exceptions["Exceptions/"]:::core
        click Framework "https://github.com/script-php/easyapp/blob/main//system/Framework.php"
        click ControllerBase "https://github.com/script-php/easyapp/blob/main//system/Controller.php"
        click DefaultDispatch "https://github.com/script-php/easyapp/blob/main//system/Default.php"
        click Registry "https://github.com/script-php/easyapp/blob/main//system/Framework/Registry.php"
        click Proxy "https://github.com/script-php/easyapp/blob/main//system/Framework/Proxy.php"
        click Request "https://github.com/script-php/easyapp/blob/main//system/Framework/Request.php"
        click Response "https://github.com/script-php/easyapp/blob/main//system/Framework/Response.php"
        click RouterAction "https://github.com/script-php/easyapp/blob/main//system/Framework/Action.php"
        click Url "https://github.com/script-php/easyapp/blob/main//system/Framework/Url.php"
        click ConfigLoader "https://github.com/script-php/easyapp/blob/main//system/Framework/Config.php"
        click EventBus "https://github.com/script-php/easyapp/blob/main//system/Framework/Event.php"
        click LanguageLoader "https://github.com/script-php/easyapp/blob/main//system/Framework/Language.php"
        click Loader "https://github.com/script-php/easyapp/blob/main//system/Framework/Load.php"
        click Db "https://github.com/script-php/easyapp/blob/main//system/Framework/Db.php"
        click Tables "https://github.com/script-php/easyapp/blob/main//system/Framework/Tables.php"
        click MailCore "https://github.com/script-php/easyapp/blob/main//system/Framework/Mail.php"
        click ImageCore "https://github.com/script-php/easyapp/blob/main//system/Framework/Image.php"
        click Util "https://github.com/script-php/easyapp/blob/main//system/Framework/Util.php"
        click FileHelper "https://github.com/script-php/easyapp/blob/main//system/Framework/File.php"
        click Exceptions "https://github.com/script-php/easyapp/tree/main//system/Framework/Exceptions/"
    end

    %% Application Layer
    subgraph "Application Layer"
        classDef app fill:#ffe0b3,stroke:#333
        AppConfig["app/config.php"]:::app
        Controllers["Controllers/"]:::app
        Models["Models/"]:::app
        Views["Views/"]:::app
        AppHelper["helper.php"]:::app
        AppLang["language/"]:::app
        click AppConfig "https://github.com/script-php/easyapp/blob/main//app/config.php"
        click Controllers "https://github.com/script-php/easyapp/tree/main//app/controller/"
        click Models "https://github.com/script-php/easyapp/tree/main//app/model/"
        click Views "https://github.com/script-php/easyapp/tree/main//app/view/"
        click AppHelper "https://github.com/script-php/easyapp/blob/main//app/helper.php"
        click AppLang "https://github.com/script-php/easyapp/tree/main//app/language/"
    end

    %% Storage & Assets
    subgraph "Storage & Assets"
        classDef storage fill:#e0e0e0,stroke:#333
        Assets["assets/"]:::storage
        Cache["storage/cache/"]:::storage
        Logs["storage/logs/"]:::storage
        Sessions["storage/sessions/"]:::storage
        Uploads["storage/uploads/"]:::storage
        click Assets "https://github.com/script-php/easyapp/tree/main//assets/"
        click Cache "https://github.com/script-php/easyapp/tree/main//storage/cache/"
        click Logs "https://github.com/script-php/easyapp/tree/main//storage/logs/"
        click Sessions "https://github.com/script-php/easyapp/tree/main//storage/sessions/"
        click Uploads "https://github.com/script-php/easyapp/tree/main//storage/uploads/"
    end

    %% External Dependencies
    subgraph "External Dependencies"
        classDef deps fill:#d9d9d9,stroke:#333
        ComposerJSON["composer.json/lock"]:::deps
        Vendor["system/Vendor/ & vendor/"]:::deps
        click ComposerJSON "https://github.com/script-php/easyapp/blob/main//composer.json"
        click ComposerJSON "https://github.com/script-php/easyapp/blob/main//composer.lock"
        click Vendor "https://github.com/script-php/easyapp/tree/main//system/Vendor/"
    end

    %% Tests
    subgraph "Tests"
        classDef test fill:#f2e0ff,stroke:#333
        TestIndex["tests/index.php"]:::test
        TestConfig["tests/config.php"]:::test
        TestCtrls["tests/controller/"]:::test
        TestModels["tests/model/"]:::test
        TestViews["tests/view/"]:::test
        TestLang["tests/language/"]:::test
        TestHelper["tests/helper.php"]:::test
        click TestIndex "https://github.com/script-php/easyapp/blob/main//tests/index.php"
        click TestConfig "https://github.com/script-php/easyapp/blob/main//tests/config.php"
        click TestCtrls "https://github.com/script-php/easyapp/tree/main//tests/controller/"
        click TestModels "https://github.com/script-php/easyapp/tree/main//tests/model/"
        click TestViews "https://github.com/script-php/easyapp/tree/main//tests/view/"
        click TestLang "https://github.com/script-php/easyapp/tree/main//tests/language/"
        click TestHelper "https://github.com/script-php/easyapp/blob/main//tests/helper.php"
    end

    %% Data Flow & Connections
    Browser -->|HTTP Request| WS
    WS --> HT
    HT --> Index
    Index --> Auto
    Auto --> Framework
    Framework --> ConfigLoader
    Framework --> EventBus
    Framework --> Registry
    Registry --> Proxy
    Framework --> Request
    Request --> RouterAction
    RouterAction --> DefaultDispatch
    DefaultDispatch --> ControllerBase
    ControllerBase --> Controllers
    Controllers --> Models
    Controllers --> AppHelper
    Controllers --> AppLang
    Controllers --> EventBus
    Controllers --> Db
    Db --> DB
    Controllers --> Views
    Views --> Loader
    Loader --> Views
    Views --> LanguageLoader
    LanguageLoader --> AppLang
    Controllers --> Response
    Response -->|HTTP Response| Browser
    Controllers --> Cache
    Controllers --> Logs
    Controllers --> Sessions
    Controllers --> Uploads
    ComposerJSON --> Vendor
    Framework --> MailCore
    MailCore --> MailService
    Framework --> ImageCore
    Controllers --> ImageCore

    %% Styles
    classDef app fill:#ffe0b3,stroke:#333
    classDef core fill:#c2d9ff,stroke:#333
    classDef external fill:#c2f0c2,stroke:#333
    classDef storage fill:#e0e0e0,stroke:#333
    classDef deps fill:#d9d9d9,stroke:#333
    classDef test fill:#f2e0ff,stroke:#333
    classDef runtime fill:#d0e1f9,stroke:#333
```
