# chicongst/simple_mvc architecture

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

- Interactive diagram: https://gitdiagram.com/chicongst/simple_mvc
- Repository: https://github.com/chicongst/simple_mvc

## Overview

##### Main Components
- Front Controller – The entry point (index.php) is responsible for handling incoming HTTP requests.
- Bootstrap/Autoload Mechanism – The app/autoload.php in conjunction with the libraries (such as Core.php and Controller.php) is responsible for automatically loading the required classes.
- Routing and Core Logic – The libraries/Core.php likely contains the logic that interprets the request URL and dispatches it to the appropriate controller.
- Controllers – Located in app/controllers (e.g., Auth.php, IndexPage.php, Posts.php, Users.php), these manage the user requests and business logic.
- Models – Found in app/models (e.g., Post.php, User.php), these represent the data objects and interact with the database.
- Views – The views folder holds the front-end presentation files (with subdivisions for includes, posts, and users), along with a rich collection of static assets (CSS, JavaScript, images, and vendor libraries such as Bootstrap, CKEditor, DataTables, and others).
- Configuration – The config directory contains configuration and session initialization files.
- Database & Helper Libraries – The libraries folder includes helpers and core libraries like Database.php (for database interactions), Controller.php (an abstract base for controllers), and the php MVC SQL file for database schema/settings.

##### Relationships and Data Flow
- Web requests reach the front controller (index.php) which triggers the autoload mechanism.
- The Core component (Core.php) then interprets the URI, selecting and calling the appropriate controller.
- Each controller (in app/controllers) may call one or more models (in app/models) to fetch or update data in the database. The Database library is utilized here.
- After executing business logic, controllers pass data to view templates (in the views folder) for the final output.
- The views use static assets (found in views/include/assets) and vendor libraries for styling, interactivity, and dynamic behavior.

##### Architectural Patterns and Principles
- MVC Pattern – The project strictly separates concerns: controllers handle input logic, models manage data and business rules, and views handle presentation.
- Separation of Concerns – Configuration, libraries, and autoloading are separated into distinct directories.
- Front Controller Pattern – All requests are funneled through index.php, simplifying route management and initial setup.

##### Key Technologies and Framework Tools
- PHP (server-side scripting) is used as the backend language.
- SQL (database schema provided in libraries/phpmvc.sql) is involved in data persistence.
- Bootstrap, CKEditor, DataTables, and other third-party assets found under views/include/assets/vendors enhance the front-end.

## Diagram (Mermaid)

```mermaid
graph TD
    %% MVC Components
    subgraph "MVC Components"
        A("HTTP Request"):::http
        B("Front Controller (index.php)"):::front
        C("Bootstrap/Autoload (app/autoload.php)"):::autoload
        D("Core/Router (libraries/Core.php)"):::core
        E("Controllers (app/controllers)"):::controller
        F("Models (app/models)"):::model
        G("Views (views)"):::view
    end

    A -->|"handles"| B
    B -->|"calls"| C
    C -->|"initializes"| D
    D -->|"dispatches to"| E
    E -->|"interactsWith"| F
    E -->|"renders"| G

    %% Supporting Components
    subgraph "Supporting Components"
        H("Configuration (config)"):::config
    end

    subgraph "Libraries & Helpers"
        I("Database Library (libraries/Database.php)"):::library
        J("Base Controller (libraries/Controller.php)"):::library
        K("Database Schema (libraries/phpmvc.sql)"):::library
    end

    H -->|"configures"| B
    J -->|"extends"| E
    I -->|"supports"| F

    %% Click Events
    click B "https://github.com/chicongst/simple_mvc/blob/master/index.php"
    click C "https://github.com/chicongst/simple_mvc/blob/master/app/autoload.php"
    click D "https://github.com/chicongst/simple_mvc/blob/master/libraries/Core.php"
    click E "https://github.com/chicongst/simple_mvc/tree/master/app/controllers"
    click F "https://github.com/chicongst/simple_mvc/tree/master/app/models"
    click G "https://github.com/chicongst/simple_mvc/tree/master/views"
    click H "https://github.com/chicongst/simple_mvc/tree/master/config"
    click I "https://github.com/chicongst/simple_mvc/blob/master/libraries/Database.php"
    click J "https://github.com/chicongst/simple_mvc/blob/master/libraries/Controller.php"
    click K "https://github.com/chicongst/simple_mvc/blob/master/libraries/phpmvc.sql"

    %% Class Definitions for Styling
    classDef http fill:#e3f2fd,stroke:#333,stroke-width:2px;
    classDef front fill:#ffecb3,stroke:#333,stroke-width:2px;
    classDef autoload fill:#ffe0b2,stroke:#333,stroke-width:2px;
    classDef core fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef controller fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef model fill:#dcedc8,stroke:#333,stroke-width:2px;
    classDef view fill:#f8bbd0,stroke:#333,stroke-width:2px;
    classDef config fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef library fill:#f0f4c3,stroke:#333,stroke-width:2px;
```
