KageDocs
Development

Architecture

How the user interface, privileged service, and embedded Xray core fit together.

Kage client documentation

One binary, two desktop modes

Kage                  GUI, running as the user
Kage --core-service   Privileged tunnel service

The GUI starts another copy of itself through the platform’s authorisation flow: osascript on macOS, pkexec on Linux, or UAC on Windows. Both sides therefore use the same app version.

React + Wails UI  ←→  Authenticated socket  ←→  Core service
    user                  JSON lines              admin
                                              TUN, DNS, routing
                                              embedded Xray

The privileged service calls core libraries in-process. Logs, connection state, byte counters, and the live connection list return over the same socket. Quitting the GUI shuts the service down; the service also watches the GUI process so that a crash does not leave the service holding the routing table.

Socket authentication

Every service connection must first present a 256-bit per-session token. The GUI writes it to a 0600 file, the elevated process reads and deletes the file, and unauthenticated connections are closed without exposing state.

Passing the token through a file avoids publishing it in a world-readable command line on Linux. Explicit authentication also covers platforms where Unix socket chmod and chown do not enforce the expected access boundary.

Embedded Xray

Kage generates native Xray configuration for tunnel creation, DNS, routing, and outbounds. Xray runs in process. Kage sanitizes supplied Xray configurations, keeping proxy listeners on loopback and stripping API listeners, file-log paths, and embedded routing scripts.

Source map

PathResponsibility
main.goEntry point, GUI/service dispatch, window, and tray.
internal/app/Services exposed to the frontend.
internal/core/Privileged service and IPC client.
internal/xrayconfig/Native Xray configuration and routing compilation.
internal/xrayruntime/In-process Xray runtime.
internal/link/Share-link and configuration parsing.
internal/remote/Subscriptions and optional profile synchronisation.
internal/probe/Latency and connectivity checks.
internal/stats/, internal/speedtest/Stored measurements and speed tests.
internal/plugins/Plugin packaging, validation, serving, and sandbox policy.
internal/cli/Desktop command line and control socket.
internal/storage/, internal/models/Persistence and shared types.
frontend/React app, backend bridge, and translations.
Taskfile.yml, build/Build and packaging tasks.

Mobile tunnel

Android’s VPN service supplies the tunnel descriptor. The Android bridge passes it to Xray and protects outbound sockets from looping back into the VPN. On iOS, the Packet Tunnel Network Extension hosts Xray and supplies the tunnel. See build instructions.

On this page