# xlmnxp/qanah architecture

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

- Interactive diagram: https://gitdiagram.com/xlmnxp/qanah
- Repository: https://github.com/xlmnxp/qanah

## Overview

Qanah is a peer-to-peer VPN that turns WireGuard-style configuration into encrypted IP tunnels carried over WebRTC data channels. The principal workflow parses peer configuration, prepares a TUN interface, derives keys, negotiates peer connections through automatic MQTT or manual signaling, then routes packets directly or through a single relay hop. The excerpts show the main orchestration and packet-routing responsibilities; some setup and keepalive details are documented in the README rather than visible in sampled code.

Main entry points: [`src/main.rs`](https://github.com/xlmnxp/qanah/blob/main/src/main.rs) (VPN orchestration), [`src/tunnel.rs`](https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs) (Peer routing table), [`src/crypto.rs`](https://github.com/xlmnxp/qanah/blob/main/src/crypto.rs) (Packet encryption), [`src/peer.rs`](https://github.com/xlmnxp/qanah/blob/main/src/peer.rs) (Peer connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Configuration and setup"]
  node_cli["VPN orchestration<br/>[main.rs]"]
  node_wgconfig["WireGuard config<br/>[config.rs]"]
  node_tun["TUN interface<br/>[tunnel.rs]"]
end

subgraph group_security["Keys and security"]
  node_keyderive["Key derivation<br/>[crypto.rs]"]
  node_packetcipher["Packet encryption<br/>[crypto.rs]"]
end

subgraph group_connect["Peer connectivity"]
  node_peerconn["Peer connection<br/>[peer.rs]"]
  node_webrtc["WebRTC and ICE"]
  node_signaling["Signaling exchange<br/>[signaling.rs]"]
  node_mqtt["MQTT broker"]
end

subgraph group_traffic["Tunnel traffic"]
  node_routing["Peer routing table<br/>[tunnel.rs]"]
  node_packetforward["Packet forwarding<br/>[tunnel.rs]"]
  node_datac["WebRTC data channel"]
  node_keepalive["NAT keepalive<br/>[main.rs]"]
end

node_operator(("VPN operator"))
node_os["Host network"]
node_manual["Manual SDP exchange"]

node_operator -->|"starts VPN"| node_cli
node_cli -->|"loads config"| node_wgconfig
node_cli -->|"creates interface"| node_tun
node_tun -->|"configures routes"| node_os
node_cli -->|"derives keys"| node_keyderive
node_keyderive -->|"provides keys"| node_packetcipher
node_cli -->|"starts connections"| node_peerconn
node_peerconn -->|"negotiates ICE"| node_webrtc
node_cli -->|"exchanges SDP"| node_signaling
node_signaling -->|"publishes SDP"| node_mqtt
node_operator -->|"copies SDP"| node_manual
node_cli -->|"offers or answers"| node_manual
node_signaling -->|"encrypts signaling"| node_packetcipher
node_peerconn -->|"opens channel"| node_datac
node_tun -->|"reads packets"| node_packetforward
node_packetforward -->|"routes packets"| node_routing
node_routing -->|"encrypts outbound"| node_packetcipher
node_routing -->|"sends packets"| node_datac
node_datac -->|"delivers packets"| node_packetforward
node_packetforward -->|"decrypts inbound"| node_packetcipher
node_packetforward -->|"writes packets"| node_tun
node_cli -->|"manages keepalive"| node_keepalive
node_keepalive -->|"sends keepalives"| node_datac
node_routing -->|"relays one hop"| node_routing

click node_cli "https://github.com/xlmnxp/qanah/blob/main/src/main.rs"
click node_wgconfig "https://github.com/xlmnxp/qanah/blob/main/src/config.rs"
click node_tun "https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs"
click node_keyderive "https://github.com/xlmnxp/qanah/blob/main/src/crypto.rs"
click node_packetcipher "https://github.com/xlmnxp/qanah/blob/main/src/crypto.rs"
click node_peerconn "https://github.com/xlmnxp/qanah/blob/main/src/peer.rs"
click node_signaling "https://github.com/xlmnxp/qanah/blob/main/src/signaling.rs"
click node_routing "https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs"
click node_packetforward "https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs"
click node_keepalive "https://github.com/xlmnxp/qanah/blob/main/src/main.rs"

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_cli,node_wgconfig,node_tun toneBlue
class node_keyderive,node_packetcipher toneAmber
class node_peerconn,node_webrtc,node_signaling,node_mqtt toneMint
class node_routing,node_packetforward,node_datac,node_keepalive toneRose
class node_operator,node_os,node_manual toneIndigo
```

## Components

### Configuration and setup

- [VPN orchestration](https://github.com/xlmnxp/qanah/blob/main/src/main.rs): `src/main.rs`
- [WireGuard config](https://github.com/xlmnxp/qanah/blob/main/src/config.rs): `src/config.rs`
- [TUN interface](https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs): `src/tunnel.rs`

### Keys and security

- [Key derivation](https://github.com/xlmnxp/qanah/blob/main/src/crypto.rs): `src/crypto.rs`
- [Packet encryption](https://github.com/xlmnxp/qanah/blob/main/src/crypto.rs): `src/crypto.rs`

### Peer connectivity

- [Peer connection](https://github.com/xlmnxp/qanah/blob/main/src/peer.rs): `src/peer.rs`
- **WebRTC and ICE**
- [Signaling exchange](https://github.com/xlmnxp/qanah/blob/main/src/signaling.rs): `src/signaling.rs`
- **MQTT broker**

### Tunnel traffic

- [Peer routing table](https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs): `src/tunnel.rs`
- [Packet forwarding](https://github.com/xlmnxp/qanah/blob/main/src/tunnel.rs): `src/tunnel.rs`
- **WebRTC data channel**
- [NAT keepalive](https://github.com/xlmnxp/qanah/blob/main/src/main.rs): `src/main.rs`

### Other components

- **VPN operator**
- **Host network**
- **Manual SDP exchange**

## Connections

- VPN operator → VPN orchestration: starts VPN (evidence: `README.md`)
- VPN orchestration → WireGuard config: loads config (evidence: `src/main.rs`)
- VPN orchestration → TUN interface: creates interface (evidence: `src/main.rs`)
- TUN interface → Host network: configures routes (evidence: `README.md`)
- VPN orchestration → Key derivation: derives keys (evidence: `src/main.rs`)
- Key derivation → Packet encryption: provides keys (evidence: `src/crypto.rs`)
- VPN orchestration → Peer connection: starts connections (evidence: `src/main.rs`)
- Peer connection → WebRTC and ICE: negotiates ICE (evidence: `src/peer.rs`)
- VPN orchestration → Signaling exchange: exchanges SDP (evidence: `src/main.rs`)
- Signaling exchange → MQTT broker: publishes SDP (evidence: `README.md`)
- VPN operator → Manual SDP exchange: copies SDP (evidence: `README.md`)
- VPN orchestration → Manual SDP exchange: offers or answers (evidence: `README.md`)
- Signaling exchange → Packet encryption: encrypts signaling (evidence: `src/signaling.rs`)
- Peer connection → WebRTC data channel: opens channel (evidence: `src/peer.rs`)
- TUN interface → Packet forwarding: reads packets (evidence: `README.md`)
- Packet forwarding → Peer routing table: routes packets (evidence: `src/tunnel.rs`)
- Peer routing table → Packet encryption: encrypts outbound (evidence: `src/tunnel.rs`)
- Peer routing table → WebRTC data channel: sends packets (evidence: `src/tunnel.rs`)
- WebRTC data channel → Packet forwarding: delivers packets
- Packet forwarding → Packet encryption: decrypts inbound (evidence: `src/tunnel.rs`)
- Packet forwarding → TUN interface: writes packets (evidence: `src/tunnel.rs`)
- VPN orchestration → NAT keepalive: manages keepalive (evidence: `README.md`)
- NAT keepalive → WebRTC data channel: sends keepalives (evidence: `README.md`)
- Peer routing table → Peer routing table: relays one hop (evidence: `src/tunnel.rs`)
