# amnezia-vpn/amneziawg-go architecture

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

- Interactive diagram: https://gitdiagram.com/amnezia-vpn/amneziawg-go
- Repository: https://github.com/amnezia-vpn/amneziawg-go

## Overview

AmneziaWG is a userspace VPN daemon that adds DPI-resistant traffic obfuscation to WireGuard. The main workflow starts the daemon, creates a TUN interface and UAPI control listener, then configures and runs a device that exchanges encrypted packets over network sockets. The README documents configurable handshake junk and signature packets, message padding and headers, header protection, and timing controls. The graph includes those capabilities, plus the optional Outline stream-dialer integration. Some internal packet-stage connections are omitted because the sampled excerpts do not establish their callers.

Main entry points: [`device/device.go`](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/device.go) (Device lifecycle), [`main.go`](https://github.com/amnezia-vpn/amneziawg-go/blob/master/main.go) (Daemon entry), [`conn/bind_std.go`](https://github.com/amnezia-vpn/amneziawg-go/blob/master/conn/bind_std.go) (UDP bind), [`tun/tun.go`](https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/tun.go) (TUN interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Daemon runtime"]
  node_daemon["Daemon entry<br/>[main.go]"]
  node_device["Device lifecycle<br/>[device.go]"]
end

subgraph group_control["Configuration control"]
  node_control_socket["UAPI listener"]
  node_uapi_handler["UAPI configuration<br/>[uapi.go]"]
end

subgraph group_tunnel["Tunnel and transport"]
  node_tun_api["TUN interface<br/>[tun.go]"]
  node_linux_tun["Linux TUN<br/>[tun_linux.go]"]
  node_netstack["Userspace netstack<br/>[tun.go]"]
  node_udp_bind["UDP bind<br/>[bind_std.go]"]
  node_windows_bind["Windows bind<br/>[bind_windows.go]"]
end

subgraph group_protocol["VPN protocol"]
  node_obfuscation["Obfuscation settings<br/>[uapi.go]"]
  node_send["Packet sending<br/>[send.go]"]
  node_receive["Packet receiving<br/>[receive.go]"]
  node_noise["Noise handshake<br/>[noise-protocol.go]"]
  node_peer["Peer state<br/>[peer.go]"]
  node_allowed_ips["Allowed IPs<br/>[allowedips.go]"]
end

subgraph group_integration["Optional integration"]
  node_outline["Outline dialer<br/>[dialer.go]"]
end

node_operator(("Operator"))
node_tools(("AWG tools"))
node_internet(("Network peers"))

node_operator -->|"starts"| node_daemon
node_daemon -->|"creates"| node_tun_api
node_daemon -->|"opens"| node_control_socket
node_daemon -->|"constructs"| node_device
node_tools -->|"configures"| node_control_socket
node_control_socket -->|"dispatches"| node_uapi_handler
node_uapi_handler -->|"configures"| node_device
node_uapi_handler -->|"parses settings"| node_obfuscation
node_device -->|"uses"| node_udp_bind
node_device -->|"uses"| node_tun_api
node_tun_api -->|"implemented by"| node_linux_tun
node_device -.->|"runs"| node_send
node_device -.->|"runs"| node_receive
node_send -->|"sends packets"| node_udp_bind
node_receive -->|"receives packets"| node_udp_bind
node_send -->|"reads packets"| node_tun_api
node_device -.->|"uses handshake"| node_noise
node_device -.->|"manages"| node_peer
node_peer -.->|"routes by"| node_allowed_ips
node_internet -.->|"exchanges datagrams"| node_udp_bind
node_daemon -.->|"selects on Windows"| node_windows_bind
node_outline -->|"creates"| node_netstack
node_outline -->|"configures and starts"| node_device
node_outline -->|"selects bind"| node_udp_bind

click node_daemon "https://github.com/amnezia-vpn/amneziawg-go/blob/master/main.go"
click node_device "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/device.go"
click node_control_socket "https://github.com/amnezia-vpn/amneziawg-go/tree/master/ipc"
click node_uapi_handler "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/uapi.go"
click node_obfuscation "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/uapi.go"
click node_tun_api "https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/tun.go"
click node_linux_tun "https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/tun_linux.go"
click node_netstack "https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/netstack/tun.go"
click node_udp_bind "https://github.com/amnezia-vpn/amneziawg-go/blob/master/conn/bind_std.go"
click node_windows_bind "https://github.com/amnezia-vpn/amneziawg-go/blob/master/conn/bind_windows.go"
click node_send "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/send.go"
click node_receive "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/receive.go"
click node_noise "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/noise-protocol.go"
click node_peer "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/peer.go"
click node_allowed_ips "https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/allowedips.go"
click node_outline "https://github.com/amnezia-vpn/amneziawg-go/blob/master/outline/dialer.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_daemon,node_device toneBlue
class node_control_socket,node_uapi_handler toneAmber
class node_tun_api,node_linux_tun,node_netstack,node_udp_bind,node_windows_bind toneMint
class node_obfuscation,node_send,node_receive,node_noise,node_peer,node_allowed_ips toneRose
class node_outline,node_operator,node_tools,node_internet toneIndigo
```

## Components

### Daemon runtime

- [Daemon entry](https://github.com/amnezia-vpn/amneziawg-go/blob/master/main.go): `main.go`
- [Device lifecycle](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/device.go): `device/device.go`

### Configuration control

- [UAPI listener](https://github.com/amnezia-vpn/amneziawg-go/tree/master/ipc): `ipc`
- [UAPI configuration](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/uapi.go): `device/uapi.go`

### Tunnel and transport

- [TUN interface](https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/tun.go): `tun/tun.go`
- [Linux TUN](https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/tun_linux.go): `tun/tun_linux.go`
- [Userspace netstack](https://github.com/amnezia-vpn/amneziawg-go/blob/master/tun/netstack/tun.go): `tun/netstack/tun.go`
- [UDP bind](https://github.com/amnezia-vpn/amneziawg-go/blob/master/conn/bind_std.go): `conn/bind_std.go`
- [Windows bind](https://github.com/amnezia-vpn/amneziawg-go/blob/master/conn/bind_windows.go): `conn/bind_windows.go`

### VPN protocol

- [Obfuscation settings](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/uapi.go): `device/uapi.go`
- [Packet sending](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/send.go): `device/send.go`
- [Packet receiving](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/receive.go): `device/receive.go`
- [Noise handshake](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/noise-protocol.go): `device/noise-protocol.go`
- [Peer state](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/peer.go): `device/peer.go`
- [Allowed IPs](https://github.com/amnezia-vpn/amneziawg-go/blob/master/device/allowedips.go): `device/allowedips.go`

### Optional integration

- [Outline dialer](https://github.com/amnezia-vpn/amneziawg-go/blob/master/outline/dialer.go): `outline/dialer.go`

### Other components

- **Operator**
- **AWG tools**
- **Network peers**

## Connections

- Operator → Daemon entry: starts (evidence: `README.md`)
- Daemon entry → TUN interface: creates (evidence: `main.go`)
- Daemon entry → UAPI listener: opens (evidence: `main.go`)
- Daemon entry → Device lifecycle: constructs (evidence: `main.go`)
- AWG tools → UAPI listener: configures (evidence: `README.md`)
- UAPI listener → UAPI configuration: dispatches (evidence: `device/uapi.go`)
- UAPI configuration → Device lifecycle: configures (evidence: `device/uapi.go`)
- UAPI configuration → Obfuscation settings: parses settings (evidence: `device/uapi.go`)
- Device lifecycle → UDP bind: uses (evidence: `device/device.go`)
- Device lifecycle → TUN interface: uses (evidence: `device/device.go`)
- TUN interface → Linux TUN: implemented by (evidence: `tun/tun_linux.go`)
- Device lifecycle → Packet sending: runs
- Device lifecycle → Packet receiving: runs
- Packet sending → UDP bind: sends packets (evidence: `device/send.go`)
- Packet receiving → UDP bind: receives packets (evidence: `device/receive.go`)
- Packet sending → TUN interface: reads packets (evidence: `device/send.go`)
- Device lifecycle → Noise handshake: uses handshake
- Device lifecycle → Peer state: manages
- Peer state → Allowed IPs: routes by
- Network peers → UDP bind: exchanges datagrams
- Daemon entry → Windows bind: selects on Windows
- Outline dialer → Userspace netstack: creates (evidence: `outline/dialer.go`)
- Outline dialer → Device lifecycle: configures and starts (evidence: `outline/dialer.go`)
- Outline dialer → UDP bind: selects bind (evidence: `outline/dialer.go`)
