# mysteriumnetwork/node architecture

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

- Interactive diagram: https://gitdiagram.com/mysteriumnetwork/node
- Repository: https://github.com/mysteriumnetwork/node

## Overview

#### Purpose and Executables
Mysterium Node is a cross-platform Go implementation of a decentralized VPN node: provider and consumer roles, a local HTTP “Tequila” API, and CLI control. The principal binary starts from `cmd/mysterium_node/mysterium_node.go`, with composition/bootstrap in `cmd/bootstrap.go` and `cmd/node.go`. Supporting executables include the secure package updater (`cmd/myst_updater/main.go`), NAT discovery (`cmd/natdisco/main.go`), port checking, and a privileged supervisor.

#### Process Composition and Local Control Plane
Dependency injection wires configuration, identity, storage, networking, service implementations, API, and lifecycle management at startup. CLI commands expose account, connection, service, daemon, configuration, and reset operations through `cmd/commands/`. Tequila is the node’s local HTTP boundary: routes/handlers translate client requests into core operations, enforce auth middleware, and expose SSE/events and API contracts. Key paths: `tequilapi/http_api_server.go`, `tequilapi/endpoints/`, `tequilapi/contract/`.

#### Node Lifecycle, State, and Persistence
Core orchestration manages node options, service registration, connections, sessions, state events, and cleanup. BoltDB persists registration, identities-related state, session/settlement histories, and migration state; it is an important restart and upgrade boundary. Event bus and typed event packages decouple state changes from API/status consumers. Key paths: `core/node/`, `core/service/manager.go`, `core/connection/manager.go`, `core/storage/boltdb/storage.go`.

#### Marketplace Discovery and Identity
Consumers discover purchasable provider proposals through interchangeable API, broker, and DHT repositories, then filter/sort/reduce proposals before connecting. Node identity is filesystem-keystore-backed, signs/verifies protocol data, and supports blockchain registry/transactor integration. Market types define contacts, locations, pricing, quality, and proposals. Key paths: `core/discovery/`, `identity/manager.go`, `identity/registry/`, `market/service_proposal.go`.

#### VPN Transport and Network Boundaries
The service layer abstracts transport types and registers WireGuard, QUIC, OpenVPN, data transfer, monitoring, and no-op implementations. WireGuard is the supported underlying VPN transport and has endpoint variants for kernel/userspace, netstack, proxy, remote, and platform-specific TUN/network behavior. Connection setup crosses OS networking/DNS/routing/firewall boundaries; provider-facing NAT traversal, UPnP mapping, hole punching, and reachability support inbound connectivity. Key paths: `services/wireguard/`, `p2p/`, `nat/`, `firewall/`.

#### Sessions, Payments, and Remote Messaging
Session creation connects consumer and provider service endpoints, tracks bandwidth/time/connectivity, and publishes lifecycle events. Ping-pong settlement calculates usage pricing, exchanges invoices/promises, tracks balances, and persists settlement history; Hermes is the payment-channel-facing integration. NATS-backed communication provides signed messaging/request-response for broker discovery and related remote control flows. Key paths: `session/pingpong/`, `consumer/session/`, `communication/nats/`, `pilvytis/`.

#### Deployment, Platforms, and Operations
Runtime targets desktop/server Linux, Windows, macOS, Android/iOS mobile bindings, and Docker. Linux packaging installs systemd node and updater services; the updater validates authenticated Debian artifacts and verifies post-update health. A separate supervisor handles privileged platform/WireGuard operations. External integrations include Ethereum/geth-compatible chain operations, NATS, discovery APIs/DHT, Hermes/Pilvytis payment services, Elasticsearch/Morqa quality reporting, GitHub version release lookup, and optional Docker. Key paths: `supervisor/daemon/`, `updater/deb/updater.go`, `bin/package/installation/`, `mobile/mysterium/`.

