Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

PageDescription
Module StructureSource tree, module responsibilities, dependency graph
Config GenerationHow engine JSON configs are generated from nodes
Import PipelineEnd-to-end subscription import flow
Daemon ArchitectureDaemon process, IPC protocol, supervisor event loop
Runtime LifecycleSession state machine, connect/replace/disconnect flows
Test PipelineProbe execution, test stages, output formatting
Database SchemaFull SQL DDL and per-table column reference