How mmalmi/nostr-vpn works
1. Repository shape
- This is a Rust workspace with one shared core library and several front ends / platform wrappers:
- nostr-vpn-core: protocol, config, crypto, NAT, DNS, diagnostics, WireGuard helpers
- nostr-vpn-cli: the nvpn command-line client and daemon
- nostr-vpn-gui: Tauri + Svelte UI for desktop plus Android/iOS targets
- nostr-vpn-relay: local test relay and UDP reflector
- nostr-vpn-wintun: Windows tunnel integration support
2. Primary control-plane/data-plane split
- The control plane is built around Nostr signaling and config/state management.
- The data plane is userspace WireGuard, implemented through boringtun and platform tunnel adapters.
- In a diagram, treat “Nostr relays / signaling” and “WireGuard tunnel traffic” as two separate flows that meet in the core session logic.
3. Shared core as the architectural center
- nostr-vpn-core owns the reusable business logic:
- configuration model and path handling
- identity/crypto key generation
- node records, presence, and roster logic
- signaling message handling
- NAT discovery / hole punching support
- MagicDNS / name mapping
- diagnostics and status reporting
- WireGuard configuration/rendering helpers
- Both CLI and GUI depend on this core, so it is the main boundary between UI/platform code and network/protocol logic.
4. CLI runtime and daemon lifecycle
- nostr-vpn-cli is the operational entry point for headless use.
- It handles init, connect/up/down, daemon start/stop/pause/resume, service installation, status, netcheck, doctor bundles, and lower-level networking commands.
- The CLI is also the process that actually orchestrates tunnel bring-up on desktop/server systems, often as a background service on macOS, Linux, or Windows.
5. GUI architecture
- nostr-vpn-gui is a Tauri app with a Svelte frontend and a Rust backend.
- On desktop, the GUI shells out to the nvpn sidecar/CLI for service control and networking.
- On mobile, it uses platform-specific VPN runtime code in src-tauri instead of relying on the desktop sidecar pattern.
- The GUI is therefore a presentation and orchestration layer, not the owner of the core networking protocol.
6. Platform-specific tunnel boundaries
- The repository has explicit platform adapters for VPN lifecycle and tunnel interfaces:
- Windows: wintun support plus Windows service integration
- Android: native service/plugin code under src-tauri/gen/android
- iOS/macOS: Packet Tunnel and Apple project files under src-tauri/gen/apple
- These adapters isolate OS-specific tunnel creation, permissions, and lifecycle from the shared protocol logic.
7. External network dependencies
- Nostr relays are the main distributed signaling dependency; peers publish and consume private peer announcements through relays.
- NAT traversal uses STUN/reflector-style discovery and UDP hole punching.
- WireGuard traffic flows directly between peers once endpoints are discovered and the tunnel is established.
- Default relays are bundled as fallbacks when a network config does not specify its own relay list.
8. Configuration and identity model
- The app persists a single config file containing global settings and one or more named networks.
- Each network has its own stable network_id, participant allowlist, and active/inactive state.
- The config also stores Nostr relay URLs, keys, NAT discovery settings, tunnel IP, endpoint, and advertised routes.
- The design supports multiple saved networks, but only one active network participates in the live runtime.
9. Session and routing features
- Once connected, the system tracks peer presence, endpoints, and health, then configures the WireGuard session accordingly.
- The core supports route advertisement and exit-node selection, so the VPN can act as a routed mesh, not just a point-to-point tunnel.
- MagicDNS and diagnostics are part of the same operational surface, which means name resolution and health status are first-class features of the control plane.
10. Local test infrastructure
- nostr-vpn-relay provides a minimal websocket relay for integration tests and e2e scenarios.
- nvpn-reflector provides a minimal UDP reflector for NAT discovery and hole-punch testing.
- These are not production services; they exist to validate signaling and traversal behavior in controlled environments.
11. End-to-end validation environment
- The repo contains Docker-based e2e scripts that exercise relay connectivity, mesh formation, NAT traversal, exit-node routing, and GUI smoke flows.
- This indicates the project expects real tunnel devices and container networking privileges during validation.
- For an architecture diagram, it is useful to show an explicit “test harness / local infrastructure” boundary separate from production components.
12. Release and distribution boundaries
- Releases are multi-platform and include:
- desktop CLI archives
- signed macOS and Windows GUI artifacts
- Android APK/AAB artifacts
- The GUI and CLI are built and validated in CI, but the runtime architecture remains centered on the shared core plus platform wrappers.
Main entry points: main.rs nvpn · lib.rs Backend · e2e-docker.sh E2E harness · signaling.rs Signaling
Components 20
Core
Shared protocol, state, and tunnel logic used by all front ends.
- Config · Persistent network model, paths, relay settings, and active-network selection.
crates/nostr-vpn-core/src/config.rs - Identity · Key generation and cryptographic identity used for peers and signaling.
crates/nostr-vpn-core/src/crypto.rs - Signaling · Nostr relay messaging, join requests, service signaling, and roster coordination.
crates/nostr-vpn-core/src/signaling.rs - Session · Presence, node records, roster state, and session lifecycle coordination.
crates/nostr-vpn-core/src/presence.rs - NAT · Endpoint discovery and hole-punch support for peer connectivity.
crates/nostr-vpn-core/src/nat.rs - MagicDNS · Mesh name resolution and peer name mapping.
crates/nostr-vpn-core/src/magic_dns.rs - WireGuard · Userspace WireGuard configuration and rendering helpers for tunnel bring-up.
crates/nostr-vpn-core/src/wireguard.rs - Diagnostics · Shared status, health, and diagnostic reporting surface.
crates/nostr-vpn-core/src/diagnostics.rs
CLI
Headless command-line client and daemon runtime.
- nvpn · Headless command-line entry point for connect, daemon lifecycle, service control, and networking commands.
crates/nostr-vpn-cli/src/main.rs - Ops tools · Doctor bundles, netcheck, status, and other operational commands.
crates/nostr-vpn-cli/src/diagnostics.rs - Userspace WG · Desktop/server userspace tunnel orchestration built around boringtun.
crates/nostr-vpn-cli/src/userspace_wg.rs
GUI
Tauri desktop/mobile application and platform backends.
- Tauri app · Svelte frontend plus Rust backend for desktop and mobile orchestration.
crates/nostr-vpn-gui/src/App.svelte - Backend · Rust-side orchestration layer for UI commands and platform bridging.
crates/nostr-vpn-gui/src-tauri/src/lib.rs - Sidecar · Desktop path that shells out to nvpn for service control and networking.
crates/nostr-vpn-gui/scripts/prepare-sidecar.mjs
Platform Adapters
OS-specific tunnel and service integrations.
- Windows tunnel · Windows-specific tunnel and service integration used by the CLI.
crates/nostr-vpn-cli/src/windows_tunnel.rs - Mobile VPN · Android and iOS VPN session code used instead of the desktop sidecar path.
crates/nostr-vpn-gui/src-tauri/src/mobile_wg.rs
Test Infra
Local relay, reflector, and end-to-end validation harnesses.
- Test relay · Minimal websocket relay for integration and end-to-end signaling tests.
crates/nostr-vpn-relay/src/bin/nvpn-udp-relay.rs - Reflector · Minimal UDP reflector used to validate NAT discovery and traversal.
crates/nostr-vpn-relay/src/bin/nvpn-reflector.rs - E2E harness · Docker-based scripts and Tauri driver flows for full-stack validation.
scripts/e2e-docker.sh
Other components
- Workspace · Top-level multi-crate repository coordinating shared core and front ends.
Connections 28
- Workspace → Config: contains
- Workspace → nvpn: contains
- Workspace → Tauri app: contains
- Workspace → Test relay: contains
- Workspace → Reflector: contains
- Workspace → E2E harness: contains
- nvpn → Config: uses
- nvpn → Signaling: uses
- nvpn → WireGuard: uses
- nvpn → Ops tools: exposes
- nvpn → Userspace WG: orchestrates
- nvpn → Windows tunnel: adapts
- Tauri app → Backend: drives
- Backend → Config: uses
- Backend → Signaling: uses
- Backend → Diagnostics: uses
- Backend → Sidecar: desktop path
- Backend → Mobile VPN: mobile path
- Identity → Signaling: signs
- Session → WireGuard: configures
- NAT → Reflector: tests against
- NAT → WireGuard: feeds endpoints
- MagicDNS → Session: names peers
- Signaling → Test relay: talks to
- E2E harness → Test relay: spins up
- E2E harness → Reflector: spins up
- E2E harness → Tauri app: smokes
- E2E harness → nvpn: exercises