# sibidharan/zealphp architecture

> Architecture diagram of the GitHub repository sibidharan/zealphp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sibidharan/zealphp
- Repository: https://github.com/sibidharan/zealphp

## Overview

ZealPHP is a long-running PHP HTTP server built on OpenSwoole. The principal workflow accepts an HTTP request, dispatches it through middleware and route or file-based API handling, then emits an HTTP response. Its other major product branches include coroutine-safe legacy PHP compatibility and sessions, WebSockets and streaming, shared storage and cross-node messaging, timers, and templating. The README documents these capabilities; unsampled implementation details are represented only where paths are supported, and uncertain connections are omitted.

Main entry points: [`src/App.php`](https://github.com/sibidharan/zealphp/blob/master/src/App.php) (App server), [`src/ResponseMiddleware.php`](https://github.com/sibidharan/zealphp/blob/master/src/ResponseMiddleware.php) (Middleware stack), [`src/Store.php`](https://github.com/sibidharan/zealphp/blob/master/src/Store.php) (Shared Store), [`src/Middleware/Pipeline/ApiDispatchHandler.php`](https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/ApiDispatchHandler.php) (API dispatch)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_app["App server<br/>[App.php]"]
  node_context["Request context<br/>[RequestContext.php]"]
  node_coroutines["Coroutine runtime<br/>[App.php]"]
  node_timers["Timers<br/>[App.php]"]
end

subgraph group_http["HTTP handling"]
  node_middleware["Middleware stack"]
  node_route_dispatch["Route dispatch"]
  node_path_dispatch["Path dispatch"]
  node_api_dispatch["API dispatch"]
  node_zeal_api["ZealAPI endpoints<br/>[ZealAPI.php]"]
  node_request["HTTP request<br/>[Request.php]"]
  node_response["HTTP response<br/>[Response.php]"]
end

subgraph group_state["State and realtime"]
  node_store[("Shared Store<br/>[Store.php]")]
  node_redis[("Redis backend<br/>[RedisBackend.php]")]
  node_redis_client["Redis client<br/>[RedisClient.php]"]
  node_counter[("Shared Counter<br/>[Counter.php]")]
  node_websocket["WebSocket router<br/>[WSRouter.php]"]
end

subgraph group_compat["Compatibility and output"]
  node_sessions["Session manager<br/>[SessionManager.php]"]
  node_legacy["Legacy compatibility<br/>[SessionManager.php]"]
  node_cgi["Legacy CGI workers<br/>[WorkerPool.php]"]
  node_templates["Templating<br/>[App.php]"]
  node_sse["SSE streaming<br/>[Response.php]"]
end

node_client(("HTTP client"))

node_client -->|"sends request"| node_app
node_app -->|"configures middleware"| node_middleware
node_middleware -->|"dispatches routes"| node_route_dispatch
node_middleware -->|"dispatches paths"| node_path_dispatch
node_app -->|"registers API dispatch"| node_api_dispatch
node_api_dispatch -->|"invokes endpoints"| node_zeal_api
node_zeal_api -->|"uses request"| node_request
node_middleware -->|"builds response"| node_response
node_request -.->|"request state"| node_context
node_app -->|"runs coroutines"| node_coroutines
node_app -->|"schedules timers"| node_timers
node_app -->|"supports sessions"| node_sessions
node_sessions -->|"uses request state"| node_context
node_app -->|"isolates legacy state"| node_legacy
node_app -->|"offers CGI mode"| node_cgi
node_app -->|"renders templates"| node_templates
node_response -->|"streams events"| node_sse
node_app -->|"registers WebSockets"| node_websocket
node_websocket -->|"routes shared messages"| node_store
node_app -->|"shares state"| node_store
node_store -->|"selects backend"| node_redis
node_redis -->|"uses client"| node_redis_client
node_app -->|"provides counters"| node_counter

click node_app "https://github.com/sibidharan/zealphp/blob/master/src/App.php"
click node_context "https://github.com/sibidharan/zealphp/blob/master/src/RequestContext.php"
click node_coroutines "https://github.com/sibidharan/zealphp/blob/master/src/App.php"
click node_timers "https://github.com/sibidharan/zealphp/blob/master/src/App.php"
click node_middleware "https://github.com/sibidharan/zealphp/blob/master/src/ResponseMiddleware.php"
click node_route_dispatch "https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/RouteDispatchHandler.php"
click node_path_dispatch "https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/PathDispatchHandler.php"
click node_api_dispatch "https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/ApiDispatchHandler.php"
click node_zeal_api "https://github.com/sibidharan/zealphp/blob/master/src/ZealAPI.php"
click node_request "https://github.com/sibidharan/zealphp/blob/master/src/HTTP/Request.php"
click node_response "https://github.com/sibidharan/zealphp/blob/master/src/HTTP/Response.php"
click node_store "https://github.com/sibidharan/zealphp/blob/master/src/Store.php"
click node_redis "https://github.com/sibidharan/zealphp/blob/master/src/Store/RedisBackend.php"
click node_redis_client "https://github.com/sibidharan/zealphp/blob/master/src/Store/RedisClient.php"
click node_counter "https://github.com/sibidharan/zealphp/blob/master/src/Counter.php"
click node_websocket "https://github.com/sibidharan/zealphp/blob/master/src/WSRouter.php"
click node_sessions "https://github.com/sibidharan/zealphp/blob/master/src/Session/SessionManager.php"
click node_legacy "https://github.com/sibidharan/zealphp/blob/master/src/Session/SessionManager.php"
click node_cgi "https://github.com/sibidharan/zealphp/blob/master/src/CGI/WorkerPool.php"
click node_templates "https://github.com/sibidharan/zealphp/blob/master/src/App.php"
click node_sse "https://github.com/sibidharan/zealphp/blob/master/src/HTTP/Response.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_context,node_coroutines,node_timers,node_client toneBlue
class node_middleware,node_route_dispatch,node_path_dispatch,node_api_dispatch,node_zeal_api,node_request,node_response toneAmber
class node_store,node_redis,node_redis_client,node_counter,node_websocket toneMint
class node_sessions,node_legacy,node_cgi,node_templates,node_sse toneRose
```

## Components

### Server runtime

- [App server](https://github.com/sibidharan/zealphp/blob/master/src/App.php): `src/App.php`
- [Request context](https://github.com/sibidharan/zealphp/blob/master/src/RequestContext.php): `src/RequestContext.php`
- [Coroutine runtime](https://github.com/sibidharan/zealphp/blob/master/src/App.php): `src/App.php`
- [Timers](https://github.com/sibidharan/zealphp/blob/master/src/App.php): `src/App.php`

### HTTP handling

- [Middleware stack](https://github.com/sibidharan/zealphp/blob/master/src/ResponseMiddleware.php): `src/ResponseMiddleware.php`
- [Route dispatch](https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/RouteDispatchHandler.php): `src/Middleware/Pipeline/RouteDispatchHandler.php`
- [Path dispatch](https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/PathDispatchHandler.php): `src/Middleware/Pipeline/PathDispatchHandler.php`
- [API dispatch](https://github.com/sibidharan/zealphp/blob/master/src/Middleware/Pipeline/ApiDispatchHandler.php): `src/Middleware/Pipeline/ApiDispatchHandler.php`
- [ZealAPI endpoints](https://github.com/sibidharan/zealphp/blob/master/src/ZealAPI.php): `src/ZealAPI.php`
- [HTTP request](https://github.com/sibidharan/zealphp/blob/master/src/HTTP/Request.php): `src/HTTP/Request.php`
- [HTTP response](https://github.com/sibidharan/zealphp/blob/master/src/HTTP/Response.php): `src/HTTP/Response.php`

### State and realtime

- [Shared Store](https://github.com/sibidharan/zealphp/blob/master/src/Store.php): `src/Store.php`
- [Redis backend](https://github.com/sibidharan/zealphp/blob/master/src/Store/RedisBackend.php): `src/Store/RedisBackend.php`
- [Redis client](https://github.com/sibidharan/zealphp/blob/master/src/Store/RedisClient.php): `src/Store/RedisClient.php`
- [Shared Counter](https://github.com/sibidharan/zealphp/blob/master/src/Counter.php): `src/Counter.php`
- [WebSocket router](https://github.com/sibidharan/zealphp/blob/master/src/WSRouter.php): `src/WSRouter.php`

### Compatibility and output

- [Session manager](https://github.com/sibidharan/zealphp/blob/master/src/Session/SessionManager.php): `src/Session/SessionManager.php`
- [Legacy compatibility](https://github.com/sibidharan/zealphp/blob/master/src/Session/SessionManager.php): `src/Session/SessionManager.php`
- [Legacy CGI workers](https://github.com/sibidharan/zealphp/blob/master/src/CGI/WorkerPool.php): `src/CGI/WorkerPool.php`
- [Templating](https://github.com/sibidharan/zealphp/blob/master/src/App.php): `src/App.php`
- [SSE streaming](https://github.com/sibidharan/zealphp/blob/master/src/HTTP/Response.php): `src/HTTP/Response.php`

### Other components

- **HTTP client**

## Connections

- HTTP client → App server: sends request (evidence: `README.md`)
- App server → Middleware stack: configures middleware (evidence: `src/ResponseMiddleware.php`)
- Middleware stack → Route dispatch: dispatches routes (evidence: `src/ResponseMiddleware.php`)
- Middleware stack → Path dispatch: dispatches paths (evidence: `src/ResponseMiddleware.php`)
- App server → API dispatch: registers API dispatch (evidence: `src/Middleware/Pipeline/ApiDispatchHandler.php`)
- API dispatch → ZealAPI endpoints: invokes endpoints (evidence: `src/Middleware/Pipeline/ApiDispatchHandler.php`)
- ZealAPI endpoints → HTTP request: uses request (evidence: `src/ZealAPI.php`)
- Middleware stack → HTTP response: builds response (evidence: `src/ResponseMiddleware.php`)
- HTTP request → Request context: request state
- App server → Coroutine runtime: runs coroutines (evidence: `README.md`)
- App server → Timers: schedules timers (evidence: `README.md`)
- App server → Session manager: supports sessions (evidence: `README.md`)
- Session manager → Request context: uses request state (evidence: `src/Session/SessionManager.php`)
- App server → Legacy compatibility: isolates legacy state (evidence: `README.md`)
- App server → Legacy CGI workers: offers CGI mode (evidence: `README.md`)
- App server → Templating: renders templates (evidence: `README.md`)
- HTTP response → SSE streaming: streams events (evidence: `README.md`)
- App server → WebSocket router: registers WebSockets (evidence: `README.md`)
- WebSocket router → Shared Store: routes shared messages (evidence: `src/WSRouter.php`)
- App server → Shared Store: shares state (evidence: `README.md`)
- Shared Store → Redis backend: selects backend (evidence: `src/Store.php`)
- Redis backend → Redis client: uses client (evidence: `src/Store/RedisBackend.php`)
- App server → Shared Counter: provides counters (evidence: `README.md`)
