# nodepassproject/anywhere architecture

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

- Interactive diagram: https://gitdiagram.com/nodepassproject/anywhere
- Repository: https://github.com/nodepassproject/anywhere

## Overview

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: [`Anywhere Network Extension/TunnelStack/TunnelStack.swift`](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Network%20Extension/TunnelStack/TunnelStack.swift) (Tunnel stack), [`Shared/DataStore/ConfigurationStore.swift`](https://github.com/nodepassproject/anywhere/blob/main/Shared/DataStore/ConfigurationStore.swift) (Config store), [`Shared/Networking/RuleResolver.swift`](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/RuleResolver.swift) (Rule resolver), [`Shared/Networking/Protocols/VLESS/VLESSProtocol.swift`](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/VLESS/VLESSProtocol.swift) (Protocols)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Anywhere app"]
  node_app_entry["Anywhere<br/>swiftui app<br/>[AnywhereApp.swift]"]
  node_app_home["Home UI<br/>swiftui views<br/>[HomeView.swift]"]
  node_app_settings["Settings<br/>[SettingsView.swift]"]
  node_app_deeplink["Deep links<br/>url import"]
  node_app_stores[("App store<br/>state store<br/>[VoyagerStore.swift]")]
  node_app_voyager["Voyager UI<br/>feature flow"]
end

subgraph group_shared["Shared core"]
  node_shared_models["Domain models<br/>core models<br/>[ProxyChain.swift]"]
  node_shared_store[("Config store<br/>persistence")]
  node_shared_rule["Rule resolver<br/>routing logic<br/>[RuleResolver.swift]"]
  node_shared_netcore["Proxy core<br/>transport core<br/>[ProxyClient.swift]"]
  node_shared_protocols["Protocols"]
  node_shared_tls_quic["TLS/QUIC<br/>crypto transport"]
  node_shared_vendor["Vendored cores<br/>native deps<br/>[ngtcp2_conn.c]"]
end

subgraph group_tunnel["Network extension"]
  node_tunnel_entry["Packet tunnel<br/>network extension"]
  node_tunnel_stack["Tunnel stack<br/>flow engine<br/>[TunnelStack.swift]"]
  node_tunnel_route["Routing<br/>classification<br/>[DomainRouter.swift]"]
  node_tunnel_mitm["MITM engine<br/>http rewrite"]
  node_tunnel_stackcore["lwIP stack<br/>userspace ip stack<br/>[lwip_bridge.c]"]
end

subgraph group_platforms["Other front ends"]
  node_platform_tv["Anywhere TV<br/>tvOS app<br/>[AppDelegate.swift]"]
  node_platform_widget["Widget<br/>[WidgetBundle.swift]"]
end

subgraph group_tests["Tests"]
  node_test_suite["Tests"]
end

node_app_entry -->|"hosts"| node_app_home
node_app_entry -->|"hosts"| node_app_settings
node_app_entry -->|"routes"| node_app_deeplink
node_app_home -->|"binds"| node_app_stores
node_app_settings -->|"edits"| node_shared_store
node_app_settings -->|"configures"| node_shared_rule
node_app_voyager -->|"uses"| node_app_stores
node_shared_store -->|"persists"| node_shared_models
node_shared_store -->|"loads"| node_shared_rule
node_shared_rule -->|"matches"| node_shared_models
node_shared_netcore -->|"adapts"| node_shared_protocols
node_shared_protocols -->|"relies on"| node_shared_tls_quic
node_shared_tls_quic -->|"builds on"| node_shared_vendor
node_tunnel_entry -->|"starts"| node_tunnel_stack
node_tunnel_stack -->|"classifies"| node_tunnel_route
node_tunnel_stack -->|"intercepts"| node_tunnel_mitm
node_tunnel_stack -->|"drives"| node_tunnel_stackcore
node_tunnel_route -->|"consults"| node_shared_rule
node_tunnel_stack -->|"opens"| node_shared_netcore
node_tunnel_stack -->|"speaks"| node_shared_protocols
node_tunnel_mitm -->|"uses"| node_shared_store
node_platform_tv -->|"shares"| node_shared_store
node_platform_widget -->|"controls"| node_app_stores
node_test_suite -->|"verifies"| node_tunnel_stack
node_test_suite -->|"verifies"| node_shared_protocols

click node_app_entry "https://github.com/nodepassproject/anywhere/blob/main/Anywhere/AnywhereApp.swift"
click node_app_home "https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Views/Home/HomeView.swift"
click node_app_settings "https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Views/Settings/SettingsView.swift"
click node_app_deeplink "https://github.com/nodepassproject/anywhere/blob/main/Anywhere/DeepLinkManager.swift"
click node_app_stores "https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Stores/VoyagerStore.swift"
click node_app_voyager "https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Views/Voyager/AnywhereVoyagerView.swift"
click node_shared_models "https://github.com/nodepassproject/anywhere/blob/main/Shared/Models/ProxyChain.swift"
click node_shared_store "https://github.com/nodepassproject/anywhere/blob/main/Shared/DataStore/ConfigurationStore.swift"
click node_shared_rule "https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/RuleResolver.swift"
click node_shared_netcore "https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/Core/ProxyClient.swift"
click node_shared_protocols "https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/VLESS/VLESSProtocol.swift"
click node_shared_tls_quic "https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/QUIC/QUICConnection.swift"
click node_shared_vendor "https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/ngtcp2/ngtcp2_conn.c"
click node_tunnel_entry "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Network Extension/PacketTunnelProvider.swift"
click node_tunnel_stack "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Network Extension/TunnelStack/TunnelStack.swift"
click node_tunnel_route "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Network Extension/DomainRouter.swift"
click node_tunnel_mitm "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Network Extension/MITM/MITMScriptEngine.swift"
click node_tunnel_stackcore "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Network Extension/lwip/lwip_bridge.c"
click node_platform_tv "https://github.com/nodepassproject/anywhere/blob/main/Anywhere TV/AppDelegate.swift"
click node_platform_widget "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Widget/WidgetBundle.swift"
click node_test_suite "https://github.com/nodepassproject/anywhere/blob/main/Anywhere Tests/ConfigurationConnectivityTests.swift"

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_app_entry,node_app_home,node_app_settings,node_app_deeplink,node_app_stores,node_app_voyager toneBlue
class node_shared_models,node_shared_store,node_shared_rule,node_shared_netcore,node_shared_protocols,node_shared_tls_quic,node_shared_vendor toneAmber
class node_tunnel_entry,node_tunnel_stack,node_tunnel_route,node_tunnel_mitm,node_tunnel_stackcore toneMint
class node_platform_tv,node_platform_widget toneRose
class node_test_suite toneIndigo
```

## Components

### Anywhere app

Main SwiftUI control plane and settings UI

- [Anywhere](https://github.com/nodepassproject/anywhere/blob/main/Anywhere/AnywhereApp.swift): swiftui app · Main iPhone/iPad control plane entry point · `Anywhere/AnywhereApp.swift`
- [Home UI](https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Views/Home/HomeView.swift): swiftui views · Primary screens for onboarding, home, proxies, and settings · `Anywhere/Views/Home/HomeView.swift`
- [Settings](https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Views/Settings/SettingsView.swift): swiftui settings · Settings, MITM, routing, logs, requests, and import flows · `Anywhere/Views/Settings/SettingsView.swift`
- [Deep links](https://github.com/nodepassproject/anywhere/blob/main/Anywhere/DeepLinkManager.swift): url import · External link handling and import entrypoints · `Anywhere/DeepLinkManager.swift`
- [App store](https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Stores/VoyagerStore.swift): state store · User-facing store coordinating configuration and runtime state · `Anywhere/Stores/VoyagerStore.swift`
- [Voyager UI](https://github.com/nodepassproject/anywhere/blob/main/Anywhere/Views/Voyager/AnywhereVoyagerView.swift): feature flow · Voyager onboarding and feature surface · `Anywhere/Views/Voyager/AnywhereVoyagerView.swift`

### Shared core

Common models, persistence, networking, and utilities

- [Domain models](https://github.com/nodepassproject/anywhere/blob/main/Shared/Models/ProxyChain.swift): core models · Proxy, routing, subscription, tunnel, and latency types · `Shared/Models/ProxyChain.swift`
- [Config store](https://github.com/nodepassproject/anywhere/blob/main/Shared/DataStore/ConfigurationStore.swift): persistence · Certificate, chain, rule, subscription, and blob-backed persistence · `Shared/DataStore/ConfigurationStore.swift`
- [Rule resolver](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/RuleResolver.swift): routing logic · Runtime routing and rule matching boundary · `Shared/Networking/RuleResolver.swift`
- [Proxy core](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/Core/ProxyClient.swift): transport core · Protocol-agnostic proxy client, transports, tunnels, and framing · `Shared/Networking/Protocols/Core/ProxyClient.swift`
- [Protocols](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/VLESS/VLESSProtocol.swift): proxy protocols · Concrete proxy protocols such as VLESS, Hysteria, Trojan, Shadowsocks, AnyTLS, SOCKS5, Naive, Sudoku, and Nowhere · `Shared/Networking/Protocols/VLESS/VLESSProtocol.swift`
- [TLS/QUIC](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/Protocols/QUIC/QUICConnection.swift): crypto transport · Native TLS, QUIC, HPACK/QPACK, and crypto framing implementation · `Shared/Networking/Protocols/QUIC/QUICConnection.swift`
- [Vendored cores](https://github.com/nodepassproject/anywhere/blob/main/Shared/Networking/ngtcp2/ngtcp2_conn.c): native deps · 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](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Network%20Extension/PacketTunnelProvider.swift): network extension · VPN extension entrypoint and lifecycle · `Anywhere Network Extension/PacketTunnelProvider.swift`
- [Tunnel stack](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Network%20Extension/TunnelStack/TunnelStack.swift): flow engine · Flow scheduling, packet handling, and protocol adaptation · `Anywhere Network Extension/TunnelStack/TunnelStack.swift`
- [Routing](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Network%20Extension/DomainRouter.swift): classification · DNS, fake IP, domain routing, and sniffing · `Anywhere Network Extension/DomainRouter.swift`
- [MITM engine](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Network%20Extension/MITM/MITMScriptEngine.swift): http rewrite · HTTP/S interception, logging, rewriting, synthetic responses, and scripts · `Anywhere Network Extension/MITM/MITMScriptEngine.swift`
- [lwIP stack](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Network%20Extension/lwip/lwip_bridge.c): userspace ip 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](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20TV/AppDelegate.swift): tvOS app · Separate tvOS management UI for proxies and configuration · `Anywhere TV/AppDelegate.swift`
- [Widget](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Widget/WidgetBundle.swift): widget surface · Compact VPN and mode toggle controls · `Anywhere Widget/WidgetBundle.swift`

### Tests

Protocol and tunnel validation

- [Tests](https://github.com/nodepassproject/anywhere/blob/HEAD/Anywhere%20Tests/ConfigurationConnectivityTests.swift): protocol tests · Deterministic byte-level and tunneled HTTP/1, HTTP/2, and HTTP/3 validation · `Anywhere Tests/ConfigurationConnectivityTests.swift`

## Connections

- 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
