# walkor/workerman architecture

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

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

## Overview

##### Main Components

a) Core Components:
- Worker Class (Central Component)
- Event Loop System
- Connection Management
- Protocol Handlers
- Timer System

b) Connection Types:
- TCP Connections
- UDP Connections
- Async Connections
- WebSocket Connections
- HTTP Connections

c) Protocol Layer:
- HTTP Protocol
- WebSocket Protocol
- Custom Protocol Support
- Frame Protocol
- Text Protocol

**┌─────────────────────────────────────────────────────────┐**
- Application Layer                      │
- (User Implementation: HTTP/WebSocket/Custom Servers)    │
- ┤
- Worker Layer                         │
- (Process Management & Event Distribution)        │
- ┤
- Protocol Layer                        │
- (HTTP, WebSocket, Custom Protocol Handlers)          │
- ┤
- Connection Layer                       │
- (TCP, UDP, Async Connections Management)            │
- ┤
- Event Layer                          │
- (Event Loop: Ev, Select, Swoole, Swow, Revolt)     │
- ┘

##### Component Relationships

- Worker → Event Loop (dependency)
- Worker → Connection Management (composition)
- Connection → Protocol Handlers (usage)
- Protocol Handlers → Session Handlers (optional usage)
- Timer → Event Loop (integration)

##### Implementation Details to Highlight

- Multi-process architecture
- Event-driven nature
- Protocol abstraction
- Connection lifecycle
- Timer implementation
- SSL/TLS support

##### Additional Elements

- Notes about scalability and process management
- External service integration points (Redis, proxy support)
- Where custom protocol handlers can be added

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#4d88ff
    classDef connection fill:#b3ffb3,stroke:#4dff4d
    classDef protocol fill:#ffd9b3,stroke:#ffb366
    classDef event fill:#e6b3ff,stroke:#cc66ff
    classDef http fill:#ffb3b3,stroke:#ff6666
    classDef session fill:#ffffb3,stroke:#ffff66

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        UserApp["User Applications"]
    end

    %% Worker Layer
    subgraph WorkerLayer["Worker Layer"]
        Worker["Worker Class"]:::core
        Timer["Timer System"]:::core
    end

    %% Protocol Layer
    subgraph ProtocolLayer["Protocol Layer"]
        ProtocolInterface["Protocol Interface"]:::protocol
        HTTP["HTTP Protocol"]:::protocol
        WebSocket["WebSocket Protocol"]:::protocol
        Frame["Frame Protocol"]:::protocol
        Text["Text Protocol"]:::protocol
    end

    %% HTTP Components
    subgraph HTTPComponents["HTTP Components"]
        Request["Request Handler"]:::http
        Response["Response Handler"]:::http
        Chunk["Chunk Handler"]:::http
        SSE["Server Sent Events"]:::http
    end

    %% Session Layer
    subgraph SessionLayer["Session Management"]
        SessionInterface["Session Interface"]:::session
        FileSession["File Session Handler"]:::session
        RedisSession["Redis Session Handler"]:::session
        RedisClusterSession["Redis Cluster Handler"]:::session
    end

    %% Connection Layer
    subgraph ConnectionLayer["Connection Layer"]
        ConnectionInterface["Connection Interface"]:::connection
        TCP["TCP Connection"]:::connection
        UDP["UDP Connection"]:::connection
        AsyncTCP["Async TCP Connection"]:::connection
        AsyncUDP["Async UDP Connection"]:::connection
    end

    %% Event Layer
    subgraph EventLayer["Event Layer"]
        EventInterface["Event Interface"]:::event
        Ev["Ev Implementation"]:::event
        Select["Select Implementation"]:::event
        Swoole["Swoole Implementation"]:::event
        Swow["Swow Implementation"]:::event
        Revolt["Revolt Implementation"]:::event
    end

    %% Relationships
    UserApp --> Worker
    Worker --> Timer
    Worker --> ConnectionInterface
    Worker --> EventInterface
    ConnectionInterface --> ProtocolInterface
    HTTP --> Request
    HTTP --> Response
    HTTP --> Chunk
    HTTP --> SSE
    HTTP --> SessionInterface
    SessionInterface --> FileSession
    SessionInterface --> RedisSession
    SessionInterface --> RedisClusterSession
    ProtocolInterface --> HTTP
    ProtocolInterface --> WebSocket
    ProtocolInterface --> Frame
    ProtocolInterface --> Text
    ConnectionInterface --> TCP
    ConnectionInterface --> UDP
    ConnectionInterface --> AsyncTCP
    ConnectionInterface --> AsyncUDP
    EventInterface --> Ev
    EventInterface --> Select
    EventInterface --> Swoole
    EventInterface --> Swow
    EventInterface --> Revolt

    %% Click Events
    click Worker "https://github.com/walkor/workerman/blob/master/src/Worker.php"
    click Timer "https://github.com/walkor/workerman/blob/master/src/Timer.php"
    click EventInterface "https://github.com/walkor/workerman/blob/master/src/Events/EventInterface.php"
    click Ev "https://github.com/walkor/workerman/blob/master/src/Events/Ev.php"
    click Select "https://github.com/walkor/workerman/blob/master/src/Events/Select.php"
    click Swoole "https://github.com/walkor/workerman/blob/master/src/Events/Swoole.php"
    click Swow "https://github.com/walkor/workerman/blob/master/src/Events/Swow.php"
    click Revolt "https://github.com/walkor/workerman/blob/master/src/Events/Revolt.php"
    click ConnectionInterface "https://github.com/walkor/workerman/blob/master/src/Connection/ConnectionInterface.php"
    click TCP "https://github.com/walkor/workerman/blob/master/src/Connection/TcpConnection.php"
    click UDP "https://github.com/walkor/workerman/blob/master/src/Connection/UdpConnection.php"
    click AsyncTCP "https://github.com/walkor/workerman/blob/master/src/Connection/AsyncTcpConnection.php"
    click AsyncUDP "https://github.com/walkor/workerman/blob/master/src/Connection/AsyncUdpConnection.php"
    click ProtocolInterface "https://github.com/walkor/workerman/blob/master/src/Protocols/ProtocolInterface.php"
    click HTTP "https://github.com/walkor/workerman/blob/master/src/Protocols/Http.php"
    click WebSocket "https://github.com/walkor/workerman/blob/master/src/Protocols/Websocket.php"
    click Frame "https://github.com/walkor/workerman/blob/master/src/Protocols/Frame.php"
    click Text "https://github.com/walkor/workerman/blob/master/src/Protocols/Text.php"
    click Request "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Request.php"
    click Response "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Response.php"
    click Chunk "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Chunk.php"
    click SSE "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/ServerSentEvents.php"
    click SessionInterface "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Session/SessionHandlerInterface.php"
    click FileSession "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Session/FileSessionHandler.php"
    click RedisSession "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Session/RedisSessionHandler.php"
    click RedisClusterSession "https://github.com/walkor/workerman/blob/master/src/Protocols/Http/Session/RedisClusterSessionHandler.php"
```
