# brunoggdev/hefestosphp architecture

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

- Interactive diagram: https://gitdiagram.com/brunoggdev/hefestosphp
- Repository: https://github.com/brunoggdev/hefestosphp

## Overview

##### Project Type and Purpose
- This is a lightweight, zero-dependency PHP MVC framework (“HefestosPHP”) plus a sample “app” skeleton.
- Its goal is to teach beginners the core concepts of MVC (Models, Views, Controllers), routing, and database access in Portuguese, without the complexity of full-blown frameworks.

##### High-Level Components
a. Public/Web Root
- public/index.php (front controller)
- .htaccess (rewrites all requests to index.php)
- hefestos.css (optional static asset)
b. Application Layer (app/)
- Config (routing, database, filters, initialization)
- Controllers (ExemploController.php)
- Models (ExemploModel.php)
- Views (home.php, componentes/)
- Filtros (request filters)
- Database migrations/tables and SQLite file
- Testes (unit tests)
- auxiliares.php (helpers)
c. Framework Core (system/)
- Core (App.php, Controller.php, Model.php, Entidade.php)
- Database layer (Database.php, Tabela.php)
- Routing (Rota, Requisicao, Redirecionar, Filtros)
- CLI tooling (generators/templates for controllers, models, tables, etc.)
- Ferramentas (HTTP client, session, validator, upload, etc.)
- Error handling (exceptions)
- Views (404, 500, debug, maintenance)
- autoloader and iniciar_app.php
d. CLI/“forja” Directory
- (Possibly custom generators or project scaffolding)

##### Interactions and Data Flow
1. Browser → public/index.php
2. index.php → system/hefestos_autoloader → system/iniciar_app → system/Core/App
3. App uses system/Rotas to match incoming URI to a Controller/Action
4. Controller (in app/Controllers) invokes Models (app/Models → system/Database)
5. Model interacts with the DB (SQLite by default or other via database.php config)
6. Controller passes data to Views (app/Views or system/Views on errors)
7. View templates render HTML → Response sent to Browser
8. Optional filters (app/Filtros + system/Rotas/Filtros) execute before/after controllers
9. CLI (system/CLI and forja/) can be invoked via terminal to generate code or run migrations/tests

