# parrotsec/anonsurf architecture

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

- Interactive diagram: https://gitdiagram.com/parrotsec/anonsurf
- Repository: https://github.com/parrotsec/anonsurf

## Overview

AnonSurf routes supported traffic and DNS through Tor, with start/stop/restart and recovery managed by a Go service. Users can operate it through the CLI or an unprivileged Qt desktop interface; the GUI reads CLI status and uses systemd D-Bus for authorized actions. The code excerpts substantiate GUI dispatch and adapters, while the README documents network behavior and boot recovery. Several Go subsystem links are omitted because their callers were not shown.

Main entry points: [`src/internal/anonsurf/controller.go`](https://github.com/parrotsec/anonsurf/blob/master/src/internal/anonsurf/controller.go) (Lifecycle controller), [`gui/src/application/main.cpp`](https://github.com/parrotsec/anonsurf/blob/master/gui/src/application/main.cpp) (GUI startup), [`gui/src/tray/traycontroller.cpp`](https://github.com/parrotsec/anonsurf/blob/master/gui/src/tray/traycontroller.cpp) (Tray controller), [`gui/src/anonsurf/anonsurfbackend.cpp`](https://github.com/parrotsec/anonsurf/blob/master/gui/src/anonsurf/anonsurfbackend.cpp) (GUI state and actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_guiapp["GUI startup<br/>[main.cpp]"]
  node_guiinstance["Single instance<br/>[instance.cpp]"]
  node_guibackend["GUI state and actions"]
  node_tray["Tray controller<br/>[traycontroller.cpp]"]
  node_menu["Tray menu<br/>[traymenu.cpp]"]
  node_notifications["Desktop notifications<br/>[notifications.cpp]"]
  node_guicli["GUI CLI adapter<br/>[commandclient.cpp]"]
  node_guisystemd["GUI systemd adapter<br/>[systemdclient.cpp]"]
  node_cli["AnonSurf CLI<br/>[main.go]"]
end

subgraph group_lifecycle["Service lifecycle"]
  node_daemon["Service daemon<br/>[main.go]"]
  node_controller["Lifecycle controller<br/>[controller.go]"]
  node_recovery["Transactional recovery<br/>[rollback.go]"]
  node_status["Status reporting<br/>[status.go]"]
end

subgraph group_routing["Network protection"]
  node_firewall["Firewall routing<br/>[manager.go]"]
  node_dns["DNS routing<br/>[nm.go]"]
  node_ipv6["IPv6 management<br/>[manager.go]"]
end

subgraph group_tor["Tor configuration"]
  node_torconfig["Tor configuration<br/>[torrc_manager.go]"]
  node_torcheck["Tor verification<br/>[tor_check.go]"]
end

subgraph group_os["Operating-system integration"]
  node_command["Command runner<br/>[runner.go]"]
  node_systemd["Systemd service<br/>[service.go]"]
end

node_user(("Desktop user"))
node_cliuser(("CLI user"))
node_torservice[("Tor service")]
node_network(("Network and DNS"))

node_user -->|"opens"| node_guiapp
node_guiapp -->|"checks instance"| node_guiinstance
node_guiapp -->|"creates backend"| node_guibackend
node_guiapp -->|"creates tray"| node_tray
node_tray -->|"updates from"| node_guibackend
node_tray -->|"updates"| node_menu
node_tray -->|"sends alerts"| node_notifications
node_guibackend -->|"requests status"| node_guicli
node_guibackend -->|"dispatches actions"| node_guisystemd
node_guicli -->|"runs commands"| node_cli
node_guisystemd -->|"calls over D-Bus"| node_systemd
node_cliuser -.->|"runs commands"| node_cli
node_cli -.->|"requests lifecycle"| node_controller
node_daemon -.->|"manages lifecycle"| node_controller
node_controller -.->|"recovers state"| node_recovery
node_controller -.->|"configures routing"| node_firewall
node_controller -.->|"configures DNS"| node_dns
node_controller -.->|"manages IPv6"| node_ipv6
node_controller -.->|"configures Tor"| node_torconfig
node_cli -.->|"shows status"| node_status
node_controller -.->|"runs system commands"| node_command
node_daemon -.->|"publishes lifecycle"| node_systemd
node_torconfig -.->|"configures"| node_torservice
node_firewall -.->|"routes traffic"| node_network
node_dns -.->|"routes DNS"| node_network
node_torcheck -.->|"verifies routing"| node_torservice

click node_guiapp "https://github.com/parrotsec/anonsurf/blob/master/gui/src/application/main.cpp"
click node_guiinstance "https://github.com/parrotsec/anonsurf/blob/master/gui/src/application/instance.cpp"
click node_guibackend "https://github.com/parrotsec/anonsurf/blob/master/gui/src/anonsurf/anonsurfbackend.cpp"
click node_tray "https://github.com/parrotsec/anonsurf/blob/master/gui/src/tray/traycontroller.cpp"
click node_menu "https://github.com/parrotsec/anonsurf/blob/master/gui/src/tray/traymenu.cpp"
click node_notifications "https://github.com/parrotsec/anonsurf/blob/master/gui/src/notifications/notifications.cpp"
click node_guicli "https://github.com/parrotsec/anonsurf/blob/master/gui/src/cli/commandclient.cpp"
click node_guisystemd "https://github.com/parrotsec/anonsurf/blob/master/gui/src/systemd/systemdclient.cpp"
click node_cli "https://github.com/parrotsec/anonsurf/blob/master/src/cmd/anonsurf-cli/main.go"
click node_daemon "https://github.com/parrotsec/anonsurf/blob/master/src/cmd/anondaemon/main.go"
click node_controller "https://github.com/parrotsec/anonsurf/blob/master/src/internal/anonsurf/controller.go"
click node_recovery "https://github.com/parrotsec/anonsurf/blob/master/src/internal/anonsurf/rollback.go"
click node_status "https://github.com/parrotsec/anonsurf/blob/master/src/internal/status/status.go"
click node_firewall "https://github.com/parrotsec/anonsurf/blob/master/src/internal/firewall/manager.go"
click node_dns "https://github.com/parrotsec/anonsurf/blob/master/src/internal/dns/nm.go"
click node_ipv6 "https://github.com/parrotsec/anonsurf/blob/master/src/internal/ipv6/manager.go"
click node_torconfig "https://github.com/parrotsec/anonsurf/blob/master/src/internal/tor/torrc_manager.go"
click node_torcheck "https://github.com/parrotsec/anonsurf/blob/master/src/internal/netcheck/tor_check.go"
click node_command "https://github.com/parrotsec/anonsurf/blob/master/src/internal/command/runner.go"
click node_systemd "https://github.com/parrotsec/anonsurf/blob/master/src/internal/systemd/service.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_guiapp,node_guiinstance,node_guibackend,node_tray,node_menu,node_notifications,node_guicli,node_guisystemd,node_cli,node_user,node_cliuser toneBlue
class node_daemon,node_controller,node_recovery,node_status,node_torservice toneAmber
class node_firewall,node_dns,node_ipv6 toneMint
class node_torconfig,node_torcheck toneRose
class node_command,node_systemd,node_network toneIndigo
```

## Components

### User interfaces

- [GUI startup](https://github.com/parrotsec/anonsurf/blob/master/gui/src/application/main.cpp): `gui/src/application/main.cpp`
- [Single instance](https://github.com/parrotsec/anonsurf/blob/master/gui/src/application/instance.cpp): `gui/src/application/instance.cpp`
- [GUI state and actions](https://github.com/parrotsec/anonsurf/blob/master/gui/src/anonsurf/anonsurfbackend.cpp): `gui/src/anonsurf/anonsurfbackend.cpp`
- [Tray controller](https://github.com/parrotsec/anonsurf/blob/master/gui/src/tray/traycontroller.cpp): `gui/src/tray/traycontroller.cpp`
- [Tray menu](https://github.com/parrotsec/anonsurf/blob/master/gui/src/tray/traymenu.cpp): `gui/src/tray/traymenu.cpp`
- [Desktop notifications](https://github.com/parrotsec/anonsurf/blob/master/gui/src/notifications/notifications.cpp): `gui/src/notifications/notifications.cpp`
- [GUI CLI adapter](https://github.com/parrotsec/anonsurf/blob/master/gui/src/cli/commandclient.cpp): `gui/src/cli/commandclient.cpp`
- [GUI systemd adapter](https://github.com/parrotsec/anonsurf/blob/master/gui/src/systemd/systemdclient.cpp): `gui/src/systemd/systemdclient.cpp`
- [AnonSurf CLI](https://github.com/parrotsec/anonsurf/blob/master/src/cmd/anonsurf-cli/main.go): `src/cmd/anonsurf-cli/main.go`

### Service lifecycle

- [Service daemon](https://github.com/parrotsec/anonsurf/blob/master/src/cmd/anondaemon/main.go): `src/cmd/anondaemon/main.go`
- [Lifecycle controller](https://github.com/parrotsec/anonsurf/blob/master/src/internal/anonsurf/controller.go): `src/internal/anonsurf/controller.go`
- [Transactional recovery](https://github.com/parrotsec/anonsurf/blob/master/src/internal/anonsurf/rollback.go): `src/internal/anonsurf/rollback.go`
- [Status reporting](https://github.com/parrotsec/anonsurf/blob/master/src/internal/status/status.go): `src/internal/status/status.go`

### Network protection

- [Firewall routing](https://github.com/parrotsec/anonsurf/blob/master/src/internal/firewall/manager.go): `src/internal/firewall/manager.go`
- [DNS routing](https://github.com/parrotsec/anonsurf/blob/master/src/internal/dns/nm.go): `src/internal/dns/nm.go`
- [IPv6 management](https://github.com/parrotsec/anonsurf/blob/master/src/internal/ipv6/manager.go): `src/internal/ipv6/manager.go`

### Tor configuration

- [Tor configuration](https://github.com/parrotsec/anonsurf/blob/master/src/internal/tor/torrc_manager.go): `src/internal/tor/torrc_manager.go`
- [Tor verification](https://github.com/parrotsec/anonsurf/blob/master/src/internal/netcheck/tor_check.go): `src/internal/netcheck/tor_check.go`

### Operating-system integration

- [Command runner](https://github.com/parrotsec/anonsurf/blob/master/src/internal/command/runner.go): `src/internal/command/runner.go`
- [Systemd service](https://github.com/parrotsec/anonsurf/blob/master/src/internal/systemd/service.go): `src/internal/systemd/service.go`

### Other components

- **Desktop user**
- **CLI user**
- **Tor service**
- **Network and DNS**

## Connections

- Desktop user → GUI startup: opens (evidence: `gui/src/application/main.cpp`)
- GUI startup → Single instance: checks instance (evidence: `gui/src/application/main.cpp`)
- GUI startup → GUI state and actions: creates backend (evidence: `gui/src/application/main.cpp`)
- GUI startup → Tray controller: creates tray (evidence: `gui/src/application/main.cpp`)
- Tray controller → GUI state and actions: updates from (evidence: `gui/src/tray/traycontroller.cpp`)
- Tray controller → Tray menu: updates (evidence: `gui/src/tray/traycontroller.cpp`)
- Tray controller → Desktop notifications: sends alerts (evidence: `gui/src/tray/traycontroller.cpp`)
- GUI state and actions → GUI CLI adapter: requests status (evidence: `gui/src/anonsurf/anonsurfbackend.cpp`)
- GUI state and actions → GUI systemd adapter: dispatches actions (evidence: `gui/src/anonsurf/anonsurfbackend.cpp`)
- GUI CLI adapter → AnonSurf CLI: runs commands (evidence: `gui/src/cli/commandclient.cpp`)
- GUI systemd adapter → Systemd service: calls over D-Bus (evidence: `gui/src/systemd/systemdclient.cpp`)
- CLI user → AnonSurf CLI: runs commands
- AnonSurf CLI → Lifecycle controller: requests lifecycle
- Service daemon → Lifecycle controller: manages lifecycle
- Lifecycle controller → Transactional recovery: recovers state
- Lifecycle controller → Firewall routing: configures routing
- Lifecycle controller → DNS routing: configures DNS
- Lifecycle controller → IPv6 management: manages IPv6
- Lifecycle controller → Tor configuration: configures Tor
- AnonSurf CLI → Status reporting: shows status
- Lifecycle controller → Command runner: runs system commands
- Service daemon → Systemd service: publishes lifecycle
- Tor configuration → Tor service: configures
- Firewall routing → Network and DNS: routes traffic
- DNS routing → Network and DNS: routes DNS
- Tor verification → Tor service: verifies routing
