# stearz/php-redirect-server architecture

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

- Interactive diagram: https://gitdiagram.com/stearz/php-redirect-server
- Repository: https://github.com/stearz/php-redirect-server

## Overview

##### Project type and purpose
- This is a small PHP–based web application whose sole job is to answer incoming HTTP requests by issuing redirects of various types.
- It uses a MySQL database to store redirect rules.

##### File structure
- Top‐level files:
- index.php – the main request handler
- config.inc.php – database connection settings
- mod_*.inc.php – pluggable modules, each implementing a different redirect type (301, 302, frame, proxy)
- There are no separate “frontend” or “backend” directories—everything runs in a single PHP‐enabled webserver process.
- The only external dependency is MySQL (configurable via config.inc.php).

##### Extract key architecture insights from the README
- Incoming HTTP requests hit index.php
- index.php loads config.inc.php to connect to the database, then dispatches to one of four modules based on the “type” field in the redirects table
- The database table (“redirects”) holds: id, type, name, target, activation window
- mod_proxy.inc.php may act as an HTTP proxy rather than issuing a redirect

##### Main components and their interactions
a. Client (browser or bot)
b. Web Server + PHP engine (Apache/nginx with PHP-FPM)
- Serves index.php
- Loads configuration (DB credentials)
- Dynamically loads one of the modules
c. Module plugins
- mod_301.inc.php – sends HTTP 301 response
- mod_302.inc.php – sends HTTP 302 response
- mod_frame.inc.php – returns an HTML frame wrapper pointing to target
- mod_proxy.inc.php – fetches content from the target and streams it back
d. MySQL database
- Table “redirects” stores the routing rules
e. (Optional) Logs or monitoring – not present in code but can be added

##### Architectural patterns and design principles
- Modular plugin architecture: each redirect type is a separate module file
- Single‐entry controller: index.php acts as the front controller
- Data‐driven routing: redirect logic is driven by database records
- Separation of concerns: config is isolated in config.inc.php

- Clear labels for: Client, Web Server + PHP, config.inc.php, index.php, each mod_*.inc.php, MySQL Database

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    subgraph "External Actor"
        Client["Browser / Bot"]:::external
    end

    %% Web Server + PHP Layer
    subgraph "Web Server + PHP"
        direction TB
        Index["index.php"]:::server
        Config["config.inc.php"]:::server

        subgraph "Redirect Modules"
            direction TB
            M301["mod_301.inc.php"]:::module
            M302["mod_302.inc.php"]:::module
            MFrame["mod_frame.inc.php"]:::module
            MProxy["mod_proxy.inc.php"]:::module
        end
    end

    %% Database
    Database["MySQL<br/>redirects table"]:::database

    %% Documentation & Metadata
    subgraph "Documentation & Metadata"
        direction TB
        README["README.md"]:::docs
        VERSION["VERSION"]:::docs
        CHANGELOG["CHANGELOG.md"]:::docs
        LICENSE["LICENSE"]:::docs
        GITIGNORE[".gitignore"]:::docs
        HTACCESS[".htaccess"]:::docs
    end

    %% Data Flows
    Client -->|"HTTP GET request"| Index
    Index -->|"require/include"| Config
    Index -->|"SQL SELECT FROM redirects WHERE name=..."| Database
    Database -->|"redirect record (type,name,target)"| Index
    Index -->|"include appropriate module"| M301
    Index -->|"include appropriate module"| M302
    Index -->|"include appropriate module"| MFrame
    Index -->|"include appropriate module"| MProxy
    M301 -->|"HTTP 301 response"| Client
    M302 -->|"HTTP 302 response"| Client
    MFrame -->|"HTML frame wrapper"| Client
    MProxy -->|"proxied content stream"| Client

    %% Click Events
    click Index "https://github.com/stearz/php-redirect-server/blob/master/index.php"
    click Config "https://github.com/stearz/php-redirect-server/blob/master/config.inc.php"
    click M301 "https://github.com/stearz/php-redirect-server/blob/master/mod_301.inc.php"
    click M302 "https://github.com/stearz/php-redirect-server/blob/master/mod_302.inc.php"
    click MFrame "https://github.com/stearz/php-redirect-server/blob/master/mod_frame.inc.php"
    click MProxy "https://github.com/stearz/php-redirect-server/blob/master/mod_proxy.inc.php"
    click README "https://github.com/stearz/php-redirect-server/blob/master/README.md"
    click VERSION "https://github.com/stearz/php-redirect-server/tree/master/VERSION"
    click CHANGELOG "https://github.com/stearz/php-redirect-server/blob/master/CHANGELOG.md"
    click LICENSE "https://github.com/stearz/php-redirect-server/tree/master/LICENSE"
    click GITIGNORE "https://github.com/stearz/php-redirect-server/blob/master/.gitignore"
    click HTACCESS "https://github.com/stearz/php-redirect-server/blob/master/.htaccess"

    %% Styles
    classDef external fill:#b3e5fc,stroke:#036,stroke-width:1px
    classDef server fill:#bbdefb,stroke:#0a3,stroke-width:1px
    classDef module fill:#fff9c4,stroke:#b38,stroke-width:1px
    classDef database fill:#ffe0b2,stroke:#a52,stroke-width:1px
    classDef docs fill:#c8e6c9,stroke:#2a6,stroke-width:1px
```
