# walkor/webman architecture

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

- Interactive diagram: https://gitdiagram.com/walkor/webman
- Repository: https://github.com/walkor/webman

## Overview

##### Project type and purpose
- This is “webman,” a high-performance, event-driven PHP web framework built on top of Workerman.
- It provides an HTTP server, middleware pipeline, routing, controllers, models, views, and custom process support for long-running PHP services.

##### File structure
- Top-level:
- start.php / windows.php: entry points that bootstrap the Workerman server.
- composer.json: framework dependencies (Workerman, PSR interfaces, etc.).
- app/: your application code
- controller/IndexController.php – MVC controllers
- model/Test.php – data models
- middleware/StaticFile.php – built-in static file handler
- process/Http.php, Monitor.php – custom Workerman processes
- view/index/view.html – template files
- functions.php – global helper functions
- config/: all framework and application configuration
- route.php, server.php, process.php, middleware.php, container.php, etc.
- public/: default document root for static assets
- runtime/: writable directory for logs and compiled views
- support/: framework support classes (Request, Response, bootstrap)

##### README for additional insights
- Confirms the purpose: a production-grade PHP framework optimized for high concurrency.
- Points to docs and emphasizes open-source, MIT-licensed.

a. Main components
- Workerman Server Core
- HTTP Worker Process
- Monitor Process
- Configuration & Dependency Injection Container
- Middleware Pipeline (including StaticFile)
- Router
- Controllers & Models (app/controller, app/model)
- View Renderer (app/view + runtime/views)
- Public Asset Directory (public/)
- Support Layer (Request, Response)
- Runtime (logs, caches)
b. Relationships & data flow
1. Client → Workerman HTTP Worker
2. Worker: load config → init DI container
3. Worker: HTTP request enters Middleware Pipeline
– StaticFile middleware intercepts asset requests (public/)
– Other middleware (session, exception handler, etc.)
4. After middleware: Router dispatches to Controller
5. Controller invokes Model(s), business logic, collects data
6. Controller returns Response or View
7. View Renderer compiles template (app/view → runtime/views)
8. Response goes back through pipeline → Workerman → Client
9. Monitor Process runs alongside: watches Worker, restarts on failure
c. Architectural patterns & principles
- Event-driven, non-blocking IO (Workerman event loop)
- MVC pattern in app/
- Middleware pipeline pattern (chain of responsibility)
- Dependency Injection via container.php
- Process isolation: separate Monitor and HTTP processes
d. Key technologies & libraries
- PHP 7+
- Workerman – event-driven server
- PSR-7/PSR-15 (Request/Response, Middleware)
- Composer‐managed dependencies

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External"
        Client["Client"]:::external
    end

    subgraph "Framework Core"
        StartUnix["start.php"]:::framework
        StartWin["windows.php"]:::framework
        Bootstrap["support/bootstrap.php"]:::framework
        Core["Workerman Server Core"]:::framework
        RequestLoop["Event Loop"]:::framework
    end

    subgraph "Configuration Layer"
        ConfigBoot["config/bootstrap.php"]:::config
        Container["config/container.php"]:::config
        Dependence["config/dependence.php"]:::config
        ViewConfig["config/view.php"]:::config
        RouterConfig["config/route.php"]:::config
    end

    subgraph "Support Layer"
        Req["support/Request.php"]:::framework
        Res["support/Response.php"]:::framework
    end

    subgraph "Application Layer"
        subgraph "Processes"
            HttpProc["HTTP Worker Process"]:::application
            MonProc["Monitor Process"]:::application
        end
        subgraph "Middleware Pipeline"
            MWConfig["config/middleware.php"]:::config
            Static["StaticFile Middleware"]:::application
            OtherMW["Other Middleware"]:::application
        end
        Router["Router"]:::application
        Ctrl["IndexController"]:::application
        Model["Test Model"]:::application
        ViewRenderer["View Renderer"]:::application
        Template["Template (view.html)"]:::application
        PublicDir["public/"]:::application
    end

    subgraph "Runtime / Storage"
        Logs["runtime/logs/"]:::runtime
        ViewsCache["runtime/views/"]:::runtime
    end

    Client --> Core
    StartUnix --> Bootstrap
    StartWin --> Bootstrap
    Bootstrap --> ConfigBoot
    ConfigBoot --> Container
    Container --> Dependence
    Dependence --> Core
    Container --> MWConfig
    MWConfig --> Static
    Container --> RouterConfig
    RouterConfig --> Router
    Container --> ViewConfig
    ViewConfig --> ViewRenderer

    Core --> HttpProc
    Core --> MonProc
    HttpProc --> RequestLoop
    RequestLoop --> Req
    Req --> Static
    Static -->|"asset request"| PublicDir
    PublicDir --> Res
    Static -->|"app request"| OtherMW
    OtherMW --> Router
    Router --> Ctrl
    Ctrl --> Model
    Ctrl --> ViewRenderer
    ViewRenderer --> Template
    Template --> ViewsCache
    ViewsCache --> Res
    Res --> Client
    MonProc -->|"monitors"| HttpProc

    click StartUnix "https://github.com/walkor/webman/blob/master/start.php"
    click StartWin "https://github.com/walkor/webman/blob/master/windows.php"
    click Bootstrap "https://github.com/walkor/webman/blob/master/support/bootstrap.php"
    click HttpProc "https://github.com/walkor/webman/blob/master/app/process/Http.php"
    click MonProc "https://github.com/walkor/webman/blob/master/app/process/Monitor.php"
    click Container "https://github.com/walkor/webman/blob/master/config/container.php"
    click Dependence "https://github.com/walkor/webman/blob/master/config/dependence.php"
    click MWConfig "https://github.com/walkor/webman/blob/master/config/middleware.php"
    click Static "https://github.com/walkor/webman/blob/master/app/middleware/StaticFile.php"
    click RouterConfig "https://github.com/walkor/webman/blob/master/config/route.php"
    click Ctrl "https://github.com/walkor/webman/blob/master/app/controller/IndexController.php"
    click Model "https://github.com/walkor/webman/blob/master/app/model/Test.php"
    click Template "https://github.com/walkor/webman/blob/master/app/view/index/view.html"
    click ViewConfig "https://github.com/walkor/webman/blob/master/config/view.php"
    click PublicDir "https://github.com/walkor/webman/tree/master/public/"
    click Req "https://github.com/walkor/webman/blob/master/support/Request.php"
    click Res "https://github.com/walkor/webman/blob/master/support/Response.php"
    click Logs "https://github.com/walkor/webman/tree/master/runtime/logs/"
    click ViewsCache "https://github.com/walkor/webman/tree/master/runtime/views/"

    classDef framework fill:#bbdefb,stroke:#333,stroke-width:1px,color:#000
    classDef application fill:#c8e6c9,stroke:#333,stroke-width:1px,color:#000
    classDef config fill:#ffe082,stroke:#333,stroke-width:1px,color:#000
    classDef runtime fill:#e0e0e0,stroke:#333,stroke-width:1px,color:#000
    classDef external fill:#f8bbd0,stroke:#333,stroke-width:1px,color:#000
```
