# johnwatsoon/wattunnel architecture

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

- Interactive diagram: https://gitdiagram.com/johnwatsoon/wattunnel
- Repository: https://github.com/johnwatsoon/wattunnel

## Overview

WatTunnel is encrypted, censorship-resistant port forwarding between Iran and Kharej. The main workflow is to configure a Kharej endpoint, create a token, configure Iran with that token and port mappings, then carry user TCP/UDP traffic over a selected carrier to Kharej and its local service. The repository also includes tunnel management, pairing and recovery, a web panel, and connection diagnostics. The graph uses README-documented behavior and shown source references; unsampled implementation details and their wiring are left out.

Main entry points: [`cmd/wattun/main.go`](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/main.go) (Tunnel runtime), [`cmd/wattun/mgr`](https://github.com/johnwatsoon/wattunnel/tree/main/cmd/wattun/mgr) (Go manager), [`cmd/wattun/scepter_ops.go`](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/scepter_ops.go) (Remote operations), [`wat/session.go`](https://github.com/johnwatsoon/wattunnel/blob/main/wat/session.go) (Encrypted sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Setup and management"]
  node_manager["Go manager"]
  node_tunnel_config["Tunnel configuration<br/>[config.go]"]
  node_diagnostics["Connection tests<br/>[speedtest.go]"]
  node_probe["ICMP probe<br/>[main.go]"]
end

subgraph group_transport["Tunnel transport"]
  node_engine["Tunnel runtime<br/>[main.go]"]
  node_session["Encrypted sessions<br/>[session.go]"]
  node_server["Session server<br/>[server.go]"]
  node_carriers["Carrier transports<br/>[carrier_tcp.go]"]
  node_bonding["Carrier bonding<br/>[bond.go]"]
  node_stream_forward["Stream forwarding<br/>[stream.go]"]
  node_datagram_forward["UDP forwarding<br/>[udp.go]"]
end

subgraph group_control["Pairing and control"]
  node_pairing["Pairing credentials<br/>[pairing.go]"]
  node_scepter_ops["Remote operations<br/>[scepter_ops.go]"]
  node_latch["Recovery latch<br/>[latch.go]"]
  node_cockpit["Manager cockpit<br/>[scepter_cockpit.go]"]
end

subgraph group_panel["Web panel"]
  node_web_client["Panel web client<br/>[app.js]"]
  node_panel_routes["Panel API routes<br/>[routes.go]"]
  node_panel_actions["Panel actions<br/>[actions.go]"]
  node_panel_server["Panel server<br/>[server.go]"]
end

node_operator(("Tunnel operator"))
node_iran_users(("Iran-side users"))
node_kharej_service(("Kharej local service"))

node_operator -->|"configures tunnels"| node_manager
node_manager -->|"writes settings"| node_tunnel_config
node_manager -->|"runs tests"| node_diagnostics
node_manager -->|"starts tunnel"| node_engine
node_manager -.->|"tests ICMP"| node_probe
node_iran_users -->|"connects through"| node_engine
node_engine -->|"creates sessions"| node_session
node_engine -.->|"serves sessions"| node_server
node_engine -->|"selects carrier"| node_carriers
node_engine -->|"forwards TCP"| node_stream_forward
node_engine -->|"forwards UDP"| node_datagram_forward
node_session -.->|"uses transport"| node_carriers
node_engine -.->|"bonds paths"| node_bonding
node_stream_forward -->|"reaches local port"| node_kharej_service
node_operator -->|"manages remotely"| node_web_client
node_web_client -->|"uses panel"| node_panel_server
node_panel_server -.->|"routes requests"| node_panel_routes
node_panel_routes -->|"dispatches actions"| node_panel_actions
node_panel_actions -.->|"manages tunnels"| node_cockpit
node_pairing -->|"enables management channel"| node_engine
node_engine -->|"serves remote operations"| node_scepter_ops
node_latch -.->|"revives management"| node_scepter_ops
node_cockpit -.->|"issues operations"| node_scepter_ops

click node_manager "https://github.com/johnwatsoon/wattunnel/tree/main/cmd/wattun/mgr"
click node_tunnel_config "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/config.go"
click node_diagnostics "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/speedtest.go"
click node_probe "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wprobe/main.go"
click node_engine "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/main.go"
click node_session "https://github.com/johnwatsoon/wattunnel/blob/main/wat/session.go"
click node_server "https://github.com/johnwatsoon/wattunnel/blob/main/wat/server.go"
click node_carriers "https://github.com/johnwatsoon/wattunnel/blob/main/wat/carrier_tcp.go"
click node_bonding "https://github.com/johnwatsoon/wattunnel/blob/main/wat/bond.go"
click node_stream_forward "https://github.com/johnwatsoon/wattunnel/blob/main/wat/stream.go"
click node_datagram_forward "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/udp.go"
click node_pairing "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/pairing.go"
click node_scepter_ops "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/scepter_ops.go"
click node_latch "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/latch.go"
click node_cockpit "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/mgr/scepter_cockpit.go"
click node_web_client "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/web/app.js"
click node_panel_routes "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/routes.go"
click node_panel_actions "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/actions.go"
click node_panel_server "https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/server.go"

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_manager,node_tunnel_config,node_diagnostics,node_probe,node_iran_users toneBlue
class node_engine,node_session,node_server,node_carriers,node_bonding,node_stream_forward,node_datagram_forward toneAmber
class node_pairing,node_scepter_ops,node_latch,node_cockpit toneMint
class node_web_client,node_panel_routes,node_panel_actions,node_panel_server toneRose
class node_operator,node_kharej_service toneIndigo
```

## Components

### Setup and management

- [Go manager](https://github.com/johnwatsoon/wattunnel/tree/main/cmd/wattun/mgr): `cmd/wattun/mgr`
- [Tunnel configuration](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/config.go): `cmd/wattun/config.go`
- [Connection tests](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/speedtest.go): `cmd/wattun/speedtest.go`
- [ICMP probe](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wprobe/main.go): `cmd/wprobe/main.go`

### Tunnel transport

- [Tunnel runtime](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/main.go): `cmd/wattun/main.go`
- [Encrypted sessions](https://github.com/johnwatsoon/wattunnel/blob/main/wat/session.go): `wat/session.go`
- [Session server](https://github.com/johnwatsoon/wattunnel/blob/main/wat/server.go): `wat/server.go`
- [Carrier transports](https://github.com/johnwatsoon/wattunnel/blob/main/wat/carrier_tcp.go): `wat/carrier_tcp.go`
- [Carrier bonding](https://github.com/johnwatsoon/wattunnel/blob/main/wat/bond.go): `wat/bond.go`
- [Stream forwarding](https://github.com/johnwatsoon/wattunnel/blob/main/wat/stream.go): `wat/stream.go`
- [UDP forwarding](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/udp.go): `cmd/wattun/udp.go`

### Pairing and control

- [Pairing credentials](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/pairing.go): `cmd/wattun/pairing.go`
- [Remote operations](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/scepter_ops.go): `cmd/wattun/scepter_ops.go`
- [Recovery latch](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/latch.go): `cmd/wattun/latch.go`
- [Manager cockpit](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/mgr/scepter_cockpit.go): `cmd/wattun/mgr/scepter_cockpit.go`

### Web panel

- [Panel web client](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/web/app.js): `cmd/wattun/panel/web/app.js`
- [Panel API routes](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/routes.go): `cmd/wattun/panel/routes.go`
- [Panel actions](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/actions.go): `cmd/wattun/panel/actions.go`
- [Panel server](https://github.com/johnwatsoon/wattunnel/blob/main/cmd/wattun/panel/server.go): `cmd/wattun/panel/server.go`

### Other components

- **Tunnel operator**
- **Iran-side users**
- **Kharej local service**

## Connections

- Tunnel operator → Go manager: configures tunnels (evidence: `README.md`)
- Go manager → Tunnel configuration: writes settings (evidence: `README.md`)
- Go manager → Connection tests: runs tests (evidence: `README.md`)
- Go manager → Tunnel runtime: starts tunnel (evidence: `README.md`)
- Go manager → ICMP probe: tests ICMP
- Iran-side users → Tunnel runtime: connects through (evidence: `README.md`)
- Tunnel runtime → Encrypted sessions: creates sessions (evidence: `cmd/wattun/main.go`)
- Tunnel runtime → Session server: serves sessions
- Tunnel runtime → Carrier transports: selects carrier (evidence: `README.md`)
- Tunnel runtime → Stream forwarding: forwards TCP (evidence: `cmd/wattun/main.go`)
- Tunnel runtime → UDP forwarding: forwards UDP (evidence: `cmd/wattun/main.go`)
- Encrypted sessions → Carrier transports: uses transport
- Tunnel runtime → Carrier bonding: bonds paths
- Stream forwarding → Kharej local service: reaches local port (evidence: `README.md`)
- Tunnel operator → Panel web client: manages remotely (evidence: `README.md`)
- Panel web client → Panel server: uses panel (evidence: `cmd/wattun/panel/web/app.js`)
- Panel server → Panel API routes: routes requests
- Panel API routes → Panel actions: dispatches actions (evidence: `cmd/wattun/panel/routes.go`)
- Panel actions → Manager cockpit: manages tunnels
- Pairing credentials → Tunnel runtime: enables management channel (evidence: `cmd/wattun/pairing.go`)
- Tunnel runtime → Remote operations: serves remote operations (evidence: `cmd/wattun/scepter_ops.go`)
- Recovery latch → Remote operations: revives management
- Manager cockpit → Remote operations: issues operations
