How nodepassproject/anywhere works
1. Overall shape
Anywhere is a multi-target Apple-platform networking app with three main runtime pieces: the main client app (Anywhere), a packet-tunnel network extension (Anywhere Network Extension), and a small widget/Control Center surface (Anywhere Widget). The codebase is split so UI, shared domain logic, and low-level tunnel/protocol engines are reusable across iPhone, iPad, and tvOS variants.
2. Main app as control plane
The Anywhere target is the user-facing control plane built mostly in SwiftUI. It hosts onboarding, home/status, proxy management, settings, MITM/rule editors, logs, and import flows. ViewModels and Stores bridge UI state to persistent configuration and runtime status, while DeepLinkManager and the URL-scheme handling support importing proxies and rule sets from external links.
3. Shared domain layer
The Shared directory is the app’s common core. It contains the model types for proxies, proxy chains, routing rules, subscriptions, tunnel messages, and latency results; shared utilities; and the networking domain objects used by both the app and the extension. This is the main boundary between UI and runtime systems.
4. Configuration and persistence
Configuration is stored through Shared/DataStore, which contains stores for certificates, chains, routing rules, MITM rule sets, subscriptions, and blob-backed state. There is also a local routing database (Rules.db) and import parsers for rule-set formats. The architecture is centered on local persisted config rather than a remote backend.
5. Proxy/protocol engine
Shared/Networking/Protocols is the core transport layer. It implements multiple proxy protocols natively: VLESS, Hysteria2, Trojan, AnyTLS, Shadowsocks, Sudoku, SOCKS5, Naive, plus protocol-specific transports and multiplexers. This layer is where outbound connections are actually formed, authenticated, encrypted, multiplexed, and adapted to TCP, UDP, HTTP, QUIC, TLS, WebSocket, gRPC, and XHTTP variants.
6. QUIC and crypto as first-class subsystems
QUIC is not delegated to a system wrapper; it is implemented with vendored ngtcp2 under Shared/Networking/ngtcp2. Crypto and protocol framing are also mostly native, with in-repo implementations for TLS handshakes, HPACK/QPACK, BLAKE2/3, VLESS encryption, and protocol-specific obfuscation or padding. This is a major architectural boundary: protocol correctness and transport behavior live inside the repo.
7. Packet tunnel and userspace network stack
The Anywhere Network Extension target is the system VPN engine. PacketTunnelProvider is the entry point, and TunnelStack plus TunnelScheduler orchestrate per-flow handling. The extension includes a userspace TCP/IP stack built on vendored lwIP, which allows the app to terminate and re-create IP traffic inside the tunnel instead of relying only on higher-level socket interception.
8. Traffic classification and routing
The tunnel side contains DNS handling, fake-IP support, domain routing, and flow sniffing (DNSPacket, DomainRouter, FakeIPPool, HTTPRequestSniffer, TLSClientHelloSniffer). The flow is: incoming packet flow -> classify protocol/domain -> resolve route target -> either connect directly or build a proxy chain/protocol session. This is the heart of transparent routing for all apps on the device.
9. MITM and HTTP rewrite subsystem
The Anywhere Network Extension/MITM subtree is a dedicated interception engine for HTTP/S traffic. It includes request logging, session tracking, header/body rewriting, regex gates, JSON patching, synthetic responses, certificate caching, and a script engine/store/watchdog for process(ctx)-style transformations. The app-side settings screens under Anywhere/Views/Settings/MITM manage rule sets, certificates, and script profiles for this subsystem.
10. Rule evaluation and import pipelines
Routing rules and MITM rule sets are imported, parsed, stored, and evaluated separately. Routing rule parsing lives in the app UI layer, while Shared/Networking/RuleResolver.swift and the data-store database represent the runtime side of rule matching. Subscription fetching and catalog helpers feed these pipelines, so the system can keep proxy lists, routing policies, and MITM policies synchronized from local or remote sources.
11. Status, metrics, and logs
Runtime observability is split across StatsRecorder, RequestLog, TransportErrorLogger, ConnectionMetrics, and the shared view models like ConnectionStatsModel, LogsModel, and RequestsModel. The tunnel and protocol layers emit events upward, and the UI renders connection state, request history, and performance indicators from those models.
12. Platform integration surfaces
The widget target provides VPN and mode toggle controls, acting as a lightweight external control surface. The tvOS target is a separate management UI with its own navigation and proxy/config editors, sharing the same configuration and networking model layer. This means the architecture is not single-app UI only; it has multiple front ends over one shared networking core.
13. Testing and deterministic support
Anywhere Tests focuses on configuration connectivity and deterministic byte-level behavior, with support helpers that spin up tunneled HTTP/1, HTTP/2, and HTTP/3 clients. That suggests the architecture is validated at protocol and tunnel boundaries, not just at UI or unit level.
14. Primary dependency boundaries
The repo deliberately minimizes external runtime dependencies. Apple frameworks handle app/UI/tunnel integration, while the only major vendored native subsystems are lwIP, ngtcp2, and embedded crypto/parsing libraries such as libyaml. Those native libraries are concentrated in the tunnel and protocol layers, keeping the app and shared layers mostly Swift.
Main entry points: TunnelStack.swift Tunnel stack · ConfigurationStore.swift Config store · RuleResolver.swift Rule resolver · VLESSProtocol.swift Protocols
Components 21
Anywhere app
Main SwiftUI control plane and settings UI
- Anywhere · Main iPhone/iPad control plane entry point
Anywhere/AnywhereApp.swift - Home UI · Primary screens for onboarding, home, proxies, and settings
Anywhere/Views/Home/HomeView.swift - Settings · Settings, MITM, routing, logs, requests, and import flows
Anywhere/Views/Settings/SettingsView.swift - Deep links · External link handling and import entrypoints
Anywhere/DeepLinkManager.swift - App store · User-facing store coordinating configuration and runtime state
Anywhere/Stores/VoyagerStore.swift - Voyager UI · Voyager onboarding and feature surface
Anywhere/Views/Voyager/AnywhereVoyagerView.swift
Shared core
Common models, persistence, networking, and utilities
- Domain models · Proxy, routing, subscription, tunnel, and latency types
Shared/Models/ProxyChain.swift - Config store · Certificate, chain, rule, subscription, and blob-backed persistence
Shared/DataStore/ConfigurationStore.swift - Rule resolver · Runtime routing and rule matching boundary
Shared/Networking/RuleResolver.swift - Proxy core · Protocol-agnostic proxy client, transports, tunnels, and framing
Shared/Networking/Protocols/Core/ProxyClient.swift - Protocols · Concrete proxy protocols such as VLESS, Hysteria, Trojan, Shadowsocks, AnyTLS, SOCKS5, Naive, Sudoku, and Nowhere
Shared/Networking/Protocols/VLESS/VLESSProtocol.swift - TLS/QUIC · Native TLS, QUIC, HPACK/QPACK, and crypto framing implementation
Shared/Networking/Protocols/QUIC/QUICConnection.swift - Vendored cores · Embedded QUIC, YAML, and other native support libraries
Shared/Networking/ngtcp2/ngtcp2_conn.c
Network extension
Packet tunnel engine, routing, MITM, and userspace stack
- Packet tunnel · VPN extension entrypoint and lifecycle
Anywhere Network Extension/PacketTunnelProvider.swift - Tunnel stack · Flow scheduling, packet handling, and protocol adaptation
Anywhere Network Extension/TunnelStack/TunnelStack.swift - Routing · DNS, fake IP, domain routing, and sniffing
Anywhere Network Extension/DomainRouter.swift - MITM engine · HTTP/S interception, logging, rewriting, synthetic responses, and scripts
Anywhere Network Extension/MITM/MITMScriptEngine.swift - lwIP stack · Vendored userspace TCP/IP stack used inside the tunnel
Anywhere Network Extension/lwip/lwip_bridge.c
Other front ends
tvOS and widget surfaces
- Anywhere TV · Separate tvOS management UI for proxies and configuration
Anywhere TV/AppDelegate.swift - Widget · Compact VPN and mode toggle controls
Anywhere Widget/WidgetBundle.swift
Tests
Protocol and tunnel validation
- Tests · Deterministic byte-level and tunneled HTTP/1, HTTP/2, and HTTP/3 validation
Anywhere Tests/ConfigurationConnectivityTests.swift
Connections 25
- Anywhere → Home UI: hosts · Main app presents the primary UI flow
- Anywhere → Settings: hosts · Main app presents settings and import flows
- Anywhere → Deep links: routes · URL imports and external actions enter here
- Home UI → App store: binds · Home and proxy screens read and update state
- Settings → Config store: edits · Settings persist proxy, certificate, and rule configuration
- Settings → Rule resolver: configures · Rule editors feed runtime matching data
- Voyager UI → App store: uses · Voyager flow is backed by app state
- Config store → Domain models: persists · Stores serialize shared domain objects
- Config store → Rule resolver: loads · Routing data is restored for matching
- Rule resolver → Domain models: matches · Resolver evaluates route targets and proxy chains
- Proxy core → Protocols: adapts · Protocol implementations plug into common connection abstractions
- Protocols → TLS/QUIC: relies on · Protocols use native TLS and QUIC primitives
- TLS/QUIC → Vendored cores: builds on · QUIC and parsing support come from vendored native code
- Packet tunnel → Tunnel stack: starts · Packet tunnel provider initializes the flow engine
- Tunnel stack → Routing: classifies · Incoming traffic is routed by DNS, domain, and sniffed metadata
- Tunnel stack → MITM engine: intercepts · HTTP/S flows can be rewritten or synthesized
- Tunnel stack → lwIP stack: drives · Userspace stack terminates and recreates IP traffic
- Routing → Rule resolver: consults · Runtime routing decisions use shared rule resolution
- Tunnel stack → Proxy core: opens · Tunnel flows are turned into proxy connections
- Tunnel stack → Protocols: speaks · Selected outbound protocol/session is constructed
- MITM engine → Config store: uses · MITM settings and cert data are persisted centrally
- Anywhere TV → Config store: shares · tvOS management UI uses the same configuration layer
- Widget → App store: controls · Widget toggles VPN and mode state through app storage
- Tests → Tunnel stack: verifies · Tests exercise tunnel and transport boundaries
- Tests → Protocols: verifies · Tests cover protocol behavior and deterministic byte handling