# vincentwuo/evproxy architecture

> Architecture diagram of the GitHub repository vincentwuo/evproxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vincentwuo/evproxy
- Repository: https://github.com/vincentwuo/evproxy

## Overview

##### Main Components Identification

a) Core Proxy Components:
- Listener Layer (Main Entry Point)
- Worker Pool
- Connection Handler
- Event Engine (Epoll-based)
- Load Balancer

b) Supporting Components:
- BytePool (Memory Management)
- Network Interface Controller (NIC) Management
- Configuration Management

**┌─────────────────────────────────────────────┐**
- Client Connections          │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Listener (TCP)                 │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Worker Pool                    │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Event Engine (Epoll)     │   BytePool   │
- ┼──────────────┤
- Connection Handler       │   IP Hash LB  │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Upstream Servers               │
- ┘

##### Important Details

a) Connection Flow:
- How incoming connections are accepted at the listener
- Connection distribution to workers
- Demonstrate event handling through epoll
- Connection to upstream servers

b) Memory Management:
- BytePool's role in reducing memory usage
- Buffer allocation/deallocation paths

c) Performance Features:
- Where concurrent processing occurs
- Load balancing decision points
- Points where timeout controls are implemented

##### Technical Specifications to Note
- Memory optimization points
- Load balancer with "IP Hash" strategy
- Timeout and speed limiting control points

##### Additional Elements

A side panel showing:
- Configuration options
- Performance metrics
- Resource limits
- Timeout settings

##### Specific Implementation Details

- The event-driven nature of the proxy
- How it achieves 8x less memory usage
- Worker pool configuration
- Connection pooling strategy

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        Client[Client Connections]:::external
        Upstream[Upstream Servers]:::external
    end

    subgraph Core["Core Proxy System"]
        Listener["Main Listener (TCP)"]:::network
        click Listener "https://github.com/vincentwuo/evproxy/blob/main/cmd/evproxy/main.go"

        subgraph WorkerSystem["Worker Management"]
            WorkerPool["Worker Pool"]:::worker
            click WorkerPool "https://github.com/vincentwuo/evproxy/blob/main/worker.go"
        end

        subgraph EventSystem["Event Processing System"]
            EventEngine["Event Engine (Epoll)"]:::engine
            click EventEngine "https://github.com/vincentwuo/evproxy/blob/main/internal/engine/epoll_linux.go"
            
            Timer["Timer Management"]:::engine
            click Timer "https://github.com/vincentwuo/evproxy/blob/main/internal/engine/timer.go"
            
            ConnHandler["Connection Handler"]:::network
            click ConnHandler "https://github.com/vincentwuo/evproxy/blob/main/conn.go"
        end

        subgraph Support["Support Systems"]
            BytePool["BytePool Memory Manager"]:::memory
            click BytePool "https://github.com/vincentwuo/evproxy/blob/main/pkg/bytepool/pool.go"
            
            LoadBalancer["IP Hash Load Balancer"]:::lb
            click LoadBalancer "https://github.com/vincentwuo/evproxy/blob/main/pkg/lb/iphash.go"
            
            NICManager["NIC Manager"]:::network
            click NICManager "https://github.com/vincentwuo/evproxy/blob/main/pkg/nic/manage.go"
            
            Logger["Logging System"]:::util
            click Logger "https://github.com/vincentwuo/evproxy/blob/main/pkg/util/logger.go"
            
            Atomic["Atomic Operations"]:::util
            click Atomic "https://github.com/vincentwuo/evproxy/blob/main/pkg/concurrent/atomic.go"
        end
    end

    %% Connections
    Client --> Listener
    Listener --> WorkerPool
    WorkerPool --> EventEngine
    EventEngine --> ConnHandler
    ConnHandler --> LoadBalancer
    LoadBalancer --> Upstream
    
    %% Support System Connections
    ConnHandler -.-> BytePool
    EventEngine -.-> Timer
    ConnHandler -.-> NICManager
    EventEngine -.-> Atomic
    Core -.-> Logger

    %% Styles
    classDef external fill:#gray,stroke:#333,stroke-width:2px
    classDef network fill:#3498db,stroke:#2980b9,stroke-width:2px
    classDef engine fill:#e74c3c,stroke:#c0392b,stroke-width:2px
    classDef memory fill:#2ecc71,stroke:#27ae60,stroke-width:2px
    classDef lb fill:#e67e22,stroke:#d35400,stroke-width:2px
    classDef worker fill:#9b59b6,stroke:#8e44ad,stroke-width:2px
    classDef util fill:#95a5a6,stroke:#7f8c8d,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[External Components]:::external
        L2[Network Components]:::network
        L3[Event Engine Components]:::engine
        L4[Memory Management]:::memory
        L5[Load Balancing]:::lb
        L6[Worker Management]:::worker
        L7[Utility Components]:::util
    end
```
