Architecture
This section describes xratβs internal architecture, data flow, and module structure for developers and contributors.
Context Diagram
graph TB
classDef user fill:#3a2c1a,stroke:#dfa85b,color:#e6edf3
classDef iface fill:#1a2e1a,stroke:#5bdf8a,color:#e6edf3
classDef core fill:#1a2c3a,stroke:#5b8def,color:#e6edf3
classDef engine fill:#1a3a1a,stroke:#5bdf5b,color:#e6edf3
classDef store fill:#1a3a3a,stroke:#5bdfd3,color:#e6edf3
User(("User")):::user
subgraph interfaces["User Interfaces"]
CLI["CLI (terminal)"]:::iface
TUI["TUI (ratatui)"]:::iface
API["HTTP API (axum)"]:::iface
end
subgraph xrat_core["xrat Core"]
Daemon["Daemon Supervisor"]:::core
end
subgraph engines["Proxy Engines"]
Xray["Xray-core"]:::engine
SingBox["sing-box"]:::engine
end
DB[("SQLite / Postgres")]:::store
User --> CLI
User --> TUI
User -- "HTTP" --> API
CLI -- "IPC" --> Daemon
TUI -- "IPC" --> Daemon
Daemon -- "spawns" --> Xray
Daemon -- "spawns" --> SingBox
CLI --> DB
Daemon --> DB
API --> DB
Pages
| Page | Description |
|---|---|
| Module Structure | Source tree, module responsibilities, dependency graph |
| Config Generation | How engine JSON configs are generated from nodes |
| Import Pipeline | End-to-end subscription import flow |
| Daemon Architecture | Daemon process, IPC protocol, supervisor event loop |
| Runtime Lifecycle | Session state machine, connect/replace/disconnect flows |
| Test Pipeline | Probe execution, test stages, output formatting |
| Database Schema | Full SQL DDL and per-table column reference |