# qihoo360/evpp architecture

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

- Interactive diagram: https://gitdiagram.com/qihoo360/evpp
- Repository: https://github.com/qihoo360/evpp

## Overview

Based on our review of the complete file tree and README, this project is the “evpp” C++ network library—a high-performance, event-driven framework that provides nonblocking TCP/UDP/HTTP servers and clients. It’s built using modern C++11 techniques and is heavily influenced by designs such as muduo and Golang. The project also includes client libraries that build on evpp (namely “evmc” for memcached and “evnsq” for NSQ) as well as a host of benchmarks, tests, examples, and integration with several third-party dependencies.

##### Main Components Identification
- Core evpp Library: At the center, illustrate the core modules which include:
- EventLoop and ThreadPool: The core reactor pattern that dispatches events.
- TCP/UDP/HTTP servers and clients: Modules that handle network I/O asynchronously.
- Supporting utilities: Buffer, DNS Resolver, Timer, and Invoke Timer.
- Application-Level Libraries: Represent “evmc” and “evnsq” as libraries or applications built on top of the core.
- 3rd Party and Dependencies: Include external components such as libevent, rapidjson, gtest, libhashkit, and platform-specific modules (such as win32code) as dependencies used within the evpp ecosystem.
- Build and Configuration: Elements like CMake scripts, Travis CI configuration, and Visual Studio projects help manage build and deployment.

##### Architectural Relationships and Interactions
- The Core evpp Library should be placed as the central block where all network components reside. Show that:
- The EventLoop is responsible for monitoring network events (using event watchers and libevent internally) and dispatching them to the appropriate handler.
- The ThreadPool or EventLoopThreadPool handles multi-threading, ensuring thread safety by confining event-related operations to their own threads.
- Callback mechanisms, in a functional style similar to Golang, are used to process data received on TCP/UDP sockets.
- Downstream Libraries “evmc” and “evnsq” are built on top of the evpp core, leveraging its asynchronous networking for specialized use cases (memcached client operations and NSQ messaging).