##### Architectural Patterns and Principles
- MVC separation: Controllers handle HTTP logic, Models handle data, Views handle presentation.
- Front Controller pattern: a single entry point (index.php) dispatches requests.
- Layered architecture: clear boundary between the user’s app code (app/) and the framework core (system/).
- Convention over configuration: default folder structure and naming.
- Extensibility via CLI templates and helper files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Browser["Browser / Client"]:::external
    Terminal["Terminal"]:::external

    %% Public/Web Root
    subgraph "Public/Web Root" 
        direction TB
        Index["public/index.php"]:::public
        HTACCESS[".htaccess"]:::public
        CSS["hefestos.css"]:::public
    end

    %% Application Layer
    subgraph "Application Layer (app/)" 
        direction TB
        subgraph "Config"
            direction TB
            AppConfig["app.php"]:::app
            DBConfig["database.php"]:::app
            FilConfig["filtros.php"]:::app
            InitConfig["inicializacao.php"]:::app
            RotConfig["rotas.php"]:::app
        end
        Controllers["ExemploController.php"]:::app
        Models["ExemploModel.php"]:::app
        subgraph "Views"
            direction TB
            HomeView["home.php"]:::app
            Saudacao["saudacao.php"]:::app
        end
        FiltersApp["ExemploFiltro.php"]:::app
        subgraph "Database"
            direction TB
            SQLiteDB["banco_de_dados.sqlite"]:::db
            Migration["2023-08-01-191326_exemplo.php"]:::app
        end
        Testes["exemplo_arquivo_teste.php"]:::app
        Aux["auxiliares.php"]:::app
    end

    %% Framework Core
    subgraph "Framework Core (system/)" 
        direction TB
        Loader["Autoloader"]:::core
        Bootstrap["App Bootstrap"]:::core
        subgraph "Core Classes"
            AppCore["App.php"]:::core
            ControllerCore["Controller.php"]:::core
            ModelCore["Model.php"]:::core
            Entidade["Entidade.php"]:::core
        end
        subgraph "Database Layer"
            DatabaseCore["Database.php"]:::core
            TabelaCore["Tabela.php"]:::core
        end
        subgraph "Routing"
            RotaCore["Rota.php"]:::core
            ReqCore["Requisicao.php"]:::core
            RedirectCore["Redirecionar.php"]:::core
            FilCore["Filtros.php"]:::core
        end
        subgraph "Error Views"
            V404["404.php"]:::core
            V500["500.php"]:::core
            Debug["debug.php"]:::core
            Manut["manutencao.php"]:::core
        end
        subgraph "Ferramentas"
            ClienteHttp["ClienteHttp.php"]:::core
            Colecao["Colecao.php"]:::core
            Cronometro["Cronometro.php"]:::core
            Sessao["Sessao.php"]:::core
            Upload["Upload.php"]:::core
            Validador["Validador.php"]:::core
        end
        subgraph "CLI Tooling"
            CLICore["CLI.php"]:::cli
            Templates["templates/"]:::cli
            Forja["forja/"]:::cli
        end
        subgraph "Exceptions"
            BAdReq["BadRequestException.php"]:::core
            Forbidden["ForbiddenException.php"]:::core
            HttpEx["HttpException.php"]:::core
            NotFound["NotFoundException.php"]:::core
            Unauthorized["UnauthorizedException.php"]:::core
        end
        subgraph "Testing Utils"
            Esperar["Esperar.php"]:::core
            Suite["SuiteDeTestes.php"]:::core
            Testador["Testador.php"]:::core
        end
        subgraph "Helpers"
            AuxCore["auxiliares.php"]:::core
            AuxTest["auxiliares_de_testes.php"]:::core
        end
    end

    %% Connections
    Browser -->|HTTP Request| Index
    Index -->|load| Loader
    Loader -->|init| Bootstrap
    Bootstrap -->|route match| RotaCore
    RotaCore -->|dispatch| Controllers
    FiltersApp -.->|before/after| Controllers
    FilCore -.->|global filters| Controllers
    Controllers -->|invokes| Models
    Models -->|uses| DatabaseCore
    DatabaseCore -->|queries| SQLiteDB
    Controllers -->|render| HomeView
    HomeView -->|HTML| Browser
    Controllers -->|on error| V404
    Terminal -->|exec| CLICore

    %% Click Events
    click Index "https://github.com/brunoggdev/hefestosphp/blob/main/public/index.php"
    click HTACCESS "https://github.com/brunoggdev/hefestosphp/blob/main/public/.htaccess"
    click CSS "https://github.com/brunoggdev/hefestosphp/blob/main/public/hefestos.css"
    click AppConfig "https://github.com/brunoggdev/hefestosphp/blob/main/app/Config/app.php"
    click DBConfig "https://github.com/brunoggdev/hefestosphp/blob/main/app/Config/database.php"
    click FilConfig "https://github.com/brunoggdev/hefestosphp/blob/main/app/Config/filtros.php"
    click InitConfig "https://github.com/brunoggdev/hefestosphp/blob/main/app/Config/inicializacao.php"
    click RotConfig "https://github.com/brunoggdev/hefestosphp/blob/main/app/Config/rotas.php"
    click Controllers "https://github.com/brunoggdev/hefestosphp/blob/main/app/Controllers/ExemploController.php"
    click Models "https://github.com/brunoggdev/hefestosphp/blob/main/app/Models/ExemploModel.php"
    click HomeView "https://github.com/brunoggdev/hefestosphp/blob/main/app/Views/home.php"
    click Saudacao "https://github.com/brunoggdev/hefestosphp/blob/main/app/Views/componentes/saudacao.php"
    click FiltersApp "https://github.com/brunoggdev/hefestosphp/blob/main/app/Filtros/ExemploFiltro.php"
    click SQLiteDB "https://github.com/brunoggdev/hefestosphp/blob/main/app/Database/sqlite/banco_de_dados.sqlite"
    click Migration "https://github.com/brunoggdev/hefestosphp/blob/main/app/Database/tabelas/2023-08-01-191326_exemplo.php"
    click Testes "https://github.com/brunoggdev/hefestosphp/blob/main/app/Testes/exemplo_arquivo_teste.php"
    click Aux "https://github.com/brunoggdev/hefestosphp/blob/main/app/auxiliares.php"
    click Loader "https://github.com/brunoggdev/hefestosphp/blob/main/system/hefestos_autoloader.php"
    click Bootstrap "https://github.com/brunoggdev/hefestosphp/blob/main/system/iniciar_app.php"
    click AppCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Core/App.php"
    click ControllerCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Core/Controller.php"
    click ModelCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Core/Model.php"
    click Entidade "https://github.com/brunoggdev/hefestosphp/blob/main/system/Core/Entidade.php"
    click DatabaseCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Database/Database.php"
    click TabelaCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Database/Tabela.php"
    click RotaCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Rotas/Rota.php"
    click ReqCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Rotas/Requisicao.php"
    click RedirectCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Rotas/Redirecionar.php"
    click FilCore "https://github.com/brunoggdev/hefestosphp/blob/main/system/Rotas/Filtros.php"
    click CLICore "https://github.com/brunoggdev/hefestosphp/blob/main/system/CLI/CLI.php"
    click Forja "https://github.com/brunoggdev/hefestosphp/tree/main/forja/"
    click ClienteHttp "https://github.com/brunoggdev/hefestosphp/blob/main/system/Ferramentas/ClienteHttp.php"
    click Colecao "https://github.com/brunoggdev/hefestosphp/blob/main/system/Ferramentas/Colecao.php"
    click Cronometro "https://github.com/brunoggdev/hefestosphp/blob/main/system/Ferramentas/Cronometro.php"
    click Sessao "https://github.com/brunoggdev/hefestosphp/blob/main/system/Ferramentas/Sessao.php"
    click Upload "https://github.com/brunoggdev/hefestosphp/blob/main/system/Ferramentas/Upload.php"
    click Validador "https://github.com/brunoggdev/hefestosphp/blob/main/system/Ferramentas/Validador.php"

    %% Styles
    classDef app fill:#e2f7e1,stroke:#2e8b57,color:#000
    classDef core fill:#e1e8f7,stroke:#1e3a82,color:#000
    classDef public fill:#fff3cd,stroke:#856404,color:#000
    classDef db fill:#fff5e6,stroke:#cc7a00,color:#000
    classDef cli fill:#f0e6ff,stroke:#7a3ccf,color:#000
    classDef external fill:#f5f5f5,stroke:#999,color:#000
```