Main entry points: [`tequilapi/http_api_server.go`](https://github.com/mysteriumnetwork/node/blob/master/tequilapi/http_api_server.go) (Tequila API server), [`cmd/bootstrap.go`](https://github.com/mysteriumnetwork/node/blob/master/cmd/bootstrap.go) (Bootstrap composition), [`core/connection/manager.go`](https://github.com/mysteriumnetwork/node/blob/master/core/connection/manager.go) (Connection manager), [`cmd/mysterium_node/mysterium_node.go`](https://github.com/mysteriumnetwork/node/blob/master/cmd/mysterium_node/mysterium_node.go) (Mysterium Node)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entrypoints"]
  node_node_binary["Mysterium Node<br/>Go executable<br/>[mysterium_node.go]"]
  node_bootstrap["Bootstrap composition<br/>dependency injection<br/>[bootstrap.go]"]
  node_cli["CLI commands<br/>local control"]
end

subgraph group_control["Local Control Plane"]
  node_tequila["Tequila API server<br/>local HTTP API<br/>[http_api_server.go]"]
  node_api_endpoints["API endpoints<br/>HTTP handlers"]
  node_api_contracts["API contracts<br/>API models"]
end

subgraph group_core["Node Core"]
  node_node_core["Node orchestration<br/>lifecycle and state"]
  node_service_manager["Service manager<br/>transport registry<br/>[manager.go]"]
  node_connection_manager["Connection manager<br/>connection lifecycle<br/>[manager.go]"]
  node_storage[("BoltDB storage<br/>persistent state<br/>[storage.go]")]
  node_identity["Identity manager<br/>keystore identity<br/>[manager.go]"]
end

subgraph group_network["Network &amp; Marketplace"]
  node_discovery["Proposal discovery<br/>market repository"]
  node_market["Market proposals<br/>market model"]
  node_wireguard["WireGuard service<br/>VPN transport"]
  node_p2p_nat["P2P and NAT traversal<br/>inbound reachability"]
  node_consumer_session["Consumer sessions<br/>session lifecycle"]
  node_settlement["Ping-pong settlement<br/>usage payments"]
  node_nats["NATS communication<br/>signed messaging"]
end

subgraph group_operations["Platform Operations"]
  node_supervisor["Privileged supervisor<br/>platform daemon"]
  node_updater["Secure package updater<br/>updater executable<br/>[updater.go]"]
  node_mobile["Mobile bindings<br/>mobile runtime"]
end

node_node_binary -->|"starts"| node_bootstrap
node_bootstrap -->|"composes"| node_node_core
node_bootstrap -->|"starts"| node_tequila
node_cli -->|"controls"| node_tequila
node_tequila -->|"routes to"| node_api_endpoints
node_api_endpoints -->|"uses"| node_api_contracts
node_api_endpoints -->|"invokes"| node_node_core
node_node_core -->|"registers services"| node_service_manager
node_node_core -->|"manages"| node_connection_manager
node_node_core -->|"persists state"| node_storage
node_node_core -->|"uses"| node_identity
node_connection_manager -->|"selects proposals"| node_discovery
node_discovery -->|"filters and ranks"| node_market
node_discovery -->|"uses broker discovery"| node_nats
node_service_manager -->|"registers"| node_wireguard
node_connection_manager -->|"creates"| node_consumer_session
node_consumer_session -->|"connects through"| node_wireguard
node_consumer_session -->|"reports usage"| node_settlement
node_settlement -->|"stores history"| node_storage
node_wireguard -->|"requires reachability"| node_p2p_nat
node_wireguard -->|"delegates privileged operations"| node_supervisor
node_updater -.->|"updates"| node_node_binary
node_mobile -->|"controls node via"| node_tequila

click node_node_binary "https://github.com/mysteriumnetwork/node/blob/master/cmd/mysterium_node/mysterium_node.go"
click node_bootstrap "https://github.com/mysteriumnetwork/node/blob/master/cmd/bootstrap.go"
click node_tequila "https://github.com/mysteriumnetwork/node/blob/master/tequilapi/http_api_server.go"
click node_service_manager "https://github.com/mysteriumnetwork/node/blob/master/core/service/manager.go"
click node_connection_manager "https://github.com/mysteriumnetwork/node/blob/master/core/connection/manager.go"
click node_storage "https://github.com/mysteriumnetwork/node/blob/master/core/storage/boltdb/storage.go"
click node_identity "https://github.com/mysteriumnetwork/node/blob/master/identity/manager.go"
click node_market "https://github.com/mysteriumnetwork/node/blob/master/market/service_proposal.go"
click node_updater "https://github.com/mysteriumnetwork/node/blob/master/updater/deb/updater.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_node_binary,node_bootstrap,node_cli toneBlue
class node_tequila,node_api_endpoints,node_api_contracts toneAmber
class node_node_core,node_service_manager,node_connection_manager,node_storage,node_identity toneMint
class node_discovery,node_market,node_wireguard,node_p2p_nat,node_consumer_session,node_settlement,node_nats toneRose
class node_supervisor,node_updater,node_mobile toneIndigo
```

## Components

### Entrypoints

- [Mysterium Node](https://github.com/mysteriumnetwork/node/blob/master/cmd/mysterium_node/mysterium_node.go): Go executable · Principal provider and consumer node process. · `cmd/mysterium_node/mysterium_node.go`
- [Bootstrap composition](https://github.com/mysteriumnetwork/node/blob/master/cmd/bootstrap.go): dependency injection · Wires runtime dependencies and lifecycle. · `cmd/bootstrap.go`
- **CLI commands**: local control

### Local Control Plane

- [Tequila API server](https://github.com/mysteriumnetwork/node/blob/master/tequilapi/http_api_server.go): local HTTP API · Authenticated local API with SSE events. · `tequilapi/http_api_server.go`
- **API endpoints**: HTTP handlers
- **API contracts**: API models

### Node Core

- **Node orchestration**: lifecycle and state · Coordinates options, services, connections, sessions, and cleanup.
- [Service manager](https://github.com/mysteriumnetwork/node/blob/master/core/service/manager.go): transport registry · `core/service/manager.go`
- [Connection manager](https://github.com/mysteriumnetwork/node/blob/master/core/connection/manager.go): connection lifecycle · `core/connection/manager.go`
- [BoltDB storage](https://github.com/mysteriumnetwork/node/blob/master/core/storage/boltdb/storage.go): persistent state · Restart, history, and migration persistence boundary. · `core/storage/boltdb/storage.go`
- [Identity manager](https://github.com/mysteriumnetwork/node/blob/master/identity/manager.go): keystore identity · Filesystem-backed signing identity. · `identity/manager.go`

### Network & Marketplace

- **Proposal discovery**: market repository · Combines API, broker, and DHT proposal sources.
- [Market proposals](https://github.com/mysteriumnetwork/node/blob/master/market/service_proposal.go): market model · `market/service_proposal.go`
- **WireGuard service**: VPN transport · Supports kernel, userspace, netstack, proxy, remote, and platform endpoints.
- **P2P and NAT traversal**: inbound reachability · Hole punching, UPnP, and reachability support.
- **Consumer sessions**: session lifecycle · Connects consumer and provider endpoints and tracks usage.
- **Ping-pong settlement**: usage payments · Exchanges invoices and promises and records balances.
- **NATS communication**: signed messaging · Broker request-response and remote control transport.

### Platform Operations

- **Privileged supervisor**: platform daemon · Performs privileged platform and WireGuard operations.
- [Secure package updater](https://github.com/mysteriumnetwork/node/blob/master/updater/deb/updater.go): updater executable · Validates Debian artifacts and post-update health. · `updater/deb/updater.go`
- **Mobile bindings**: mobile runtime

## Connections

- Mysterium Node → Bootstrap composition: starts
- Bootstrap composition → Node orchestration: composes
- Bootstrap composition → Tequila API server: starts
- CLI commands → Tequila API server: controls
- Tequila API server → API endpoints: routes to
- API endpoints → API contracts: uses
- API endpoints → Node orchestration: invokes
- Node orchestration → Service manager: registers services
- Node orchestration → Connection manager: manages
- Node orchestration → BoltDB storage: persists state
- Node orchestration → Identity manager: uses
- Connection manager → Proposal discovery: selects proposals
- Proposal discovery → Market proposals: filters and ranks
- Proposal discovery → NATS communication: uses broker discovery
- Service manager → WireGuard service: registers
- Connection manager → Consumer sessions: creates
- Consumer sessions → WireGuard service: connects through
- Consumer sessions → Ping-pong settlement: reports usage
- Ping-pong settlement → BoltDB storage: stores history
- WireGuard service → P2P and NAT traversal: requires reachability
- WireGuard service → Privileged supervisor: delegates privileged operations
- Secure package updater → Mysterium Node: updates
- Mobile bindings → Tequila API server: controls node via
