Architecture Overview
The Mullvad VPN application is a privacy-focused VPN client built with a security-first architecture. The application consists of multiple layers and components designed to maintain strict security guarantees while providing seamless user experience across desktop and mobile platforms.High-Level Components
The Mullvad VPN application is structured into two primary layers:Mullvad Layer
The Mullvad layer contains application-specific business logic:- Account and device management
- Relay selection and constraints
- API communication (api.mullvad.net)
- Settings persistence
- Management interface for frontend communication
Talpid Layer
Talpid is the generic VPN tunnel management layer that provides:- Tunnel state machine
- Firewall integration
- DNS management
- Routing configuration
- Split tunneling support
- Platform-specific implementations
System Architecture
The application follows a client-server architecture with the daemon as the core component:Key Architectural Principles
Actor-Based Asynchronous Design
The daemon uses an actor system built on Tokio to handle multiple concurrent operations:- Non-blocking message processing
- Concurrent API requests
- Asynchronous state transitions
- Multiple frontend client support
Security-First State Management
The tunnel state machine enforces strict security policies:- No data leaks between states
- Firewall rules applied before tunnel establishment
- Blocking states prevent unprotected traffic
- Fail-secure error handling
Platform Abstraction
Platform-specific code is isolated in dedicated modules:talpid-windows: Windows-specific implementationstalpid-macos: macOS-specific implementationstalpid-routing: Cross-platform routing with platform backends- Android and iOS have their own native integration layers
Workspace Structure
The codebase is organized as a Cargo workspace with the following key crates:Core Daemon Components
- mullvad-daemon: Main daemon process and orchestration
- mullvad-management-interface: gRPC interface definitions
- mullvad-cli: Command-line interface client
- talpid-core: Tunnel state machine and core VPN logic
Platform Integration
- mullvad-jni: Android JNI bindings
- mullvad-ios: iOS integration layer
- desktop/: Electron desktop application
Networking Components
- talpid-tunnel: Tunnel creation and management (WireGuard, OpenVPN)
- talpid-wireguard: WireGuard-specific implementation
- talpid-routing: System routing table management
- talpid-dns: DNS configuration and monitoring
Auxiliary Services
- mullvad-api: REST API client for Mullvad services
- mullvad-relay-selector: Relay selection algorithm
- mullvad-encrypted-dns-proxy: DNS-over-HTTPS proxy
- tunnel-obfuscation: Traffic obfuscation (Shadowsocks, UDP-over-TCP)
Security & Configuration
- mullvad-types: Shared type definitions
- mullvad-fs: Secure filesystem operations
- mullvad-leak-checker: Connection leak detection
Communication Patterns
Frontend to Daemon
- Desktop (Electron/CLI): gRPC over Unix domain socket (Unix) or named pipe (Windows)
- Android: JNI (Java Native Interface) calls from Java/Kotlin to Rust daemon
- iOS: Uses WireGuard-kit with custom integration layer
Daemon to API
- REST over HTTPS to api.mullvad.net
- Optional Shadowsocks proxying for censorship resistance
- Connection pooling and retry logic
- Non-blocking concurrent requests
Internal Actor Communication
- Message passing via Tokio channels
- Command/response pattern for synchronous-style interactions
- Event streams for state change notifications
- Careful deadlock avoidance through async design
Data Flow Example
When a user initiates a VPN connection:- Frontend sends
ConnectTunnelcommand via gRPC/JNI - Management Interface receives command and forwards to daemon
- Daemon requests relay from Relay Selector
- Tunnel State Machine transitions from
Disconnected→Connecting - Firewall applies blocking rules before tunnel establishment
- Route Manager configures system routing tables
- DNS Manager sets up secure DNS configuration
- Tunnel establishes WireGuard connection to selected relay
- Tunnel Monitor verifies connectivity
- State Machine transitions to
Connectedstate - Frontend receives state update notification and displays connected status
Related Documentation
- Daemon Architecture - Detailed daemon internals
- Frontend Architectures - Platform-specific frontend implementations
- Tunnel State Machine - State management and transitions
- Security Model - Security guarantees and threat model
- Relay Selection - Relay selection algorithm