# zizifn/edgetunnel architecture

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

- Interactive diagram: https://gitdiagram.com/zizifn/edgetunnel
- Repository: https://github.com/zizifn/edgetunnel

## Overview

EdgeTunnel is a Cloudflare Worker that accepts VLESS clients over WebSockets and forwards their traffic to remote TCP destinations; its main variant also supports DNS-over-HTTPS. A separate experimental worker adds SOCKS5 upstream proxying. The excerpts show request dispatch and key stream/socket operations, but omit some implementation details, so uncertain internal wiring is not represented.

Main entry points: [`src/worker-vless.js`](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js) (WebSocket Handler), [`src/worker-with-socks5-experimental.js`](https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js) (TCP Connector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_main["VLESS Worker"]
  node_worker["Worker Entry<br/>[worker-vless.js]"]
  node_routes["Config Routes<br/>[worker-vless.js]"]
  node_ws["WebSocket Handler<br/>[worker-vless.js]"]
  node_parser["VLESS Parser<br/>[worker-vless.js]"]
  node_streams["Stream Bridge<br/>[worker-vless.js]"]
  node_tcp["TCP Connector<br/>[worker-vless.js]"]
  node_dns["DNS Handler<br/>[worker-vless.js]"]
end

subgraph group_experimental["SOCKS Experiment"]
  node_socksworker["Experimental Worker"]
  node_socksroutes["Config Routes"]
  node_socksws["WebSocket Handler"]
  node_sockstcp["TCP Connector"]
  node_socksproto["SOCKS5 Protocol"]
end

subgraph group_external["External Services"]
  node_remote(("Remote TCP Hosts"))
  node_socksservice(("SOCKS5 Server"))
  node_dohservice(("Cloudflare DoH"))
  node_socketapi["Workers Sockets"]
end

node_client(("VLESS Client"))

node_client -->|"HTTP / WebSocket"| node_worker
node_worker -->|"dispatches routes"| node_routes
node_worker -->|"dispatches upgrade"| node_ws
node_ws -->|"parses header"| node_parser
node_ws -->|"bridges data"| node_streams
node_ws -->|"opens connection"| node_tcp
node_tcp -->|"connects via"| node_socketapi
node_tcp -->|"forwards TCP"| node_remote
node_ws -->|"routes DNS"| node_dns
node_dns -->|"queries DoH"| node_dohservice
node_client -.->|"HTTP / WebSocket"| node_socksworker
node_socksworker -->|"dispatches routes"| node_socksroutes
node_socksworker -->|"dispatches upgrade"| node_socksws
node_socksws -->|"opens connection"| node_sockstcp
node_sockstcp -->|"connects via"| node_socketapi
node_sockstcp -->|"forwards TCP"| node_remote
node_sockstcp -->|"uses SOCKS5"| node_socksproto
node_socksproto -->|"negotiates with"| node_socksservice

click node_worker "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_routes "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_ws "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_parser "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_streams "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_tcp "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_dns "https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js"
click node_socksworker "https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js"
click node_socksroutes "https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js"
click node_socksws "https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js"
click node_sockstcp "https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js"
click node_socksproto "https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js"

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_worker,node_routes,node_ws,node_parser,node_streams,node_tcp,node_dns,node_client toneBlue
class node_socksworker,node_socksroutes,node_socksws,node_sockstcp,node_socksproto toneAmber
class node_remote,node_socksservice,node_dohservice,node_socketapi toneMint
```

## Components

### VLESS Worker

- [Worker Entry](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`
- [Config Routes](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`
- [WebSocket Handler](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`
- [VLESS Parser](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`
- [Stream Bridge](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`
- [TCP Connector](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`
- [DNS Handler](https://github.com/zizifn/edgetunnel/blob/main/src/worker-vless.js): `src/worker-vless.js`

### SOCKS Experiment

- [Experimental Worker](https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js): `src/worker-with-socks5-experimental.js`
- [Config Routes](https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js): `src/worker-with-socks5-experimental.js`
- [WebSocket Handler](https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js): `src/worker-with-socks5-experimental.js`
- [TCP Connector](https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js): `src/worker-with-socks5-experimental.js`
- [SOCKS5 Protocol](https://github.com/zizifn/edgetunnel/blob/main/src/worker-with-socks5-experimental.js): `src/worker-with-socks5-experimental.js`

### External Services

- **Remote TCP Hosts**
- **SOCKS5 Server**
- **Cloudflare DoH**
- **Workers Sockets**

### Other components

- **VLESS Client**

## Connections

- VLESS Client → Worker Entry: HTTP / WebSocket
- Worker Entry → Config Routes: dispatches routes
- Worker Entry → WebSocket Handler: dispatches upgrade
- WebSocket Handler → VLESS Parser: parses header
- WebSocket Handler → Stream Bridge: bridges data
- WebSocket Handler → TCP Connector: opens connection
- TCP Connector → Workers Sockets: connects via
- TCP Connector → Remote TCP Hosts: forwards TCP
- WebSocket Handler → DNS Handler: routes DNS
- DNS Handler → Cloudflare DoH: queries DoH
- VLESS Client → Experimental Worker: HTTP / WebSocket
- Experimental Worker → Config Routes: dispatches routes
- Experimental Worker → WebSocket Handler: dispatches upgrade
- WebSocket Handler → TCP Connector: opens connection
- TCP Connector → Workers Sockets: connects via
- TCP Connector → Remote TCP Hosts: forwards TCP
- TCP Connector → SOCKS5 Protocol: uses SOCKS5
- SOCKS5 Protocol → SOCKS5 Server: negotiates with