##### Design Patterns and Technical Stack
- Nonblocking, event-driven architecture at the heart of evpp. Note that:
- Components such as the TCP and HTTP servers follow a reactor pattern utilizing callbacks.
- Thread-safety is achieved through careful design where resources (like timers or events) are bound to the thread’s local storage.
- Use of modern C++11 features like lambda expressions to implement callbacks.
- Integration with the libevent library (even though evpp implements its own IO buffer and event add/del functions for driving performance).

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "evpp Core"
        subgraph "Event Handling"
            EVLoop["EventLoop"]:::core
            ThreadPool["ThreadPool"]:::core
            EVThread["EventLoopThread"]:::core
        end
        subgraph "Network I/O Modules"
            TCPServer["TCP Server"]:::core
            TCPClient["TCP Client"]:::core
            UDPServer["UDP Server"]:::core
            UDPClient["UDP Client"]:::core
            HTTPServer["HTTP Server"]:::core
            HTTPClient["HTTP Client"]:::core
        end
        subgraph "Supporting Utilities"
            Buffer["Buffer"]:::core
            DNS["DNS Resolver"]:::core
            Timer["Invoke Timer"]:::core
            Connector["Connector"]:::core
            Logging["Logging"]:::core
        end
    end

    subgraph "Client/Application Libraries"
        evmc["evmc"]:::app
        evnsq["evnsq"]:::app
    end

    subgraph "Examples/Benchmarks/Tests"
        Examples["Examples"]:::external
        Benchmarks["Benchmarks"]:::external
        Tests["Tests"]:::external
    end

    subgraph "Build & Configuration"
        Build["Build Scripts & Config"]:::build
        VS["Visual Studio Projects"]:::build
    end

    subgraph "3rd Party & Dependencies"
        ThirdParty["Third Party Libraries"]:::external
    end

    %% Core interactions: Network I/O modules send events to EventLoop
    TCPServer -->|"sends_event"| EVLoop
    TCPClient -->|"sends_event"| EVLoop
    UDPServer -->|"notifies_event"| EVLoop
    UDPClient -->|"sends_event"| EVLoop
    HTTPServer -->|"sends_event"| EVLoop
    HTTPClient -->|"sends_event"| EVLoop

    %% EventLoop dispatches tasks to ThreadPool
    EVLoop -->|"dispatches"| ThreadPool

    %% Application libraries leverage the core
    evmc -->|"leverages"| EVLoop
    evnsq -->|"leverages"| EVLoop

    %% Examples, Benchmarks and Tests exercise core functionalities
    Examples -->|"exercise"| EVLoop
    Benchmarks -->|"exercise"| EVLoop
    Tests -->|"verify"| EVLoop

    %% Build configuration drives the core build process
    Build -->|"builds"| EVLoop
    VS -->|"builds"| EVLoop

    %% 3rd Party Libraries support core operations
    ThirdParty -->|"supports"| EVLoop

    %% Additional interactions for utilities
    TCPServer -.->|"uses"| Buffer
    UDPClient -.->|"uses"| Connector
    HTTPClient -.->|"uses"| DNS
    EVLoop -->|"schedules"| Timer
    TCPServer -->|"logs_to"| Logging

    %% Click Events for Core evpp Library – Event Handling
    click EVLoop "https://github.com/qihoo360/evpp/blob/master/evpp/event_loop.h"
    click ThreadPool "https://github.com/qihoo360/evpp/blob/master/evpp/event_loop_thread_pool.h"
    click EVThread "https://github.com/qihoo360/evpp/blob/master/evpp/event_loop_thread.h"

    %% Click Events for Core evpp Library – Network I/O Modules
    click TCPServer "https://github.com/qihoo360/evpp/blob/master/evpp/tcp_server.h"
    click TCPClient "https://github.com/qihoo360/evpp/blob/master/evpp/tcp_client.h"
    click UDPServer "https://github.com/qihoo360/evpp/blob/master/evpp/udp/udp_server.h"
    click UDPClient "https://github.com/qihoo360/evpp/blob/master/evpp/udp/sync_udp_client.h"
    click HTTPServer "https://github.com/qihoo360/evpp/blob/master/evpp/http/http_server.h"
    click HTTPClient "https://github.com/qihoo360/evpp/blob/master/evpp/httpc/request.h"

    %% Click Events for Core evpp Library – Supporting Utilities
    click Buffer "https://github.com/qihoo360/evpp/blob/master/evpp/buffer.h"
    click DNS "https://github.com/qihoo360/evpp/blob/master/evpp/dns_resolver.h"
    click Timer "https://github.com/qihoo360/evpp/blob/master/evpp/invoke_timer.h"
    click Connector "https://github.com/qihoo360/evpp/blob/master/evpp/connector.h"
    click Logging "https://github.com/qihoo360/evpp/blob/master/evpp/logging.h"

    %% Click Events for Client/Application-Level Libraries
    click evmc "https://github.com/qihoo360/evpp/tree/master/apps/evmc"
    click evnsq "https://github.com/qihoo360/evpp/tree/master/apps/evnsq"

    %% Click Events for Examples, Benchmarks, and Tests
    click Examples "https://github.com/qihoo360/evpp/tree/master/examples/"
    click Benchmarks "https://github.com/qihoo360/evpp/tree/master/benchmark/"
    click Tests "https://github.com/qihoo360/evpp/tree/master/test/"

    %% Click Events for Build and Configuration
    click Build "https://github.com/qihoo360/evpp/blob/master/CMakeLists.txt"
    click VS "https://github.com/qihoo360/evpp/tree/master/vsprojects/"

    %% Click Event for 3rd Party and External Dependencies
    click ThirdParty "https://github.com/qihoo360/evpp/tree/master/3rdparty/"

    %% Styles
    classDef core fill:#FAD,stroke:#333,stroke-width:2px;
    classDef app fill:#9F6,stroke:#333,stroke-width:2px;
    classDef external fill:#FF9,stroke:#333,stroke-width:2px;
    classDef build fill:#9FF,stroke:#333,stroke-width:2px;
```
