# mh-shuvo/php-mvc architecture

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

- Interactive diagram: https://gitdiagram.com/mh-shuvo/php-mvc
- Repository: https://github.com/mh-shuvo/php-mvc

## Overview

##### Main Components
- Front Controller / Entry Points:
- The public folder represents the document root for web requests. Include files like “public/index.php” which serves as the entry point.
- “app/bootstrap.php” in the app folder that likely initializes the framework.
- Controllers:
- Represented by “app/controllers”, these components process incoming requests. For example, “Pages.php” in this directory serves as a sample controller.
- Views:
- The “app/views” directory includes the UI components (with header and footer within “app/views/inc”) that render data.
- Core Libraries:
- “app/libraries” contains essential framework classes such as “Core.php”, “Controller.php”, “Database.php”, and “Handler.php”. These classes implement routing, base controller functionality, DB interactions, and error handling.
- Configuration:
- “app/config/config.php” holds configuration settings that drive the application behavior.
- Static Assets:
- The “public/css”, “public/js”, and other files such as “public/test.php” represent public-facing assets that support the application interface.
- Infrastructure/Support Files:
- Files like “.htaccess” in both the project root and certain directories suggest rewrite rules and URL routing mechanisms.

##### Relationships and Interactions
- Data Flow starts at the public/index.php (or test endpoints) that funnels web requests into the application.
- The Bootstrap process (in app/bootstrap.php) configures the environment, loads configuration from app/config, and instantiates Core classes.
- The Core routing (likely inside app/libraries/Core.php) directs the request to the appropriate Controller (as seen in app/controllers) based on the URL.
- The Controller then interacts with Model components (not present in a dedicated “models” folder, so model functionality might be integrated within controllers or via external libraries) and loads the appropriate Views (from app/views).
- The Views render the final output, integrating common components from “app/views/inc”, and delivering the final HTML/CSS/JS to the client.
- The Database and Handler libraries provide supporting functionality for data persistence and error management, respectively.

##### Architectural Patterns and Design Principles
- MVC Pattern: Separates concerns between Controllers handling requests, Views managing the presentation, and underlying business logic (potentially in models or libraries).
- Front Controller: The public/index.php and bootstrap.php serve as centralized entry points.
- Configuration Management: Centralized configuration stored in app/config.
- Modularity: Segregated directories for controllers, views, libraries, and configuration enhances the maintainability and scalability of the framework.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Public Layer
    subgraph "Public Layer"
        PI["public/index.php"]:::front
        PCss["public/css/style.css"]:::static
        PJs["public/js/script.js"]:::static
        PTest["public/test.php"]:::static
        PublicHT["public/.htaccess"]:::routing
    end

    %% Application Layer
    subgraph "Application Layer"
        Bootstrap["app/bootstrap.php"]:::front
        Config["app/config/config.php"]:::config

        subgraph "Core Libraries"
            CoreLib["app/libraries/Core.php"]:::library
            ControllerBase["app/libraries/Controller.php"]:::library
            Database["app/libraries/Database.php"]:::library
            Handler["app/libraries/Handler.php"]:::library
        end

        subgraph "Controllers"
            Controller["app/controllers/Pages.php"]:::controller
        end

        subgraph "Views"
            View["app/views/index.php"]:::view
            IncHeader["app/views/inc/header.php"]:::view
            IncFooter["app/views/inc/footer.php"]:::view
        end

        AppHT["app/.htaccess"]:::routing
    end

    %% URL Routing / Rewrite Rules
    subgraph "URL Routing"
        RRoot[".htaccess (root)"]:::routing
    end

    %% Relationships / Data Flow
    PI -->|"calls"| Bootstrap
    Bootstrap -->|"loads"| Config
    Bootstrap -->|"initializes"| CoreLib
    CoreLib -->|"routes to"| Controller
    Controller -->|"renders"| View
    View -->|"includes"| IncHeader
    View -->|"includes"| IncFooter

    %% Controller dependencies
    Controller -->|"extends"| ControllerBase
    Controller -->|"utilizes"| Database
    Controller -->|"handles errors via"| Handler

    %% Views reference static assets
    View -->|"includes"| PCss
    View -->|"includes"| PJs
    View -->|"includes"| PTest

    %% .htaccess relationships (supporting URL routing)
    PublicHT --- RRoot
    AppHT --- RRoot

    %% Click Events
    click PI "https://github.com/mh-shuvo/php-mvc/blob/main/public/index.php"
    click Bootstrap "https://github.com/mh-shuvo/php-mvc/blob/main/app/bootstrap.php"
    click Config "https://github.com/mh-shuvo/php-mvc/blob/main/app/config/config.php"
    click Controller "https://github.com/mh-shuvo/php-mvc/blob/main/app/controllers/Pages.php"
    click CoreLib "https://github.com/mh-shuvo/php-mvc/blob/main/app/libraries/Core.php"
    click ControllerBase "https://github.com/mh-shuvo/php-mvc/blob/main/app/libraries/Controller.php"
    click Database "https://github.com/mh-shuvo/php-mvc/blob/main/app/libraries/Database.php"
    click Handler "https://github.com/mh-shuvo/php-mvc/blob/main/app/libraries/Handler.php"
    click View "https://github.com/mh-shuvo/php-mvc/blob/main/app/views/index.php"
    click IncHeader "https://github.com/mh-shuvo/php-mvc/blob/main/app/views/inc/header.php"
    click IncFooter "https://github.com/mh-shuvo/php-mvc/blob/main/app/views/inc/footer.php"
    click PCss "https://github.com/mh-shuvo/php-mvc/blob/main/public/css/style.css"
    click PJs "https://github.com/mh-shuvo/php-mvc/blob/main/public/js/script.js"
    click PTest "https://github.com/mh-shuvo/php-mvc/blob/main/public/test.php"
    click RRoot "https://github.com/mh-shuvo/php-mvc/blob/main/.htaccess"
    click PublicHT "https://github.com/mh-shuvo/php-mvc/blob/main/public/.htaccess"
    click AppHT "https://github.com/mh-shuvo/php-mvc/blob/main/app/.htaccess"

    %% Styles
    classDef front fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef controller fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef view fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef library fill:#577590,stroke:#333,stroke-width:2px;
    classDef config fill:#f3722c,stroke:#333,stroke-width:2px;
    classDef static fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef routing fill:#a593e0,stroke:#333,stroke-width:2px;
```
