# whyvl/wireproxy architecture

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

- Interactive diagram: https://gitdiagram.com/whyvl/wireproxy
- Repository: https://github.com/whyvl/wireproxy

## Overview

##### Project type and purpose
- This is a Go‐based, userspace WireGuard client daemon (wireproxy) that exposes:
- SOCKS5 and HTTP proxy servers
- TCP “client” and “server” tunnels
- A health/metrics HTTP endpoint
- It does _not_ create a network interface; it keeps everything in userspace and routes proxy or tunnel traffic through a WireGuard peer.

##### File structure
- cmd/wireproxy/main.go: CLI entrypoint
- config.go / config_test.go: configuration loading & validation
- wireguard.go: userspace WireGuard session management
- net.go / routine.go: core networking logic, routing packets into tunnels & proxies
- http.go: HTTP proxy & health/metrics endpoint
- util.go: shared helpers
- Dockerfile, Makefile, systemd/ and rc.d/ folders: packaging/deployment
- tests & GitHub Actions workflows: CI, linting, build, container publishing

##### README for additional insights
- Describes feature set: “TCP static routing,” “SOCKS5/HTTP proxy,” health endpoints
- Explains CLI flags, sample config file sections (Interface, Peer, Socks5, http, TCPClientTunnel, TCPServerTunnel, STDIOTunnel, health endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "wireproxy Daemon"
        CLI["CLI Entrypoint"]:::userspace
        Config["Config Loader & Validator"]:::config
        ConfigTest["Config Tests"]:::infra
        WG["WireGuard Core"]:::engine
        Tunnel["Tunnel Manager"]:::userspace
        Routine["Packet Routing Routines"]:::infra
        Proxy["Proxy Servers & HTTP/Health"]:::userspace
        Util["Shared Helpers"]:::infra
    end

    subgraph "External Systems"
        Client["Client Apps"]:::external
        Peer["WireGuard Peer Endpoint"]:::external
    end

    subgraph "Deployment"
        Docker["Docker Container Build"]:::infra
        Make["Makefile"]:::infra
        SD["systemd Service"]:::infra
        RC["SysV Init Scripts"]:::infra
    end

    CI["CI Workflows"]:::infra

    %% Data Flow
    CLI -->|"parses flags"| Config
    Config -->|"in-memory config"| WG
    ConfigTest -.-> Config
    Util -.-> CLI
    Util -.-> Config
    Util -.-> WG
    Util -.-> Tunnel
    Util -.-> Proxy

    Client -->|"SOCKS5/HTTP/TCP"| Proxy
    Client -->|"TCP Tunnel"| Tunnel

    Proxy -->|"forwards data"| WG
    Tunnel -->|"forwards data"| WG
    WG -->|"encrypted UDP packets"| Peer
    Peer -->|"UDP responses"| WG
    WG -->|"decrypted responses"| Proxy
    WG -->|"decrypted responses"| Tunnel
    Proxy -->|"health & metrics queries"| WG

    %% Deployment Flows
    Docker --> CLI
    Make --> CLI
    SD --> CLI
    RC --> CLI
    CI --> CLI

    %% Click Events
    click CLI "https://github.com/whyvl/wireproxy/blob/master/cmd/wireproxy/main.go"
    click Config "https://github.com/whyvl/wireproxy/blob/master/config.go"
    click ConfigTest "https://github.com/whyvl/wireproxy/blob/master/config_test.go"
    click WG "https://github.com/whyvl/wireproxy/blob/master/wireguard.go"
    click Tunnel "https://github.com/whyvl/wireproxy/blob/master/net.go"
    click Routine "https://github.com/whyvl/wireproxy/blob/master/routine.go"
    click Proxy "https://github.com/whyvl/wireproxy/blob/master/http.go"
    click Util "https://github.com/whyvl/wireproxy/blob/master/util.go"
    click Docker "https://github.com/whyvl/wireproxy/tree/master/Dockerfile"
    click Make "https://github.com/whyvl/wireproxy/tree/master/Makefile"
    click SD "https://github.com/whyvl/wireproxy/blob/master/systemd/wireproxy.service"
    click RC "https://github.com/whyvl/wireproxy/tree/master/rc.d/wireproxy"
    click CI "https://github.com/whyvl/wireproxy/tree/master/.github/workflows/"

    %% Styles
    classDef userspace fill:#b2f5b0,stroke:#333
    classDef engine fill:#bee3f8,stroke:#333
    classDef config fill:#e2e8f0,stroke:#333
    classDef external stroke-dasharray: 5 5,stroke:#666
    classDef infra fill:#fefcbf,stroke:#333
```
