# v2fly/v2ray-core architecture

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

- Interactive diagram: https://gitdiagram.com/v2fly/v2ray-core
- Repository: https://github.com/v2fly/v2ray-core

## Overview

Project V (V2Ray Core) is a configurable network proxy platform for building private, secured connections. The main runtime path accepts inbound traffic, processes a proxy protocol, dispatches destination traffic through routing, and sends it through an outbound handler and transport. The repository also contains DNS, policy, statistics, subscription management, management APIs, TUN support, and optional networking capabilities. Several edges below are grounded in sampled source or the source index; links for unsampled subsystems are omitted rather than inferred.

Main entry points: [`features/routing/dispatcher.go`](https://github.com/v2fly/v2ray-core/blob/master/features/routing/dispatcher.go) (Traffic dispatcher), [`proxy`](https://github.com/v2fly/v2ray-core/tree/master/proxy) (Inbound protocols), [`app/proxyman/inbound/worker.go`](https://github.com/v2fly/v2ray-core/blob/master/app/proxyman/inbound/worker.go) (Inbound workers), [`app/router/router.go`](https://github.com/v2fly/v2ray-core/blob/master/app/router/router.go) (Routing rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Traffic runtime"]
  node_inbound["Inbound workers<br/>[worker.go]"]
  node_protocols["Inbound protocols"]
  node_routing["Routing rules<br/>[router.go]"]
  node_dispatcher["Traffic dispatcher<br/>[dispatcher.go]"]
  node_outbound["Outbound handlers<br/>[handler.go]"]
  node_transport["Transport connections<br/>[internet.go]"]
end

subgraph group_network["Network services"]
  node_dns["DNS services<br/>[dns.go]"]
  node_policy["Session policy<br/>[manager.go]"]
  node_stats["Traffic statistics<br/>[stats.go]"]
  node_tun["TUN networking<br/>[tun.go]"]
  node_reverse["Reverse proxy<br/>[reverse.go]"]
end

subgraph group_management["Management"]
  node_subscription["Subscriptions<br/>[manager.go]"]
  node_storage[("Persistent storage<br/>[storage.go]")]
  node_api["REST management<br/>[service.go]"]
  node_commands["Runtime commands<br/>[service.go]"]
end

subgraph group_extensions["Optional capabilities"]
  node_observatory["Connectivity observatory<br/>[observatory.go]"]
  node_webrtc["WebRTC transport<br/>[webrtc.go]"]
  node_browser["Browser forwarding<br/>[forwarder.go]"]
end

node_client(("Network client"))
node_destination(("Destination service"))

node_client -->|"connects"| node_inbound
node_inbound -->|"invokes handlers"| node_protocols
node_protocols -->|"dispatches traffic"| node_dispatcher
node_protocols -->|"dispatches UDP"| node_dispatcher
node_routing -->|"implements routing"| node_dispatcher
node_dispatcher -.->|"selects outbound"| node_outbound
node_outbound -->|"uses transport"| node_transport
node_transport -->|"connects to"| node_destination
node_protocols -->|"gets session policy"| node_policy
node_inbound -->|"uses dispatcher"| node_routing
node_routing -->|"uses DNS"| node_dns
node_tun -->|"dispatches traffic"| node_dispatcher
node_subscription -->|"persists imports"| node_storage
node_api -->|"exposes statistics"| node_stats
node_commands -.->|"registers commands"| node_api

click node_inbound "https://github.com/v2fly/v2ray-core/blob/master/app/proxyman/inbound/worker.go"
click node_protocols "https://github.com/v2fly/v2ray-core/tree/master/proxy"
click node_routing "https://github.com/v2fly/v2ray-core/blob/master/app/router/router.go"
click node_dispatcher "https://github.com/v2fly/v2ray-core/blob/master/features/routing/dispatcher.go"
click node_outbound "https://github.com/v2fly/v2ray-core/blob/master/app/proxyman/outbound/handler.go"
click node_transport "https://github.com/v2fly/v2ray-core/blob/master/transport/internet/internet.go"
click node_dns "https://github.com/v2fly/v2ray-core/blob/master/app/dns/dns.go"
click node_policy "https://github.com/v2fly/v2ray-core/blob/master/app/policy/manager.go"
click node_stats "https://github.com/v2fly/v2ray-core/blob/master/app/stats/stats.go"
click node_tun "https://github.com/v2fly/v2ray-core/blob/master/app/tun/tun.go"
click node_reverse "https://github.com/v2fly/v2ray-core/blob/master/app/reverse/reverse.go"
click node_subscription "https://github.com/v2fly/v2ray-core/blob/master/app/subscription/subscriptionmanager/manager.go"
click node_storage "https://github.com/v2fly/v2ray-core/blob/master/app/persistentstorage/storage.go"
click node_api "https://github.com/v2fly/v2ray-core/blob/master/app/restfulapi/service.go"
click node_commands "https://github.com/v2fly/v2ray-core/blob/master/app/commander/service.go"
click node_observatory "https://github.com/v2fly/v2ray-core/blob/master/app/observatory/observatory.go"
click node_webrtc "https://github.com/v2fly/v2ray-core/blob/master/app/webrtc/webrtc.go"
click node_browser "https://github.com/v2fly/v2ray-core/blob/master/app/browserforwarder/forwarder.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_inbound,node_protocols,node_routing,node_dispatcher,node_outbound,node_transport,node_client toneBlue
class node_dns,node_policy,node_stats,node_tun,node_reverse toneAmber
class node_subscription,node_storage,node_api,node_commands toneMint
class node_observatory,node_webrtc,node_browser toneRose
class node_destination toneIndigo
```

## Components

### Traffic runtime

- [Inbound workers](https://github.com/v2fly/v2ray-core/blob/master/app/proxyman/inbound/worker.go): `app/proxyman/inbound/worker.go`
- [Inbound protocols](https://github.com/v2fly/v2ray-core/tree/master/proxy): `proxy`
- [Routing rules](https://github.com/v2fly/v2ray-core/blob/master/app/router/router.go): `app/router/router.go`
- [Traffic dispatcher](https://github.com/v2fly/v2ray-core/blob/master/features/routing/dispatcher.go): `features/routing/dispatcher.go`
- [Outbound handlers](https://github.com/v2fly/v2ray-core/blob/master/app/proxyman/outbound/handler.go): `app/proxyman/outbound/handler.go`
- [Transport connections](https://github.com/v2fly/v2ray-core/blob/master/transport/internet/internet.go): `transport/internet/internet.go`

### Network services

- [DNS services](https://github.com/v2fly/v2ray-core/blob/master/app/dns/dns.go): `app/dns/dns.go`
- [Session policy](https://github.com/v2fly/v2ray-core/blob/master/app/policy/manager.go): `app/policy/manager.go`
- [Traffic statistics](https://github.com/v2fly/v2ray-core/blob/master/app/stats/stats.go): `app/stats/stats.go`
- [TUN networking](https://github.com/v2fly/v2ray-core/blob/master/app/tun/tun.go): `app/tun/tun.go`
- [Reverse proxy](https://github.com/v2fly/v2ray-core/blob/master/app/reverse/reverse.go): `app/reverse/reverse.go`

### Management

- [Subscriptions](https://github.com/v2fly/v2ray-core/blob/master/app/subscription/subscriptionmanager/manager.go): `app/subscription/subscriptionmanager/manager.go`
- [Persistent storage](https://github.com/v2fly/v2ray-core/blob/master/app/persistentstorage/storage.go): `app/persistentstorage/storage.go`
- [REST management](https://github.com/v2fly/v2ray-core/blob/master/app/restfulapi/service.go): `app/restfulapi/service.go`
- [Runtime commands](https://github.com/v2fly/v2ray-core/blob/master/app/commander/service.go): `app/commander/service.go`

### Optional capabilities

- [Connectivity observatory](https://github.com/v2fly/v2ray-core/blob/master/app/observatory/observatory.go): `app/observatory/observatory.go`
- [WebRTC transport](https://github.com/v2fly/v2ray-core/blob/master/app/webrtc/webrtc.go): `app/webrtc/webrtc.go`
- [Browser forwarding](https://github.com/v2fly/v2ray-core/blob/master/app/browserforwarder/forwarder.go): `app/browserforwarder/forwarder.go`

### Other components

- **Network client**
- **Destination service**

## Connections

- Network client → Inbound workers: connects
- Inbound workers → Inbound protocols: invokes handlers (evidence: `app/proxyman/inbound/worker.go`)
- Inbound protocols → Traffic dispatcher: dispatches traffic (evidence: `proxy/http/server.go`)
- Inbound protocols → Traffic dispatcher: dispatches UDP (evidence: `proxy/socks/server.go`)
- Routing rules → Traffic dispatcher: implements routing (evidence: `app/router/router.go`)
- Traffic dispatcher → Outbound handlers: selects outbound
- Outbound handlers → Transport connections: uses transport (evidence: `app/proxyman/outbound/handler.go`)
- Transport connections → Destination service: connects to
- Inbound protocols → Session policy: gets session policy (evidence: `proxy/http/server.go`)
- Inbound workers → Routing rules: uses dispatcher (evidence: `app/proxyman/inbound/worker.go`)
- Routing rules → DNS services: uses DNS (evidence: `app/router/router.go`)
- TUN networking → Traffic dispatcher: dispatches traffic
- Subscriptions → Persistent storage: persists imports (evidence: `app/subscription/subscriptionmanager/manager.go`)
- REST management → Traffic statistics: exposes statistics (evidence: `app/restfulapi/service.go`)
- Runtime commands → REST management: registers commands
