# johnponggit/zltoolkit architecture

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

- Interactive diagram: https://gitdiagram.com/johnponggit/zltoolkit
- Repository: https://github.com/johnponggit/zltoolkit

## Overview

##### Main Components
- Network Layer:
- Modules under the “src/Network” directory include classes for handling buffers, socket operations, TCP/UDP servers and clients, and session management.
- Components like Buffer, Socket, TcpClient, TcpServer, UdpServer, and the session logic.

- Poller/Event Loop:
- Under “src/Poller” you have event pollers (e.g., EventPoller, SelectWrap) and utilities like timers and pipes.
- This component is critical as it manages non-blocking IO and multiplexing (epoll on Linux, kqueue on macOS, etc.).

- Thread Management:
- The “src/Thread” directory contains thread pool implementations, task executors, and supporting types.
- Asynchronous task execution mechanisms and interactions with the poller and network components.

- Utility Functions:
- The “src/Util” directory includes logging, command line parsing, file operations, crypto utilities (MD5, SHA1), SQL connection pooling, and SSL utilities.
- How these utilities support the core components by providing logging, configuration support, and security (SSL encapsulation).

##### Relationships and Interactions
- Data Flow:
- From the Network modules to the Poller modules since network IO is managed by the event loop.
- From both the Network and Poller components to the Thread components for offloading tasks.
- How utility modules are shared among all layers for logging, file configuration, encryption/decryption, etc.

##### Architectural Patterns and Design Principles
- The framework follows a modular design where distinct libraries (networking, polling, threading, utilities) are decoupled.
- It leverages asynchronous IO combined with a thread pool to maximize concurrency.
- Emphasis on robust error handling, resource pooling, and cross-platform compatibility through abstraction and conditional compilation.

##### Incorporate Platform-specific Tooling and Build Configuration
- Presence of multiple build scripts (build_for_android.sh, build_for_ios.sh, etc.) that tailor the builds for different target platforms.
- You might optionally include a separate block (or note) for Continuous Integration (CI) setups seen in the .github/workflows directory and the .travis.yml file.

##### Essential Architectural Elements
- Link it directly to the event handling and threading mechanisms.
- How utility functions integrate with these components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Network Layer
    subgraph "Network Layer"
        N1["Buffer: Memory management"]:::network
        N2["Socket: Low-level Socket Ops"]:::network
        N3["TcpClient: Handles TCP client comm"]:::network
        N4["TcpServer: Handles TCP server comm"]:::network
        N5["UdpServer: Handles UDP comm"]:::network
        N6["Session: Session management"]:::network
    end

    %% Poller/Event Loop
    subgraph "Poller/Event Loop"
        P1["EventPoller: Manages async IO"]:::poller
        P2["SelectWrap: Abstraction for select"]:::poller
        P3["Timer: Schedules tasks"]:::poller
        P4["Pipe: Inter-process communication"]:::poller
        P5["PipeWrap: Wraps pipe functionality"]:::poller
    end

    %% Thread Management
    subgraph "Thread Management"
        T1["TaskExecutor: Executes async tasks"]:::thread
        T2["TaskQueue: Task scheduling"]:::thread
        T3["ThreadPool: Manages threads"]:::thread
        T4["WorkThreadPool: Worker threads management"]:::thread
        T5["Semaphore: Concurrency control"]:::thread
        T6["ThreadGroup: Group of threads"]:::thread
    end

    %% Utility Functions
    subgraph "Utility Functions"
        U1["Utilities: Logging, CLI, FileOps, Crypto, SQL, SSL"]:::util
    end

    %% Relationships and Data Flow
    N4 -->|"io"| P1
    N3 -->|"async_task"| T2
    P1 -->|"async_offload"| T1

    %% All layers utilizing utility functions
    N4 -->|"utilize"| U1
    P1 -->|"utilize"| U1
    T1 -->|"utilize"| U1

    %% Styles
    classDef network fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef poller fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef thread fill:#FFD580,stroke:#FFA500,stroke-width:2px;
    classDef util fill:#D3D3D3,stroke:#808080,stroke-width:2px;

    %% Click Events for Network Layer Components
    click N1 "https://github.com/johnponggit/zltoolkit/tree/master/src/Network"
    click N2 "https://github.com/johnponggit/zltoolkit/tree/master/src/Network"
    click N3 "https://github.com/johnponggit/zltoolkit/tree/master/src/Network"
    click N4 "https://github.com/johnponggit/zltoolkit/tree/master/src/Network"
    click N5 "https://github.com/johnponggit/zltoolkit/tree/master/src/Network"
    click N6 "https://github.com/johnponggit/zltoolkit/tree/master/src/Network"

    %% Click Events for Poller/Event Loop Components
    click P1 "https://github.com/johnponggit/zltoolkit/tree/master/src/Poller"
    click P2 "https://github.com/johnponggit/zltoolkit/tree/master/src/Poller"
    click P3 "https://github.com/johnponggit/zltoolkit/tree/master/src/Poller"
    click P4 "https://github.com/johnponggit/zltoolkit/tree/master/src/Poller"
    click P5 "https://github.com/johnponggit/zltoolkit/tree/master/src/Poller"

    %% Click Events for Thread Management Components
    click T1 "https://github.com/johnponggit/zltoolkit/tree/master/src/Thread"
    click T2 "https://github.com/johnponggit/zltoolkit/tree/master/src/Thread"
    click T3 "https://github.com/johnponggit/zltoolkit/tree/master/src/Thread"
    click T4 "https://github.com/johnponggit/zltoolkit/tree/master/src/Thread"
    click T5 "https://github.com/johnponggit/zltoolkit/tree/master/src/Thread"
    click T6 "https://github.com/johnponggit/zltoolkit/tree/master/src/Thread"

    %% Click Event for Utility Functions
    click U1 "https://github.com/johnponggit/zltoolkit/tree/master/src/Util"
```
