# 2dust/v2rayn architecture

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

- Interactive diagram: https://gitdiagram.com/2dust/v2rayn
- Repository: https://github.com/2dust/v2rayn

## Overview

v2rayN is a cross-platform desktop proxy client for managing proxy profiles and running Xray/sing-box and other supported cores. Users add or subscribe to server profiles, configure routing and DNS, select a core, then start proxying and inspect connection or speed-test results. The graph preserves those domain stages and the separate WebAPI management surface visible in the tree. Edges are limited to relationships demonstrated by excerpts, the source index, or README; unsampled feature wiring is not inferred.

Main entry points: [`v2rayN/ServiceLib/Manager/CoreManager.cs`](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/CoreManager.cs) (Core process manager), [`v2rayN/ServiceLib/Models/Entities/ProfileItem.cs`](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Models/Entities/ProfileItem.cs) (Server profiles), [`v2rayN/v2rayN.Desktop/App.axaml.cs`](https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.Desktop/App.axaml.cs) (Desktop apps), [`v2rayN/ServiceLib/Manager/AppManager.cs`](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/AppManager.cs) (App state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_desktop_app["Desktop apps<br/>[App.axaml.cs]"]
  node_main_vm["Main window"]
end

subgraph group_profiles["Profiles and configuration"]
  node_app_manager["App state<br/>[AppManager.cs]"]
  node_config["App config<br/>[Config.cs]"]
  node_profiles_vm["Profile management"]
  node_config_handler["Profile config<br/>[ConfigHandler.cs]"]
  node_profile["Server profiles<br/>[ProfileItem.cs]"]
  node_profile_store[("Profile persistence<br/>[AppManager.cs]")]
  node_subscriptions["Subscriptions"]
  node_formats["Share formats<br/>[FmtHandler.cs]"]
  node_routing_dns["Routing and DNS"]
end

subgraph group_runtime["Proxy runtime"]
  node_core_config["Core config generation"]
  node_context_builder["Core context"]
  node_core_manager["Core process manager<br/>[CoreManager.cs]"]
  node_core_process["Proxy core"]
  node_sys_proxy["System proxy<br/>[SysProxyHandler.cs]"]
  node_speedtest["Speed tests"]
  node_downloads["Downloads<br/>[DownloadService.cs]"]
  node_http["HTTP client"]
end

subgraph group_webapi["Web management"]
  node_web_host["Web API host<br/>[Program.cs]"]
  node_web_auth["Web authentication<br/>[WebAuthService.cs]"]
  node_web_endpoints["API endpoints<br/>[WebApiEndpoints.cs]"]
  node_web_runtime["Web runtime<br/>[V2rayRuntime.cs]"]
end

node_user(("User"))
node_web_user(("Web client"))

node_user -->|"launches"| node_desktop_app
node_desktop_app -->|"initializes"| node_app_manager
node_desktop_app -->|"creates"| node_main_vm
node_main_vm -.->|"manages profiles"| node_profiles_vm
node_app_manager -->|"loads config"| node_config_handler
node_app_manager -->|"queries profiles"| node_profile_store
node_profile_store -.->|"stores"| node_profile
node_profiles_vm -.->|"updates profiles"| node_config_handler
node_config_handler -.->|"validates and maps"| node_profile
node_subscriptions -.->|"fetches subscriptions"| node_downloads
node_subscriptions -.->|"parses content"| node_formats
node_formats -->|"produces profiles"| node_profile
node_routing_dns -.->|"contributes settings"| node_core_config
node_core_manager -->|"builds context"| node_context_builder
node_core_manager -->|"requests generation"| node_core_config
node_core_config -.->|"uses context"| node_context_builder
node_core_manager -->|"starts and stops"| node_core_process
node_core_manager -.->|"coordinates proxy"| node_sys_proxy
node_speedtest -->|"runs test core"| node_core_manager
node_speedtest -->|"tests profiles"| node_profile
node_downloads -->|"creates clients"| node_http
node_web_user -.->|"sends requests"| node_web_host
node_web_host -->|"configures authentication"| node_web_auth
node_web_host -->|"hosts endpoints"| node_web_endpoints
node_web_endpoints -.->|"dispatches operations"| node_web_runtime

click node_desktop_app "https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.Desktop/App.axaml.cs"
click node_main_vm "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs"
click node_app_manager "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/AppManager.cs"
click node_config "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Models/Configs/Config.cs"
click node_profiles_vm "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs"
click node_config_handler "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/ConfigHandler.cs"
click node_profile "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Models/Entities/ProfileItem.cs"
click node_profile_store "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/AppManager.cs"
click node_subscriptions "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs"
click node_formats "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs"
click node_routing_dns "https://github.com/2dust/v2rayn/tree/master/v2rayN/ServiceLib/Services/CoreConfig"
click node_core_config "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs"
click node_context_builder "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs"
click node_core_manager "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/CoreManager.cs"
click node_sys_proxy "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs"
click node_speedtest "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Services/SpeedtestService.cs"
click node_downloads "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Services/DownloadService.cs"
click node_http "https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Helper/HttpClientHelper.cs"
click node_web_host "https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Program.cs"
click node_web_auth "https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Security/WebAuthService.cs"
click node_web_endpoints "https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Api/WebApiEndpoints.cs"
click node_web_runtime "https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs"

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_desktop_app,node_main_vm,node_user,node_web_user toneBlue
class node_app_manager,node_config,node_profiles_vm,node_config_handler,node_profile,node_profile_store,node_subscriptions,node_formats,node_routing_dns toneAmber
class node_core_config,node_context_builder,node_core_manager,node_core_process,node_sys_proxy,node_speedtest,node_downloads,node_http toneMint
class node_web_host,node_web_auth,node_web_endpoints,node_web_runtime toneRose
```

## Components

### Desktop experience

- [Desktop apps](https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.Desktop/App.axaml.cs): `v2rayN/v2rayN.Desktop/App.axaml.cs`
- [Main window](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs): `v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs`

### Profiles and configuration

- [App state](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/AppManager.cs): `v2rayN/ServiceLib/Manager/AppManager.cs`
- [App config](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Models/Configs/Config.cs): `v2rayN/ServiceLib/Models/Configs/Config.cs`
- [Profile management](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs): `v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs`
- [Profile config](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/ConfigHandler.cs): `v2rayN/ServiceLib/Handler/ConfigHandler.cs`
- [Server profiles](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Models/Entities/ProfileItem.cs): `v2rayN/ServiceLib/Models/Entities/ProfileItem.cs`
- [Profile persistence](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/AppManager.cs): `v2rayN/ServiceLib/Manager/AppManager.cs`
- [Subscriptions](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs): `v2rayN/ServiceLib/Handler/SubscriptionHandler.cs`
- [Share formats](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs): `v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs`
- [Routing and DNS](https://github.com/2dust/v2rayn/tree/master/v2rayN/ServiceLib/Services/CoreConfig): `v2rayN/ServiceLib/Services/CoreConfig`

### Proxy runtime

- [Core config generation](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs): `v2rayN/ServiceLib/Handler/CoreConfigHandler.cs`
- [Core context](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs): `v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs`
- [Core process manager](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Manager/CoreManager.cs): `v2rayN/ServiceLib/Manager/CoreManager.cs`
- **Proxy core**
- [System proxy](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs): `v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs`
- [Speed tests](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Services/SpeedtestService.cs): `v2rayN/ServiceLib/Services/SpeedtestService.cs`
- [Downloads](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Services/DownloadService.cs): `v2rayN/ServiceLib/Services/DownloadService.cs`
- [HTTP client](https://github.com/2dust/v2rayn/blob/master/v2rayN/ServiceLib/Helper/HttpClientHelper.cs): `v2rayN/ServiceLib/Helper/HttpClientHelper.cs`

### Web management

- [Web API host](https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Program.cs): `v2rayN/v2rayN.WebAPI/Program.cs`
- [Web authentication](https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Security/WebAuthService.cs): `v2rayN/v2rayN.WebAPI/Security/WebAuthService.cs`
- [API endpoints](https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Api/WebApiEndpoints.cs): `v2rayN/v2rayN.WebAPI/Api/WebApiEndpoints.cs`
- [Web runtime](https://github.com/2dust/v2rayn/blob/master/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs): `v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs`

### Other components

- **User**
- **Web client**

## Connections

- User → Desktop apps: launches (evidence: `v2rayN/v2rayN.Desktop/App.axaml.cs`)
- Desktop apps → App state: initializes (evidence: `v2rayN/v2rayN.Desktop/App.axaml.cs`)
- Desktop apps → Main window: creates (evidence: `v2rayN/v2rayN.Desktop/App.axaml.cs`)
- Main window → Profile management: manages profiles
- App state → Profile config: loads config (evidence: `v2rayN/ServiceLib/Manager/AppManager.cs`)
- App state → Profile persistence: queries profiles (evidence: `v2rayN/ServiceLib/Manager/AppManager.cs`)
- Profile persistence → Server profiles: stores (evidence: `v2rayN/ServiceLib/Manager/AppManager.cs`)
- Profile management → Profile config: updates profiles
- Profile config → Server profiles: validates and maps (evidence: `v2rayN/ServiceLib/Handler/ConfigHandler.cs`)
- Subscriptions → Downloads: fetches subscriptions
- Subscriptions → Share formats: parses content
- Share formats → Server profiles: produces profiles (evidence: `v2rayN/ServiceLib.Tests/Fmt/ShareUriQueryTests.cs`)
- Routing and DNS → Core config generation: contributes settings
- Core process manager → Core context: builds context (evidence: `v2rayN/ServiceLib/Manager/CoreManager.cs`)
- Core process manager → Core config generation: requests generation (evidence: `v2rayN/ServiceLib/Manager/CoreManager.cs`)
- Core config generation → Core context: uses context
- Core process manager → Proxy core: starts and stops (evidence: `v2rayN/ServiceLib/Manager/CoreManager.cs`)
- Core process manager → System proxy: coordinates proxy
- Speed tests → Core process manager: runs test core (evidence: `v2rayN/ServiceLib/Services/SpeedtestService.cs`)
- Speed tests → Server profiles: tests profiles (evidence: `v2rayN/ServiceLib/Services/SpeedtestService.cs`)
- Downloads → HTTP client: creates clients (evidence: `v2rayN/ServiceLib/Services/DownloadService.cs`)
- Web client → Web API host: sends requests
- Web API host → Web authentication: configures authentication (evidence: `v2rayN/v2rayN.WebAPI/Program.cs`)
- Web API host → API endpoints: hosts endpoints (evidence: `v2rayN/v2rayN.WebAPI/Program.cs`)
- API endpoints → Web runtime: dispatches operations
