# banago/simple-php-website architecture

> Architecture diagram of the GitHub repository banago/simple-php-website, 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/banago/simple-php-website
- Repository: https://github.com/banago/simple-php-website

## Overview

##### Project type and purpose
- This is a minimal, beginner-friendly PHP website. It follows a simple “flat-file MVC” style:
- No database—content is stored in `.phtml` files.
- A front controller (`index.php`) routes requests.
- Separation of concerns between content, logic, and template.

##### File structure
- Top-level files:
- `.htaccess` – defines URL rewrites for “pretty” URIs.
- `index.php` – single entry point (front controller).
- `readme.md` – project description and instructions.
- Directories:
- `content/` – page templates (`home`, `about-us`, `contact`, `products`, `404`).
- `includes/` – PHP logic (configuration and helper functions).
- `template/` – presentation layer (main layout `template.php` + `style.css`).
- No database, no external services. All routing and rendering happen on the PHP server.

##### Key insights from the README
- The site uses query strings (`?page=about`) and supports pretty URIs if enabled in `config.php`.
- Demonstrates separation of concerns: logic in `/includes`, content in `/content`, layout in `/template`.

##### Main components
a. Client-side browser
b. Web server (Apache or PHP’s built-in server)
c. Front Controller (`index.php`)
d. Configuration & Helper Module (`includes/config.php`, `includes/functions.php`)
e. Content Module (`content/*.phtml`)
f. Template/Layout Module (`template/template.php`, `template/style.css`)
g. URL Rewriter (`.htaccess`, optional)

##### Relationships & data flow
1. Browser sends HTTP request → Web server
2. Web server hands request to `index.php` (front controller)
3. `index.php` reads `config.php` to check `pretty_uri` flag and loads `functions.php`
4. Based on URL or `?page=` parameter, it selects the appropriate `.phtml` in `/content`
5. The selected content is injected into `/template/template.php`, which links `style.css`
6. Template outputs the final HTML → Browser receives response
7. If page not found, a 404 content file is served

##### Architectural patterns and principles
- Front Controller pattern (all requests go through `index.php`)
- Separation of Concerns:
- Configuration & utilities (`includes/`)
- Content (`content/`)
- Presentation (`template/`)
- Simple routing mechanism with optional URL rewriting

##### Essential elements
- Clear labels: “Browser”, “Apache/PHP Server”, “index.php (Front Controller)”, etc.
- Logic layer (includes) – blue
- Content layer – green
- Presentation layer – orange

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Browser"]:::client

    %% Server and routing
    WebServer["Apache/PHP Server"]:::server
    URLRewriter[".htaccess"]:::rewriter
    FrontController["index.php\n(Front Controller)"]:::logic

    %% Logic layer
    Config["config.php\n(Configuration)"]:::logic
    Functions["functions.php\n(Helper Functions)"]:::logic

    %% Content layer
    subgraph "Content Layer"
        direction TB
        Home["home.phtml"]:::content
        About["about-us.phtml"]:::content
        Contact["contact.phtml"]:::content
        Products["products.phtml"]:::content
        NotFound["404.phtml"]:::content
    end

    %% Presentation layer
    subgraph "Presentation Layer"
        direction TB
        Template["template.php"]:::presentation
        Style["style.css"]:::presentation
    end

    %% Documentation
    Docs["readme.md"]:::docs

    %% Flows
    Browser -->|"1.HTTP request"| WebServer
    WebServer -->|"2a.URL rewrite"| URLRewriter
    URLRewriter -->|"2b.route to Front Controller"| FrontController
    FrontController -->|"3.load config"| Config
    FrontController -->|"3.load helpers"| Functions
    FrontController -->|"4.select content"| Home
    FrontController -->|"4.select content"| About
    FrontController -->|"4.select content"| Contact
    FrontController -->|"4.select content"| Products
    FrontController -->|"4.select content"| NotFound
    Home -->|"5.inject into template"| Template
    About -->|"5.inject into template"| Template
    Contact -->|"5.inject into template"| Template
    Products -->|"5.inject into template"| Template
    NotFound -->|"5.inject into template"| Template
    Template -->|"6.render HTML with CSS"| Browser

    %% Click Events
    click FrontController "https://github.com/banago/simple-php-website/blob/master/index.php"
    click URLRewriter "https://github.com/banago/simple-php-website/blob/master/.htaccess"
    click Config "https://github.com/banago/simple-php-website/blob/master/includes/config.php"
    click Functions "https://github.com/banago/simple-php-website/blob/master/includes/functions.php"
    click Home "https://github.com/banago/simple-php-website/blob/master/content/home.phtml"
    click About "https://github.com/banago/simple-php-website/blob/master/content/about-us.phtml"
    click Contact "https://github.com/banago/simple-php-website/blob/master/content/contact.phtml"
    click Products "https://github.com/banago/simple-php-website/blob/master/content/products.phtml"
    click NotFound "https://github.com/banago/simple-php-website/blob/master/content/404.phtml"
    click Template "https://github.com/banago/simple-php-website/blob/master/template/template.php"
    click Style "https://github.com/banago/simple-php-website/blob/master/template/style.css"
    click Docs "https://github.com/banago/simple-php-website/blob/master/readme.md"

    %% Styles
    classDef client fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef server fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef rewriter fill:#e6ccff,stroke:#333,stroke-width:1px
    classDef logic fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef content fill:#d4edda,stroke:#333,stroke-width:1px
    classDef presentation fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef docs fill:#f8d7da,stroke:#333,stroke-width:1px
```
