# thecodeholic/php-mvc-framework architecture

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

- Interactive diagram: https://gitdiagram.com/thecodeholic/php-mvc-framework
- Repository: https://github.com/thecodeholic/php-mvc-framework

## Overview

##### Project type and purpose
- This is a minimalistic PHP MVC web application/framework meant for educational use.
- It follows the classic Model-View-Controller pattern, uses Composer for dependency management, and supports Docker for local development.
- It provides basic user registration, login, profile, and static pages (about, contact).

##### File structure
- Top-level files:
- docker-compose.yml + docker/ – Docker setup for “app” (PHP+Apache) and “db” (MySQL).
- migrations.php + migrations/ – CLI script and migration files to create/alter the database.
- composer.json – PHP dependencies, including a core MVC package.
- .env.example – environment variables for database credentials.
- Directories:
- public/ – Web root; .htaccess + index.php (front controller) + assets (css).
- controllers/ – Controller classes handling HTTP requests.
- models/ – Domain models (e.g., User, LoginForm).
- views/ – Twig-style PHP templates, organized by layouts and pages.
- runtime/ – Temporary files.

##### README for additional insights
- Confirms MVC pattern, Composer setup, migrations flow, and Docker-based dev environment.

a. Main components
- Client (Browser)
- Docker Network
– Web Server Container (“app”): Apache+PHP
– Database Container (“db”): MySQL
- PHP MVC Application
– Front Controller (public/index.php)
– Router & Dispatcher (core package)
– Controllers
– Models (with migrations as a CLI sub-component)
– Views (templates + static assets)
- External Dependencies: Composer packages, .env configuration
b. Relationships and interactions
1. Browser sends HTTP request → Web Server (Docker “app”) on port 8080
2. Apache routes all requests to public/index.php
3. Front Controller loads .env, bootstraps core package
4. Router matches URL to a Controller action
5. Controller:
– Reads request data
– Invokes Models to query/update MySQL over Docker network
– Loads a View template, passes model data
6. View renders HTML → Apache → Browser
c. Architectural patterns & principles
- MVC separation of concerns
- Front Controller pattern
- Dependency Injection via Composer + core package
- Configuration via environment variables (.env)
- Infrastructure-as-code with Docker Compose
d. Key technologies & libraries
- PHP 7+ / Apache (in Docker)
- MySQL (in Docker)
- Composer (tc-php-mvc-core package)
- .env for configuration
- migrations.php as a lightweight migration runner

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef client fill:#ffa500,stroke:#333,stroke-width:1px
    classDef webapp fill:#add8e6,stroke:#333,stroke-width:1px
    classDef database fill:#90ee90,stroke:#333,stroke-width:1px
    classDef cli fill:#d3d3d3,stroke:#333,stroke-width:1px

    Browser["Browser"]:::client

    subgraph "Docker Compose"
        direction TB
        ComposeFile["docker-compose.yml"]:::webapp
        click ComposeFile "https://github.com/thecodeholic/php-mvc-framework/blob/master/docker-compose.yml"
        subgraph "Web Server Container (app)"
            direction TB
            Apache["Apache + PHP"]:::webapp
            click Apache "https://github.com/thecodeholic/php-mvc-framework/tree/master/docker/Dockerfile"
            Env[".env (.env.example)"]:::webapp
            click Env "https://github.com/thecodeholic/php-mvc-framework/blob/master/.env.example"
            Composer["composer.json"]:::webapp
            click Composer "https://github.com/thecodeholic/php-mvc-framework/blob/master/composer.json"
            HTAccess["public/.htaccess"]:::webapp
            click HTAccess "https://github.com/thecodeholic/php-mvc-framework/blob/master/public/.htaccess"
            FC["public/index.php\n(Front Controller)"]:::webapp
            click FC "https://github.com/thecodeholic/php-mvc-framework/blob/master/public/index.php"
            CoreRouter["Core Router & Dispatcher"]:::webapp

            subgraph "Controller Layer"
                direction TB
                AboutCtrl["AboutController.php"]:::webapp
                click AboutCtrl "https://github.com/thecodeholic/php-mvc-framework/blob/master/controllers/AboutController.php"
                SiteCtrl["SiteController.php"]:::webapp
                click SiteCtrl "https://github.com/thecodeholic/php-mvc-framework/blob/master/controllers/SiteController.php"
            end

            subgraph "Model Layer"
                direction TB
                UserModel["User.php"]:::webapp
                click UserModel "https://github.com/thecodeholic/php-mvc-framework/blob/master/models/User.php"
                LoginForm["LoginForm.php"]:::webapp
                click LoginForm "https://github.com/thecodeholic/php-mvc-framework/blob/master/models/LoginForm.php"
            end

            subgraph "View Layer"
                direction TB
                HomeView["home.php"]:::webapp
                click HomeView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/home.php"
                AboutView["about.php"]:::webapp
                click AboutView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/about.php"
                ContactView["contact.php"]:::webapp
                click ContactView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/contact.php"
                LoginView["login.php"]:::webapp
                click LoginView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/login.php"
                RegisterView["register.php"]:::webapp
                click RegisterView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/register.php"
                ProfileView["profile.php"]:::webapp
                click ProfileView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/profile.php"
                LayoutMain["layouts/main.php"]:::webapp
                click LayoutMain "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/layouts/main.php"
                LayoutAuth["layouts/auth.php"]:::webapp
                click LayoutAuth "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/layouts/auth.php"
                ErrorView["_error.php"]:::webapp
                click ErrorView "https://github.com/thecodeholic/php-mvc-framework/blob/master/views/_error.php"
            end

            Assets["public/css/bootstrap.css"]:::webapp
            click Assets "https://github.com/thecodeholic/php-mvc-framework/blob/master/public/css/bootstrap.css"
        end

        subgraph "Database Container (db)"
            direction TB
            MySQL["MySQL"]:::database
            click MySQL "https://github.com/thecodeholic/php-mvc-framework/blob/master/docker/mysql-config.cnf"
        end
    end

    subgraph "Migration CLI"
        direction TB
        Terminal["Terminal"]:::cli
        MigrationsCLI["migrations.php"]:::cli
        click MigrationsCLI "https://github.com/thecodeholic/php-mvc-framework/blob/master/migrations.php"
        M1["m0001_initial.php"]:::cli
        click M1 "https://github.com/thecodeholic/php-mvc-framework/blob/master/migrations/m0001_initial.php"
        M2["m0002_add_password_column.php"]:::cli
        click M2 "https://github.com/thecodeholic/php-mvc-framework/blob/master/migrations/m0002_add_password_column.php"
    end

    %% Flows
    Browser -->|HTTP Request| Apache
    Apache -->|routes to| FC
    FC -->|loads| Env
    FC -->|bootstraps| Composer
    FC -->|dispatch| CoreRouter
    CoreRouter -->|calls| AboutCtrl
    CoreRouter -->|calls| SiteCtrl
    AboutCtrl -->|uses| UserModel
    SiteCtrl -->|uses| UserModel
    AboutCtrl -->|renders| AboutView
    SiteCtrl -->|renders| HomeView
    SiteCtrl -->|renders| ContactView
    SiteCtrl -->|renders| LoginView
    SiteCtrl -->|renders| RegisterView
    SiteCtrl -->|renders| ProfileView
    AboutView -->|includes| LayoutMain
    HomeView -->|includes| LayoutMain
    LoginView -->|includes| LayoutAuth
    RegisterView -->|includes| LayoutAuth
    ErrorView -->|includes| LayoutMain
    UserModel -->|queries| MySQL
    LoginForm -->|validates via| MySQL
    Apache -->|serves assets| Assets
    MigrationsCLI -->|applies| M1
    MigrationsCLI -->|applies| M2
    M1 -->|migrates| MySQL
    M2 -->|migrates| MySQL
    Terminal -->|runs| MigrationsCLI

    %% Response flow
    AboutView -->|HTML Response| Browser
    HomeView -->|HTML Response| Browser
    ContactView -->|HTML Response| Browser
    LoginView -->|HTML Response| Browser
    RegisterView -->|HTML Response| Browser
    ProfileView -->|HTML Response| Browser
```
