# yusing/go-proxy architecture

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

- Interactive diagram: https://gitdiagram.com/yusing/go-proxy
- Repository: https://github.com/yusing/go-proxy

## Overview

##### Main Components Identification

The system should be divided into these major components:

a) Core Proxy Engine
- Reverse Proxy Handler
- TCP/UDP Forwarders
- SSL/TLS Manager (Autocert)
- Docker Integration
- Configuration Manager

b) Web Interface
- API Layer
- Authentication System
- Dashboard UI
- Configuration Editor

##### Key Architectural Elements

a) Modular Architecture:
- Internal packages are well-separated (/internal directory)
- Clear separation of concerns (api, config, docker, metrics, etc.)
- Middleware-based request processing

b) Event-Driven System:
- Watchers for configuration changes
- Docker container state monitoring
- Health checking system

**┌─────────────────────────────────────────────────────────────┐**
- Client Requests                         │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Entry Points Layer                       │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐        │
- HTTP/HTTPS │  │    TCP      │  │    UDP      │        │
- ┘  └─────────────┘  └─────────────┘        │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Core Proxy Layer                         │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐        │
- Middleware │  │   Routing   │  │ Load Balance │        │
- ┘  └─────────────┘  └─────────────┘        │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Service Layer                            │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐        │
- Docker    │  │  AutoCert   │  │   Metrics   │        │
- ┘  └─────────────┘  └─────────────┘        │
- ┘

##### Component Interactions

- Client request flow through the system
- Configuration updates and hot-reload paths
- Docker container management flow
- Metrics collection paths
- SSL certificate management flow

##### Special Features Highlight

- IdleSleeper functionality
- Auto SSL certification management
- Docker auto-configuration
- Health monitoring system

##### Additional Elements

Supporting components:
- Configuration stores
- Certificate storage
- Metrics endpoints
- WebUI components
- Authentication flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Requests]
    end

    subgraph "Entry Points"
        HTTP["HTTP/HTTPS Entry"]:::entry
        TCP["TCP Entry"]:::entry
        UDP["UDP Entry"]:::entry
    end

    subgraph "Core Layer"
        RP["Reverse Proxy"]:::core
        TF["TCP Forwarder"]:::core
        UF["UDP Forwarder"]:::core
        LB["Load Balancer"]:::core
        MW["Middleware"]:::core
        RM["Route Manager"]:::core
        AL["Access Logger"]:::core
    end

    subgraph "Service Layer"
        DI["Docker Integration"]:::service
        AC["AutoCert Manager"]:::service
        MS["Metrics System"]:::service
        HS["Health System"]:::service
        ES["Event System"]:::service
        IS["Idle Sleeper"]:::service
        CM["Config Manager"]:::service
    end

    subgraph "Web Interface"
        API["API Layer"]:::web
        AUTH["Authentication"]:::web
        DASH["Dashboard/Homepage"]:::web
    end

    C --> HTTP & TCP & UDP
    HTTP --> RP
    TCP --> TF
    UDP --> UF

    RP & TF & UF --> MW
    MW --> RM
    RM --> LB
    LB --> AL

    RP & TF & UF -.-> DI
    RP --> AC
    RP & TF & UF -.-> MS
    DI --> HS
    DI --> IS
    HS & IS --> ES
    ES --> CM

    HTTP --> API
    API --> AUTH
    API --> DASH
    
    classDef entry fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef service fill:#FF9800,stroke:#EF6C00,color:white
    classDef web fill:#9C27B0,stroke:#6A1B9A,color:white

    click RP "https://github.com/yusing/go-proxy/blob/v0.8/internal/net/http/reverseproxy/reverse_proxy_mod.go"
    click HTTP "https://github.com/yusing/go-proxy/blob/v0.8/internal/route/entry/reverse_proxy.go"
    click TF "https://github.com/yusing/go-proxy/blob/v0.8/internal/route/stream.go"
    click UF "https://github.com/yusing/go-proxy/blob/v0.8/internal/route/udp_forwarder.go"
    click AC "https://github.com/yusing/go-proxy/tree/v0.8/internal/autocert"
    click DI "https://github.com/yusing/go-proxy/tree/v0.8/internal/docker"
    click CM "https://github.com/yusing/go-proxy/tree/v0.8/internal/config"
    click API "https://github.com/yusing/go-proxy/tree/v0.8/internal/api"
    click AUTH "https://github.com/yusing/go-proxy/tree/v0.8/internal/api/v1/auth"
    click LB "https://github.com/yusing/go-proxy/tree/v0.8/internal/net/http/loadbalancer"
    click MW "https://github.com/yusing/go-proxy/tree/v0.8/internal/net/http/middleware"
    click HS "https://github.com/yusing/go-proxy/tree/v0.8/internal/watcher/health"
    click MS "https://github.com/yusing/go-proxy/tree/v0.8/internal/metrics"
    click ES "https://github.com/yusing/go-proxy/tree/v0.8/internal/watcher/events"
    click DASH "https://github.com/yusing/go-proxy/tree/v0.8/internal/homepage"
    click IS "https://github.com/yusing/go-proxy/tree/v0.8/internal/docker/idlewatcher"
    click AL "https://github.com/yusing/go-proxy/tree/v0.8/internal/net/http/accesslog"
    click RM "https://github.com/yusing/go-proxy/tree/v0.8/internal/route"
```
