# kykiles/xray-runner architecture

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

- Interactive diagram: https://gitdiagram.com/kykiles/xray-runner
- Repository: https://github.com/kykiles/xray-runner

## Overview

xray-runner is a Linux/Windows VPN client for importing provider links or subscriptions, choosing a profile/server, and running Xray-core through either the system proxy or a TUN interface. Its main workflow spans subscription retrieval and parsing, server selection, config construction, core execution and network setup, then status monitoring and cleanup. Separate branches cover privileged service operation, split routing, updates, and saved config display. README documents the product workflow; some internal calls are not visible in the excerpts, so uncertain connections are omitted or dashed.

Main entry points: [`internal/app/session.go`](https://github.com/kykiles/xray-runner/blob/main/internal/app/session.go) (Session lifecycle), [`internal/app/app.go`](https://github.com/kykiles/xray-runner/blob/main/internal/app/app.go) (App orchestration), [`internal/subscription/fetch.go`](https://github.com/kykiles/xray-runner/blob/main/internal/subscription/fetch.go) (Subscription fetch), [`internal/tui/list_screen.go`](https://github.com/kykiles/xray-runner/blob/main/internal/tui/list_screen.go) (Terminal UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client workflow"]
  node_cli["CLI entry<br/>[main.go]"]
  node_app["App orchestration<br/>[app.go]"]
  node_tui["Terminal UI<br/>[list_screen.go]"]
end

subgraph group_config["Profiles and config"]
  node_subscription["Subscription fetch<br/>[fetch.go]"]
  node_parser["Link and profile parsing<br/>[parse.go]"]
  node_store[("Subscription storage<br/>[store.go]")]
  node_builder["Xray config builder<br/>[builder.go]"]
  node_clientparts["Profile config validation<br/>[clientparts.go]"]
end

subgraph group_runtime["VPN runtime"]
  node_session["Session lifecycle<br/>[session.go]"]
  node_core["Xray process runner<br/>[runner.go]"]
  node_network["Proxy and TUN control<br/>[proxy.go]"]
  node_routes["Route management<br/>[route_linux.go]"]
  node_split["Process split routing<br/>[split_linux.go]"]
  node_firewall["Kill switch<br/>[nft_linux.go]"]
  node_health["Connection health<br/>[health.go]"]
end

subgraph group_privileged["Privileged service"]
  node_service["Privileged service<br/>[service.go]"]
  node_ipc["Service IPC<br/>[client.go]"]
  node_geo[("Geo database service<br/>[geostore.go]")]
end

subgraph group_support["Supporting features"]
  node_updater["Core and geo updater<br/>[updater.go]"]
  node_configview["Config preview and save<br/>[session.go]"]
end

node_user(("VPN user"))
node_xray["Xray-core"]
node_provider(("VPN provider"))
node_os["Operating system"]

node_user -->|"starts"| node_cli
node_cli -.->|"starts client"| node_app
node_user -->|"chooses subscription"| node_tui
node_tui -.->|"selects server"| node_app
node_app -.->|"refreshes"| node_subscription
node_subscription -->|"fetches links"| node_provider
node_subscription -.->|"parses response"| node_parser
node_app -.->|"saves subscriptions"| node_store
node_app -.->|"builds session config"| node_builder
node_builder -.->|"validates profile parts"| node_clientparts
node_session -.->|"starts and restarts"| node_core
node_core -->|"runs"| node_xray
node_session -.->|"sets connection mode"| node_network
node_session -->|"sets TUN routes"| node_routes
node_session -->|"enables kill switch"| node_firewall
node_session -->|"configures process routing"| node_split
node_session -->|"checks connection"| node_health
node_session -->|"shows status"| node_tui
node_session -->|"previews and saves"| node_configview
node_network -->|"changes proxy settings"| node_os
node_routes -->|"changes routes"| node_os
node_firewall -->|"installs firewall rules"| node_os
node_app -.->|"uses service client"| node_ipc
node_ipc -->|"sends requests"| node_service
node_service -.->|"uses geo store"| node_geo
node_user -->|"requests update"| node_updater
node_updater -->|"installs core"| node_xray

click node_cli "https://github.com/kykiles/xray-runner/blob/main/cmd/xray-runner/main.go"
click node_app "https://github.com/kykiles/xray-runner/blob/main/internal/app/app.go"
click node_tui "https://github.com/kykiles/xray-runner/blob/main/internal/tui/list_screen.go"
click node_session "https://github.com/kykiles/xray-runner/blob/main/internal/app/session.go"
click node_subscription "https://github.com/kykiles/xray-runner/blob/main/internal/subscription/fetch.go"
click node_parser "https://github.com/kykiles/xray-runner/blob/main/internal/subscription/parse.go"
click node_store "https://github.com/kykiles/xray-runner/blob/main/internal/subscription/store.go"
click node_builder "https://github.com/kykiles/xray-runner/blob/main/internal/xraycfg/builder.go"
click node_clientparts "https://github.com/kykiles/xray-runner/blob/main/internal/xraycfg/clientparts.go"
click node_core "https://github.com/kykiles/xray-runner/blob/main/internal/xray/runner.go"
click node_network "https://github.com/kykiles/xray-runner/blob/main/internal/system/proxy.go"
click node_routes "https://github.com/kykiles/xray-runner/blob/main/internal/system/route_linux.go"
click node_split "https://github.com/kykiles/xray-runner/blob/main/internal/system/split_linux.go"
click node_firewall "https://github.com/kykiles/xray-runner/blob/main/internal/system/nft_linux.go"
click node_health "https://github.com/kykiles/xray-runner/blob/main/internal/app/health.go"
click node_service "https://github.com/kykiles/xray-runner/blob/main/internal/service/service.go"
click node_ipc "https://github.com/kykiles/xray-runner/blob/main/internal/ipc/client.go"
click node_geo "https://github.com/kykiles/xray-runner/blob/main/internal/service/geostore.go"
click node_updater "https://github.com/kykiles/xray-runner/blob/main/internal/updater/updater.go"
click node_configview "https://github.com/kykiles/xray-runner/blob/main/internal/app/session.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_cli,node_app,node_tui,node_user toneBlue
class node_subscription,node_parser,node_store,node_builder,node_clientparts toneAmber
class node_session,node_core,node_network,node_routes,node_split,node_firewall,node_health toneMint
class node_service,node_ipc,node_geo toneRose
class node_updater,node_configview,node_xray,node_provider,node_os toneIndigo
```

## Components

### Client workflow

- [CLI entry](https://github.com/kykiles/xray-runner/blob/main/cmd/xray-runner/main.go): `cmd/xray-runner/main.go`
- [App orchestration](https://github.com/kykiles/xray-runner/blob/main/internal/app/app.go): `internal/app/app.go`
- [Terminal UI](https://github.com/kykiles/xray-runner/blob/main/internal/tui/list_screen.go): `internal/tui/list_screen.go`

### Profiles and config

- [Subscription fetch](https://github.com/kykiles/xray-runner/blob/main/internal/subscription/fetch.go): `internal/subscription/fetch.go`
- [Link and profile parsing](https://github.com/kykiles/xray-runner/blob/main/internal/subscription/parse.go): `internal/subscription/parse.go`
- [Subscription storage](https://github.com/kykiles/xray-runner/blob/main/internal/subscription/store.go): `internal/subscription/store.go`
- [Xray config builder](https://github.com/kykiles/xray-runner/blob/main/internal/xraycfg/builder.go): `internal/xraycfg/builder.go`
- [Profile config validation](https://github.com/kykiles/xray-runner/blob/main/internal/xraycfg/clientparts.go): `internal/xraycfg/clientparts.go`

### VPN runtime

- [Session lifecycle](https://github.com/kykiles/xray-runner/blob/main/internal/app/session.go): `internal/app/session.go`
- [Xray process runner](https://github.com/kykiles/xray-runner/blob/main/internal/xray/runner.go): `internal/xray/runner.go`
- [Proxy and TUN control](https://github.com/kykiles/xray-runner/blob/main/internal/system/proxy.go): `internal/system/proxy.go`
- [Route management](https://github.com/kykiles/xray-runner/blob/main/internal/system/route_linux.go): `internal/system/route_linux.go`
- [Process split routing](https://github.com/kykiles/xray-runner/blob/main/internal/system/split_linux.go): `internal/system/split_linux.go`
- [Kill switch](https://github.com/kykiles/xray-runner/blob/main/internal/system/nft_linux.go): `internal/system/nft_linux.go`
- [Connection health](https://github.com/kykiles/xray-runner/blob/main/internal/app/health.go): `internal/app/health.go`

### Privileged service

- [Privileged service](https://github.com/kykiles/xray-runner/blob/main/internal/service/service.go): `internal/service/service.go`
- [Service IPC](https://github.com/kykiles/xray-runner/blob/main/internal/ipc/client.go): `internal/ipc/client.go`
- [Geo database service](https://github.com/kykiles/xray-runner/blob/main/internal/service/geostore.go): `internal/service/geostore.go`

### Supporting features

- [Core and geo updater](https://github.com/kykiles/xray-runner/blob/main/internal/updater/updater.go): `internal/updater/updater.go`
- [Config preview and save](https://github.com/kykiles/xray-runner/blob/main/internal/app/session.go): `internal/app/session.go`

### Other components

- **VPN user**
- **Xray-core**
- **VPN provider**
- **Operating system**

## Connections

- VPN user → CLI entry: starts (evidence: `README.md`)
- CLI entry → App orchestration: starts client
- VPN user → Terminal UI: chooses subscription (evidence: `README.md`)
- Terminal UI → App orchestration: selects server
- App orchestration → Subscription fetch: refreshes
- Subscription fetch → VPN provider: fetches links (evidence: `README.md`)
- Subscription fetch → Link and profile parsing: parses response
- App orchestration → Subscription storage: saves subscriptions
- App orchestration → Xray config builder: builds session config
- Xray config builder → Profile config validation: validates profile parts
- Session lifecycle → Xray process runner: starts and restarts
- Xray process runner → Xray-core: runs (evidence: `README.md`)
- Session lifecycle → Proxy and TUN control: sets connection mode
- Session lifecycle → Route management: sets TUN routes (evidence: `README.md`)
- Session lifecycle → Kill switch: enables kill switch (evidence: `README.md`)
- Session lifecycle → Process split routing: configures process routing (evidence: `README.md`)
- Session lifecycle → Connection health: checks connection (evidence: `README.md`)
- Session lifecycle → Terminal UI: shows status (evidence: `README.md`)
- Session lifecycle → Config preview and save: previews and saves (evidence: `README.md`)
- Proxy and TUN control → Operating system: changes proxy settings (evidence: `README.md`)
- Route management → Operating system: changes routes (evidence: `README.md`)
- Kill switch → Operating system: installs firewall rules (evidence: `README.md`)
- App orchestration → Service IPC: uses service client
- Service IPC → Privileged service: sends requests (evidence: `internal/service/service.go`)
- Privileged service → Geo database service: uses geo store
- VPN user → Core and geo updater: requests update (evidence: `README.md`)
- Core and geo updater → Xray-core: installs core (evidence: `internal/updater/updater.go`)
