# evgenydarkstar/discord-tunnel architecture

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

- Interactive diagram: https://gitdiagram.com/evgenydarkstar/discord-tunnel
- Repository: https://github.com/evgenydarkstar/discord-tunnel

## Overview

Discord Tunnel routes Discord-only traffic from a Windows client through an embedded Rust runtime to a self-hosted Linux QUIC/HTTP/3 server, then onward to allowed Discord destinations. The client installer configures the Discord-side module; native hooks intercept TCP/UDP sockets, while Rust provides session handling, protocol encoding, transport and loopback bridges. Server authentication, destination policy and certificate setup are distinct stages. README statements and indexed imports support the documented links; unsampled implementation details are not assumed.

Main entry points: [`client/discord/hook/native/hooks.cpp`](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/hooks.cpp) (Socket hooks), [`server/app/discord_http3.py`](https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/discord_http3.py) (HTTP/3 server), [`client/discord/runtime/src/runtime.rs`](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/runtime.rs) (Session runtime), [`client/discord/hook/native/dllmain.cpp`](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/dllmain.cpp) (DLL entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client_setup["Client setup"]
  node_installer["Client installer<br/>[main.cpp]"]
  node_client_config["Client configuration<br/>[config.cpp]"]
  node_filesystem["Filesystem utilities<br/>[fs_utils.cpp]"]
end

subgraph group_client_runtime["Windows client runtime"]
  node_native_entry["DLL entry<br/>[dllmain.cpp]"]
  node_native_hooks["Socket hooks<br/>[hooks.cpp]"]
  node_socket_state["Socket tracking<br/>[socket_manager.cpp]"]
  node_udp_strategy["UDP strategies<br/>[udp_strategy.cpp]"]
  node_socks_udp["SOCKS5 UDP<br/>[socks5_udp.cpp]"]
  node_native_config["DLL configuration<br/>[config.cpp]"]
  node_native_runtime["Runtime FFI bridge"]
end

subgraph group_rust_runtime["Embedded Rust runtime"]
  node_ffi["C ABI<br/>[ffi.rs]"]
  node_embedded["Loopback bridges<br/>[embedded.rs]"]
  node_runtime["Session runtime<br/>[runtime.rs]"]
  node_session["Session lifecycle<br/>[session.rs]"]
  node_queue["Command event queue<br/>[queue.rs]"]
  node_transport["QUIC HTTP/3 transport<br/>[transport.rs]"]
  node_protocol["Wire protocol<br/>[protocol.rs]"]
end

subgraph group_server["Tunnel server"]
  node_server_http3["HTTP/3 server<br/>[discord_http3.py]"]
  node_server_config["Server policy config<br/>[config.py]"]
  node_server_certs["Certificate setup<br/>[certs.py]"]
  node_server_protocol["Server protocol"]
end

node_user(("Windows user"))
node_discord(("Discord app"))
node_discord_services(("Discord services"))

node_user -->|"configures client"| node_installer
node_installer -->|"writes settings"| node_client_config
node_installer -->|"uses file helpers"| node_filesystem
node_discord -->|"loads module"| node_native_entry
node_native_entry -.->|"loads settings"| node_native_config
node_native_entry -->|"initializes hooks"| node_native_hooks
node_native_entry -->|"starts runtime"| node_native_runtime
node_native_hooks -->|"calls bridge"| node_native_runtime
node_native_hooks -->|"tracks sockets"| node_socket_state
node_native_hooks -->|"uses strategy"| node_udp_strategy
node_native_hooks -.->|"uses UDP framing"| node_socks_udp
node_native_runtime -->|"calls ABI"| node_ffi
node_ffi -->|"opens bridges"| node_embedded
node_ffi -->|"forwards commands"| node_runtime
node_embedded -->|"dispatches bridge commands"| node_runtime
node_runtime -->|"creates sessions"| node_session
node_runtime -->|"drains commands"| node_queue
node_runtime -->|"drives transport"| node_transport
node_transport -->|"encodes datagrams"| node_protocol
node_transport -->|"QUIC HTTP/3"| node_server_http3
node_server_http3 -->|"reads policy"| node_server_config
node_server_http3 -->|"uses certificates"| node_server_certs
node_server_http3 -->|"uses wire codec"| node_server_protocol
node_server_http3 -->|"allows destinations"| node_discord_services

click node_installer "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/installer/main.cpp"
click node_client_config "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/shared/config.cpp"
click node_filesystem "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/shared/fs_utils.cpp"
click node_native_entry "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/dllmain.cpp"
click node_native_hooks "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/hooks.cpp"
click node_socket_state "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/socket_manager.cpp"
click node_udp_strategy "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/udp_strategy.cpp"
click node_socks_udp "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/socks5_udp.cpp"
click node_native_config "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/config.cpp"
click node_native_runtime "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/embedded_runtime.cpp"
click node_ffi "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/ffi.rs"
click node_embedded "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/embedded.rs"
click node_runtime "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/runtime.rs"
click node_session "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/session.rs"
click node_queue "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/queue.rs"
click node_transport "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/transport.rs"
click node_protocol "https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/protocol.rs"
click node_server_http3 "https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/discord_http3.py"
click node_server_config "https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/config.py"
click node_server_certs "https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/certs.py"
click node_server_protocol "https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/discord_protocol.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_installer,node_client_config,node_filesystem,node_user toneBlue
class node_native_entry,node_native_hooks,node_socket_state,node_udp_strategy,node_socks_udp,node_native_config,node_native_runtime toneAmber
class node_ffi,node_embedded,node_runtime,node_session,node_queue,node_transport,node_protocol toneMint
class node_server_http3,node_server_config,node_server_certs,node_server_protocol toneRose
class node_discord,node_discord_services toneIndigo
```

## Components

### Client setup

- [Client installer](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/installer/main.cpp): `client/discord/installer/main.cpp`
- [Client configuration](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/shared/config.cpp): `client/discord/shared/config.cpp`
- [Filesystem utilities](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/shared/fs_utils.cpp): `client/discord/shared/fs_utils.cpp`

### Windows client runtime

- [DLL entry](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/dllmain.cpp): `client/discord/hook/native/dllmain.cpp`
- [Socket hooks](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/hooks.cpp): `client/discord/hook/native/hooks.cpp`
- [Socket tracking](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/socket_manager.cpp): `client/discord/hook/native/socket_manager.cpp`
- [UDP strategies](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/udp_strategy.cpp): `client/discord/hook/native/udp_strategy.cpp`
- [SOCKS5 UDP](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/socks5_udp.cpp): `client/discord/hook/native/socks5_udp.cpp`
- [DLL configuration](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/config.cpp): `client/discord/hook/native/config.cpp`
- [Runtime FFI bridge](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/hook/native/embedded_runtime.cpp): `client/discord/hook/native/embedded_runtime.cpp`

### Embedded Rust runtime

- [C ABI](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/ffi.rs): `client/discord/runtime/src/ffi.rs`
- [Loopback bridges](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/embedded.rs): `client/discord/runtime/src/embedded.rs`
- [Session runtime](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/runtime.rs): `client/discord/runtime/src/runtime.rs`
- [Session lifecycle](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/session.rs): `client/discord/runtime/src/session.rs`
- [Command event queue](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/queue.rs): `client/discord/runtime/src/queue.rs`
- [QUIC HTTP/3 transport](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/transport.rs): `client/discord/runtime/src/transport.rs`
- [Wire protocol](https://github.com/evgenydarkstar/discord-tunnel/blob/main/client/discord/runtime/src/protocol.rs): `client/discord/runtime/src/protocol.rs`

### Tunnel server

- [HTTP/3 server](https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/discord_http3.py): `server/app/discord_http3.py`
- [Server policy config](https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/config.py): `server/app/config.py`
- [Certificate setup](https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/certs.py): `server/app/certs.py`
- [Server protocol](https://github.com/evgenydarkstar/discord-tunnel/blob/main/server/app/discord_protocol.py): `server/app/discord_protocol.py`

### Other components

- **Windows user**
- **Discord app**
- **Discord services**

## Connections

- Windows user → Client installer: configures client (evidence: `README.md`)
- Client installer → Client configuration: writes settings (evidence: `client/discord/installer/main.cpp`)
- Client installer → Filesystem utilities: uses file helpers (evidence: `client/discord/installer/main.cpp`)
- Discord app → DLL entry: loads module (evidence: `README.md`)
- DLL entry → DLL configuration: loads settings
- DLL entry → Socket hooks: initializes hooks (evidence: `client/discord/hook/native/dllmain.cpp`)
- DLL entry → Runtime FFI bridge: starts runtime (evidence: `client/discord/hook/native/dllmain.cpp`)
- Socket hooks → Runtime FFI bridge: calls bridge (evidence: `client/discord/hook/native/hooks.cpp`)
- Socket hooks → Socket tracking: tracks sockets (evidence: `client/discord/hook/native/hooks.cpp`)
- Socket hooks → UDP strategies: uses strategy (evidence: `client/discord/hook/native/hooks.cpp`)
- Socket hooks → SOCKS5 UDP: uses UDP framing
- Runtime FFI bridge → C ABI: calls ABI (evidence: `client/discord/hook/native/embedded_runtime.cpp`)
- C ABI → Loopback bridges: opens bridges (evidence: `client/discord/runtime/src/ffi.rs`)
- C ABI → Session runtime: forwards commands (evidence: `client/discord/runtime/src/ffi.rs`)
- Loopback bridges → Session runtime: dispatches bridge commands (evidence: `client/discord/runtime/src/embedded.rs`)
- Session runtime → Session lifecycle: creates sessions (evidence: `client/discord/runtime/src/runtime.rs`)
- Session runtime → Command event queue: drains commands (evidence: `client/discord/runtime/src/runtime.rs`)
- Session runtime → QUIC HTTP/3 transport: drives transport (evidence: `client/discord/runtime/src/runtime.rs`)
- QUIC HTTP/3 transport → Wire protocol: encodes datagrams (evidence: `client/discord/runtime/src/transport.rs`)
- QUIC HTTP/3 transport → HTTP/3 server: QUIC HTTP/3 (evidence: `README.md`)
- HTTP/3 server → Server policy config: reads policy (evidence: `server/app/discord_http3.py`)
- HTTP/3 server → Certificate setup: uses certificates (evidence: `server/app/discord_http3.py`)
- HTTP/3 server → Server protocol: uses wire codec (evidence: `server/app/discord_http3.py`)
- HTTP/3 server → Discord services: allows destinations (evidence: `README.md`)
