# v2ray/v2ray-core architecture

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

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

## Overview

Project V is a configurable network proxy platform for securing connections and protecting privacy. The runtime starts from a server configuration, accepts TCP/UDP traffic through inbound handlers, and routes requests to destinations; proxy protocols, outbound handlers, and transports provide the connection mechanisms. DNS resolution, routing policy, multiplexing, and management/configuration are separate supporting capabilities. The excerpts show key dispatch relationships, but many subsystems are represented by their directory because their implementations were not sampled.

Main entry points: [`app/router/router.go`](https://github.com/v2ray/v2ray-core/blob/master/app/router/router.go) (Router), [`app/proxyman/outbound/handler.go`](https://github.com/v2ray/v2ray-core/blob/master/app/proxyman/outbound/handler.go) (Outbound handlers), [`app/proxyman/inbound/worker.go`](https://github.com/v2ray/v2ray-core/blob/master/app/proxyman/inbound/worker.go) (Inbound workers), [`proxy`](https://github.com/v2ray/v2ray-core/tree/master/proxy) (Other proxy protocols)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and configuration"]
  node_launcher["Runtime launcher<br/>[main.go]"]
  node_config["Config conversion"]
  node_core["Core server<br/>[core.go]"]
end

subgraph group_traffic["Traffic handling"]
  node_inbound["Inbound workers<br/>[worker.go]"]
  node_outbound["Outbound handlers<br/>[handler.go]"]
  node_policy["Session policy<br/>[manager.go]"]
  node_stats["Traffic statistics"]
  node_reverse["Reverse proxy"]
end

subgraph group_routing["Routing and DNS"]
  node_router["Router<br/>[router.go]"]
  node_dns["DNS service<br/>[server.go]"]
end

subgraph group_protocols["Proxy protocols"]
  node_http["HTTP proxy<br/>[server.go]"]
  node_socks["SOCKS proxy<br/>[server.go]"]
  node_trojan["Trojan proxy<br/>[server.go]"]
  node_protocols["Other proxy protocols"]
end

subgraph group_network["Transport and services"]
  node_mux["Multiplexing"]
  node_transport["Network transports"]
end

node_operator(("Operator"))
node_external(("Network clients"))

node_operator -->|"starts"| node_launcher
node_launcher -->|"creates"| node_core
node_config -->|"builds routing config"| node_router
node_external -.->|"sends traffic"| node_inbound
node_inbound -->|"selects handler"| node_protocols
node_inbound -->|"uses connections"| node_transport
node_http -->|"dispatches requests"| node_router
node_socks -->|"dispatches requests"| node_router
node_trojan -->|"dispatches requests"| node_router
node_protocols -.->|"uses outbound"| node_outbound
node_outbound -->|"dials destinations"| node_transport
node_outbound -->|"dispatches sessions"| node_mux
node_router -.->|"resolves domains"| node_dns
node_dns -->|"requests dispatcher"| node_router
node_protocols -.->|"reads session limits"| node_policy
node_outbound -->|"updates counters"| node_stats

click node_launcher "https://github.com/v2ray/v2ray-core/blob/master/main/main.go"
click node_config "https://github.com/v2ray/v2ray-core/tree/master/infra/conf"
click node_core "https://github.com/v2ray/v2ray-core/blob/master/core.go"
click node_inbound "https://github.com/v2ray/v2ray-core/blob/master/app/proxyman/inbound/worker.go"
click node_outbound "https://github.com/v2ray/v2ray-core/blob/master/app/proxyman/outbound/handler.go"
click node_router "https://github.com/v2ray/v2ray-core/blob/master/app/router/router.go"
click node_dns "https://github.com/v2ray/v2ray-core/blob/master/app/dns/server.go"
click node_http "https://github.com/v2ray/v2ray-core/blob/master/proxy/http/server.go"
click node_socks "https://github.com/v2ray/v2ray-core/blob/master/proxy/socks/server.go"
click node_trojan "https://github.com/v2ray/v2ray-core/blob/master/proxy/trojan/server.go"
click node_protocols "https://github.com/v2ray/v2ray-core/tree/master/proxy"
click node_mux "https://github.com/v2ray/v2ray-core/tree/master/common/mux"
click node_transport "https://github.com/v2ray/v2ray-core/tree/master/transport/internet"
click node_policy "https://github.com/v2ray/v2ray-core/blob/master/app/policy/manager.go"
click node_stats "https://github.com/v2ray/v2ray-core/tree/master/app/stats"
click node_reverse "https://github.com/v2ray/v2ray-core/tree/master/app/reverse"

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_launcher,node_config,node_core,node_external toneBlue
class node_inbound,node_outbound,node_policy,node_stats,node_reverse toneAmber
class node_router,node_dns toneMint
class node_http,node_socks,node_trojan,node_protocols toneRose
class node_mux,node_transport,node_operator toneIndigo
```

## Components

### Runtime and configuration

- [Runtime launcher](https://github.com/v2ray/v2ray-core/blob/master/main/main.go): `main/main.go`
- [Config conversion](https://github.com/v2ray/v2ray-core/tree/master/infra/conf): `infra/conf`
- [Core server](https://github.com/v2ray/v2ray-core/blob/master/core.go): `core.go`

### Traffic handling

- [Inbound workers](https://github.com/v2ray/v2ray-core/blob/master/app/proxyman/inbound/worker.go): `app/proxyman/inbound/worker.go`
- [Outbound handlers](https://github.com/v2ray/v2ray-core/blob/master/app/proxyman/outbound/handler.go): `app/proxyman/outbound/handler.go`
- [Session policy](https://github.com/v2ray/v2ray-core/blob/master/app/policy/manager.go): `app/policy/manager.go`
- [Traffic statistics](https://github.com/v2ray/v2ray-core/tree/master/app/stats): `app/stats`
- [Reverse proxy](https://github.com/v2ray/v2ray-core/tree/master/app/reverse): `app/reverse`

### Routing and DNS

- [Router](https://github.com/v2ray/v2ray-core/blob/master/app/router/router.go): `app/router/router.go`
- [DNS service](https://github.com/v2ray/v2ray-core/blob/master/app/dns/server.go): `app/dns/server.go`

### Proxy protocols

- [HTTP proxy](https://github.com/v2ray/v2ray-core/blob/master/proxy/http/server.go): `proxy/http/server.go`
- [SOCKS proxy](https://github.com/v2ray/v2ray-core/blob/master/proxy/socks/server.go): `proxy/socks/server.go`
- [Trojan proxy](https://github.com/v2ray/v2ray-core/blob/master/proxy/trojan/server.go): `proxy/trojan/server.go`
- [Other proxy protocols](https://github.com/v2ray/v2ray-core/tree/master/proxy): `proxy`

### Transport and services

- [Multiplexing](https://github.com/v2ray/v2ray-core/tree/master/common/mux): `common/mux`
- [Network transports](https://github.com/v2ray/v2ray-core/tree/master/transport/internet): `transport/internet`

### Other components

- **Operator**
- **Network clients**

## Connections

- Operator → Runtime launcher: starts (evidence: `main/main.go`)
- Runtime launcher → Core server: creates (evidence: `main/main.go`)
- Config conversion → Router: builds routing config (evidence: `infra/conf/router.go`)
- Network clients → Inbound workers: sends traffic
- Inbound workers → Other proxy protocols: selects handler (evidence: `app/proxyman/inbound/worker.go`)
- Inbound workers → Network transports: uses connections (evidence: `app/proxyman/inbound/worker.go`)
- HTTP proxy → Router: dispatches requests (evidence: `proxy/http/server.go`)
- SOCKS proxy → Router: dispatches requests (evidence: `proxy/socks/server.go`)
- Trojan proxy → Router: dispatches requests (evidence: `proxy/trojan/server.go`)
- Other proxy protocols → Outbound handlers: uses outbound (evidence: `app/proxyman/outbound/handler.go`)
- Outbound handlers → Network transports: dials destinations (evidence: `app/proxyman/outbound/handler.go`)
- Outbound handlers → Multiplexing: dispatches sessions (evidence: `app/proxyman/outbound/handler.go`)
- Router → DNS service: resolves domains
- DNS service → Router: requests dispatcher (evidence: `app/dns/server.go`)
- Other proxy protocols → Session policy: reads session limits
- Outbound handlers → Traffic statistics: updates counters (evidence: `app/proxyman/outbound/handler.go`)
