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

Module Structure

xrat follows a modular architecture with clear separation of concerns across CLI parsing, command handlers, config parsing, database access, and engine integration.

Component Diagram

Arrows show dependency direction (A โ†’ B means A depends on B).

graph TB
    classDef entry  fill:#1a2744,stroke:#4a9eff,color:#e6edf3
    classDef iface  fill:#1a3a2a,stroke:#5bdf8a,color:#e6edf3
    classDef app    fill:#2a1a3a,stroke:#b070df,color:#e6edf3
    classDef domain fill:#2e2a1a,stroke:#dfba5b,color:#e6edf3
    classDef store  fill:#1a2e2e,stroke:#5bcfdf,color:#e6edf3
    classDef engine fill:#2e1a1a,stroke:#df6060,color:#e6edf3
    classDef probe  fill:#2a2a1a,stroke:#c0df5b,color:#e6edf3

    main["main.rs"]:::entry

    subgraph ui["User Interfaces"]
        cli["cli/"]:::iface
        server["server/"]:::iface
        tui["tui/"]:::iface
    end

    subgraph app_layer["Application Layer"]
        cmds["commands/"]:::app
        daemon["daemon/"]:::app
        rtsvc["runtime_service/"]:::app
    end

    subgraph domain_layer["Domain & Config"]
        model["model/"]:::domain
        config["config/"]:::domain
        support["support/"]:::domain
    end

    db["db/"]:::store

    subgraph engine_layer["Proxy Engines"]
        xray["xray/"]:::engine
        singbox["singbox/"]:::engine
    end

    prober["prober/"]:::probe

    main --> cli
    main --> cmds

    cmds --> rtsvc
    cmds --> daemon
    daemon --> rtsvc
    rtsvc --> xray

    config --> model
    support --> config
    support --> db

    db --> xray
    db --> prober

    prober --> xray
    prober --> model

    server --> db
    server --> model

    tui --> cmds
    tui --> db

Module Responsibilities

ModuleResponsibility
cli/Define CLI interface with Clap. Parse args and flags. Test parsing.
app/Orchestrate command execution. Manage app lifecycle (context, config, daemon).
model/Shared domain types (Node, Protocol, NodeDedupKey). No dependencies on other modules.
config/Parse proxy URIs. Normalize nodes. Detect import formats.
db/Database connection, migrations, queries, repositories.
xray/Generate Xray JSON configs. Parse Xray JSON. Manage Xray processes.
singbox/Generate sing-box JSON configs. Manage sing-box processes.
prober/Connection testing probes: ICMP, TCP, HTTP real-delay, download, upload.
server/HTTP API server using Axum. Auth, routes, response types.
support/Shared utilities: base64 decode, GeoIP, network helpers.

Data Flows

Import Flow

flowchart LR
    classDef io   fill:#1a2e1a,stroke:#5bdf8a,color:#e6edf3
    classDef cfg  fill:#2e2a1a,stroke:#dfba5b,color:#e6edf3
    classDef db   fill:#1a2e2e,stroke:#5bcfdf,color:#e6edf3

    SRC["Input\n(URL / File / Stdin)"]:::io
    APP_IN["app/input/"]:::io
    DETECT["config/import/detect"]:::cfg
    PARSE_FMT["config/import/parsers/"]:::cfg
    PROTO["config/protocols/"]:::cfg
    NORM["config/normalize/"]:::cfg
    DEDUP["model/node_dedup_key/"]:::cfg
    PERSIST["db/repository/configs/"]:::db
    SUB["db/repository/subscriptions/"]:::db

    SRC --> APP_IN --> DETECT --> PARSE_FMT --> PROTO --> NORM --> DEDUP --> PERSIST --> SUB

Test Flow

flowchart TD
    classDef cli    fill:#1a2744,stroke:#4a9eff,color:#e6edf3
    classDef app    fill:#2a1a3a,stroke:#b070df,color:#e6edf3
    classDef engine fill:#2e1a1a,stroke:#df6060,color:#e6edf3
    classDef probe  fill:#2a2a1a,stroke:#c0df5b,color:#e6edf3
    classDef store  fill:#1a2e2e,stroke:#5bcfdf,color:#e6edf3

    CLI["CLI args"]:::cli
    SET["resolve settings\napp/commands/test/"]:::app
    LOAD["load configs\ndb/repository/configs/"]:::store
    LOOP{"For each config"}
    GEN["generate probe config\nxray/config/generator/"]:::engine
    SPAWN["spawn Xray\nxray/process/"]:::engine
    ICMP["prober/icmp/"]:::probe
    TCP["prober/tcp/"]:::probe
    DELAY["prober/real_delay/"]:::probe
    DL["prober/download/"]:::probe
    UL["prober/upload/"]:::probe
    KILL["kill probe\nxray/process/"]:::engine
    SAVE["persist results\ndb/repository/connection_tests/"]:::store
    OUT["format & print\napp/commands/test/output/"]:::app

    CLI --> SET --> LOAD --> LOOP
    LOOP --> GEN --> SPAWN --> ICMP --> TCP --> DELAY --> DL --> UL --> KILL --> LOOP
    LOOP --> SAVE --> OUT

Connect Flow

flowchart LR
    classDef cli    fill:#1a2744,stroke:#4a9eff,color:#e6edf3
    classDef app    fill:#2a1a3a,stroke:#b070df,color:#e6edf3
    classDef engine fill:#2e1a1a,stroke:#df6060,color:#e6edf3
    classDef store  fill:#1a2e2e,stroke:#5bcfdf,color:#e6edf3

    CLI["CLI args"]:::cli
    LOAD["load config\napp/commands/connect/"]:::app
    RTSVC["start session\napp/runtime_service/connect/"]:::app
    XGEN["build runtime config\nxray/config/generator/"]:::engine
    XSPAWN["spawn detached\nxray/process_mgmt/"]:::engine
    SAVE["persist session\ndb/repository/runtime_sessions/"]:::store

    CLI --> LOAD --> RTSVC --> XGEN --> XSPAWN --> SAVE

Daemon Flow

flowchart TD
    classDef cli    fill:#1a2744,stroke:#4a9eff,color:#e6edf3
    classDef app    fill:#2a1a3a,stroke:#b070df,color:#e6edf3
    classDef event  fill:#1a2e1a,stroke:#5bdf8a,color:#e6edf3

    START["xrat daemon start"]:::cli
    FORK["fork child process"]:::app
    SUP["event loop\napp/daemon/supervisor/"]:::app
    REATTACH["reconcile stale sessions\napp/runtime_service/reattach/"]:::app
    SELECT{"tokio::select!"}:::app
    HEALTH["health check\n(every 15s)"]:::event
    IPC["IPC events\n(Unix socket)"]:::event
    ROTATE["rotation timer"]:::event

    START --> FORK --> SUP --> REATTACH --> SELECT
    SELECT --> HEALTH
    SELECT --> IPC
    SELECT --> ROTATE

Dependency Graph

Modules ordered from most foundational (left) to most dependent (right). An arrow means the target depends on the source.

graph LR
    classDef entry  fill:#1a2744,stroke:#4a9eff,color:#e6edf3
    classDef domain fill:#2e2a1a,stroke:#dfba5b,color:#e6edf3
    classDef store  fill:#1a2e2e,stroke:#5bcfdf,color:#e6edf3
    classDef engine fill:#2e1a1a,stroke:#df6060,color:#e6edf3
    classDef probe  fill:#2a2a1a,stroke:#c0df5b,color:#e6edf3
    classDef app    fill:#2a1a3a,stroke:#b070df,color:#e6edf3
    classDef iface  fill:#1a3a2a,stroke:#5bdf8a,color:#e6edf3

    support["support/"]:::domain
    model["model/"]:::domain
    config["config/"]:::domain
    db["db/"]:::store
    xray["xray/"]:::engine
    singbox["singbox/"]:::engine
    prober["prober/"]:::probe
    app["app/"]:::app
    cli["cli/"]:::iface
    server["server/"]:::iface
    main["main.rs"]:::entry

    support --> model
    model --> config
    config --> db
    config --> xray
    xray --> prober
    xray --> singbox
    prober --> app
    db --> app
    app --> cli
    cli --> main
    support --> server
    db --> server

Source Tree

src/
โ”œโ”€โ”€ main.rs           # Entrypoint: parse CLI, init tracing, dispatch command
โ”œโ”€โ”€ lib.rs            # Re-exports all public modules
โ”‚
โ”œโ”€โ”€ cli/              # Clap command/flag definitions
โ”‚   โ”œโ”€โ”€ mod.rs        # Module root, pub re-exports
โ”‚   โ”œโ”€โ”€ root.rs       # Cli struct with global flags
โ”‚   โ”œโ”€โ”€ command.rs    # Command enum (all subcommands)
โ”‚   โ”œโ”€โ”€ add.rs        # AddArgs
โ”‚   โ”œโ”€โ”€ connect.rs    # ConnectArgs
โ”‚   โ”œโ”€โ”€ daemon.rs     # DaemonArgs + DaemonAction
โ”‚   โ”œโ”€โ”€ disconnect.rs # DisconnectArgs
โ”‚   โ”œโ”€โ”€ import.rs     # ImportArgs
โ”‚   โ”œโ”€โ”€ lifecycle.rs  # select / enable / disable / delete / restore
โ”‚   โ”œโ”€โ”€ list.rs       # ListArgs + ListTarget
โ”‚   โ”œโ”€โ”€ parse.rs      # ParseArgs + ParseEngine
โ”‚   โ”œโ”€โ”€ proxy.rs      # ProxyArgs + ProxyAction
โ”‚   โ”œโ”€โ”€ scan.rs       # ScanArgs
โ”‚   โ”œโ”€โ”€ serve.rs      # ServeArgs
โ”‚   โ”œโ”€โ”€ status.rs     # StatusArgs
โ”‚   โ”œโ”€โ”€ tui.rs        # TuiArgs
โ”‚   โ”œโ”€โ”€ test_cmd/     # TestArgs + TestFormat/TestSortBy
โ”‚   โ””โ”€โ”€ tests/        # CLI parsing tests (cases/test_command, cases/runtime_parse, ...)
โ”‚
โ”œโ”€โ”€ app/              # Application layer
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ app_paths.rs  # Filesystem layout resolution
โ”‚   โ”œโ”€โ”€ context.rs    # AppContext: DB + config + runtime paths
โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ”œโ”€โ”€ paths.rs  # Runtime path resolution
โ”‚   โ”‚   โ””โ”€โ”€ tests/    # Context tests (binary, database resolution)
โ”‚   โ”œโ”€โ”€ config/       # AppConfig TOML deserialization (proxy + testing)
โ”‚   โ”œโ”€โ”€ daemon.rs     # Daemon CLI dispatch glue
โ”‚   โ”œโ”€โ”€ error.rs      # AppError enum
โ”‚   โ”œโ”€โ”€ import.rs     # Top-level import orchestration
โ”‚   โ”œโ”€โ”€ input/        # Input source reading (read_input, fetch_url)
โ”‚   โ”œโ”€โ”€ runtime_service.rs  # RuntimeService public re-exports
โ”‚   โ”œโ”€โ”€ commands/     # Command handlers
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ add.rs
โ”‚   โ”‚   โ”œโ”€โ”€ connect.rs
โ”‚   โ”‚   โ”œโ”€โ”€ daemon.rs
โ”‚   โ”‚   โ”œโ”€โ”€ disconnect.rs
โ”‚   โ”‚   โ”œโ”€โ”€ import.rs
โ”‚   โ”‚   โ”œโ”€โ”€ lifecycle.rs
โ”‚   โ”‚   โ”œโ”€โ”€ list.rs
โ”‚   โ”‚   โ”œโ”€โ”€ parse.rs
โ”‚   โ”‚   โ”œโ”€โ”€ proxy.rs
โ”‚   โ”‚   โ”œโ”€โ”€ runtime_output.rs
โ”‚   โ”‚   โ”œโ”€โ”€ scan.rs
โ”‚   โ”‚   โ”œโ”€โ”€ serve.rs
โ”‚   โ”‚   โ”œโ”€โ”€ status/   # display + json + tests submodules
โ”‚   โ”‚   โ”œโ”€โ”€ test.rs
โ”‚   โ”‚   โ”œโ”€โ”€ test/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bulk/         # bulk executor
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ bulk_executor/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ execution/    # per-config probe loop
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ handlers/     # CLI arg handling helpers
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ output/       # table / TSV / CSV / JSON output
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ output_types/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ settings/     # resolve / rows / validation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ stages/       # endpoint / progress / throughput
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tests/        # focused tests
โ”‚   โ”‚   โ””โ”€โ”€ tui.rs
โ”‚   โ”œโ”€โ”€ runtime_service/  # Proxy process lifecycle
โ”‚   โ”‚   โ”œโ”€โ”€ connect/      # Connect flow
โ”‚   โ”‚   โ”œโ”€โ”€ replace_flow/ # Atomic disconnect + connect (candidate, ports, stage)
โ”‚   โ”‚   โ”œโ”€โ”€ reattach/     # Stale session recovery (process inspector)
โ”‚   โ”‚   โ”œโ”€โ”€ session_state/# State transitions + inbound health
โ”‚   โ”‚   โ”œโ”€โ”€ types.rs
โ”‚   โ”‚   โ””โ”€โ”€ tests/        # Integration tests
โ”‚   โ””โ”€โ”€ daemon/       # Daemon supervisor
โ”‚       โ”œโ”€โ”€ ipc/      # Unix socket IPC protocol
โ”‚       โ”‚   โ”œโ”€โ”€ types.rs      # Request/response types (DaemonRequest, RotationTrigger, ...)
โ”‚       โ”‚   โ”œโ”€โ”€ handler/      # dispatch.rs + io.rs
โ”‚       โ”‚   โ”œโ”€โ”€ client/       # unix_impl.rs + unsupported_impl.rs
โ”‚       โ”‚   โ”œโ”€โ”€ transport/    # ping_shutdown.rs, proxy.rs, runtime.rs
โ”‚       โ”‚   โ””โ”€โ”€ tests/        # IPC integration tests
โ”‚       โ””โ”€โ”€ supervisor/      # Event loop
โ”‚           โ”œโ”€โ”€ mod.rs
โ”‚           โ”œโ”€โ”€ types.rs
โ”‚           โ”œโ”€โ”€ health.rs
โ”‚           โ”œโ”€โ”€ runtime.rs
โ”‚           โ”œโ”€โ”€ test_support.rs
โ”‚           โ”œโ”€โ”€ tests.rs
โ”‚           โ””โ”€โ”€ handlers/    # Health check, rotation, runtime
โ”‚               โ”œโ”€โ”€ health.rs
โ”‚               โ”œโ”€โ”€ mod.rs
โ”‚               โ”œโ”€โ”€ runtime/         # runtime_lifecycle/, runtime_status_connect/
โ”‚               โ””โ”€โ”€ tests/           # tests_replace/
โ”‚
โ”œโ”€โ”€ model/             # Shared domain types
โ”‚   โ”œโ”€โ”€ node.rs        # Node struct
โ”‚   โ”œโ”€โ”€ protocol.rs    # Protocol enum
โ”‚   โ””โ”€โ”€ node_dedup_key.rs  # Dedup key generation
โ”‚
โ”œโ”€โ”€ config/            # Config parsing and normalization
โ”‚   โ”œโ”€โ”€ protocols/     # Protocol-specific parsers
โ”‚   โ”‚   โ”œโ”€โ”€ vless.rs   # vless:// parser
โ”‚   โ”‚   โ”œโ”€โ”€ vmess.rs   # vmess:// parser
โ”‚   โ”‚   โ”œโ”€โ”€ ss.rs      # ss:// parser
โ”‚   โ”‚   โ”œโ”€โ”€ trojan.rs  # trojan:// parser
โ”‚   โ”‚   โ”œโ”€โ”€ http.rs    # http:// parser
โ”‚   โ”‚   โ”œโ”€โ”€ socks5.rs  # socks5:// parser
โ”‚   โ”‚   โ”œโ”€โ”€ hy2.rs     # hysteria2:// parser
โ”‚   โ”‚   โ””โ”€โ”€ tests/     # Parser tests
โ”‚   โ”œโ”€โ”€ line.rs        # Line-by-line text parsing
โ”‚   โ”œโ”€โ”€ normalize.rs   # Node normalization defaults
โ”‚   โ”œโ”€โ”€ parse_service.rs # Engine-aware parsing
โ”‚   โ”œโ”€โ”€ import/        # Import format detection
โ”‚   โ”‚   โ”œโ”€โ”€ detect.rs  # Format detection heuristics
โ”‚   โ”‚   โ”œโ”€โ”€ error.rs
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs     # ImportMode / ImportResult / parse_import
โ”‚   โ”‚   โ”œโ”€โ”€ subscription.rs # URL fetch + metadata
โ”‚   โ”‚   โ””โ”€โ”€ parsers/   # single_link, plain_list, base64, sip008, xray
โ”‚   โ””โ”€โ”€ parsing_helpers.rs # Shared URI helpers
โ”‚
โ”œโ”€โ”€ db/                # Database layer
โ”‚   โ”œโ”€โ”€ connection.rs  # Connection pool management
โ”‚   โ”œโ”€โ”€ schema.rs      # Migration runner
โ”‚   โ”œโ”€โ”€ error.rs       # DbError enum
โ”‚   โ”œโ”€โ”€ mod.rs         # DbPool + facade re-exports
โ”‚   โ”œโ”€โ”€ database/      # Database query methods
โ”‚   โ”œโ”€โ”€ repository/    # SQL implementations
โ”‚   โ”‚   โ”œโ”€โ”€ api/       # API-specific queries
โ”‚   โ”‚   โ”œโ”€โ”€ cf_scan_results.rs
โ”‚   โ”‚   โ”œโ”€โ”€ configs/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ import_ops/  # Upsert on dedup_key
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ state_ops/   # enable/disable/select/delete
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ server_ops.rs
โ”‚   โ”‚   โ”œโ”€โ”€ connection_tests.rs
โ”‚   โ”‚   โ”œโ”€โ”€ row/             # Shared row helpers
โ”‚   โ”‚   โ””โ”€โ”€ runtime_sessions.rs
โ”‚   โ””โ”€โ”€ record/        # Record types (DTOs)
โ”‚       โ”œโ”€โ”€ cf_scan_results.rs
โ”‚       โ”œโ”€โ”€ configs.rs
โ”‚       โ”œโ”€โ”€ connection_tests.rs
โ”‚       โ”œโ”€โ”€ import.rs  # ImportSource, SubscriptionRecord, ...
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ””โ”€โ”€ runtime_sessions.rs
โ”‚
โ”œโ”€โ”€ xray/              # Xray-core integration
โ”‚   โ”œโ”€โ”€ config/        # Config generation
โ”‚   โ”‚   โ”œโ”€โ”€ generator/ # Probe + runtime config builders
โ”‚   โ”‚   โ”œโ”€โ”€ outbound.rs # Protocol-to-outbound mapping
โ”‚   โ”‚   โ”œโ”€โ”€ stream.rs  # Stream settings (TLS, WS, gRPC, TCP)
โ”‚   โ”‚   โ””โ”€โ”€ types.rs   # XrayConfig, Inbound, Outbound structs
โ”‚   โ”œโ”€โ”€ parsing/       # Xray JSON config parsing
โ”‚   โ”‚   โ”œโ”€โ”€ core/      # Top-level config structure
โ”‚   โ”‚   โ”œโ”€โ”€ protocols/ # Inbound/outbound protocol parsers
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ inbound_settings/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ outbound_settings/
โ”‚   โ”‚   โ”œโ”€โ”€ transports/ # Transport settings parsers
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ security/
โ”‚   โ”‚   โ””โ”€โ”€ shared/    # Shared types (enums, strings)
โ”‚   โ”œโ”€โ”€ process/       # Low-level process spawn + lifecycle
โ”‚   โ”‚   โ”œโ”€โ”€ errors.rs
โ”‚   โ”‚   โ”œโ”€โ”€ spawn.rs
โ”‚   โ”‚   โ””โ”€โ”€ tests.rs
โ”‚   โ””โ”€โ”€ process_mgmt/  # High-level process management + signals
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ”œโ”€โ”€ process.rs
โ”‚       โ”œโ”€โ”€ signals.rs
โ”‚       โ””โ”€โ”€ tests.rs
โ”‚
โ”œโ”€โ”€ singbox/           # sing-box integration
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ””โ”€โ”€ config/        # sing-box config generation + process_mgmt helper
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ””โ”€โ”€ process_mgmt.rs
โ”‚
โ”œโ”€โ”€ prober/            # Connection testing probes
โ”‚   โ”œโ”€โ”€ mod.rs         # FailureKind + combined TestResult
โ”‚   โ”œโ”€โ”€ icmp/          # ICMP ping (parse system ping output)
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs     # icmp_ping, ping_with_system_command
โ”‚   โ”‚   โ”œโ”€โ”€ parsing.rs # parse_ping_latency, classify_ping_failure
โ”‚   โ”‚   โ””โ”€โ”€ tests.rs
โ”‚   โ”œโ”€โ”€ tcp/           # TCP connectivity check + failure classification
โ”‚   โ”‚   โ”œโ”€โ”€ check.rs   # tcp_check
โ”‚   โ”‚   โ”œโ”€โ”€ classify.rs
โ”‚   โ”‚   โ”œโ”€โ”€ errors.rs
โ”‚   โ”‚   โ”œโ”€โ”€ model.rs   # TcpResult
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ””โ”€โ”€ tests.rs
โ”‚   โ”œโ”€โ”€ real_delay/    # HTTP round-trip latency via proxy
โ”‚   โ”‚   โ”œโ”€โ”€ check/     # execute, model, port, request, mod
โ”‚   โ”‚   โ”œโ”€โ”€ classify.rs
โ”‚   โ”‚   โ””โ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ download/      # Download speed measurement
โ”‚   โ”‚   โ”œโ”€โ”€ check/     # proxied, result, mod
โ”‚   โ”‚   โ”œโ”€โ”€ classify.rs
โ”‚   โ”‚   โ””โ”€โ”€ mod.rs
โ”‚   โ””โ”€โ”€ upload/        # Upload speed measurement
โ”‚       โ”œโ”€โ”€ classify.rs
โ”‚       โ”œโ”€โ”€ mod.rs
โ”‚       โ””โ”€โ”€ request.rs
โ”‚
โ”œโ”€โ”€ server/            # Axum HTTP API
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ routes/        # b64, configs, health, json
โ”‚   โ”œโ”€โ”€ auth.rs        # API key authentication
โ”‚   โ”œโ”€โ”€ response.rs    # Response types
โ”‚   โ”œโ”€โ”€ state.rs       # ServerState
โ”‚   โ””โ”€โ”€ error.rs       # Server error types
โ”‚
โ”œโ”€โ”€ tui/               # Ratatui TUI
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ run.rs         # Terminal lifecycle + main loop
โ”‚   โ”œโ”€โ”€ keymap.rs
โ”‚   โ”œโ”€โ”€ task.rs        # Background task primitives
โ”‚   โ”œโ”€โ”€ theme.rs
โ”‚   โ”œโ”€โ”€ app/           # App state, reducers, navigation
โ”‚   โ”œโ”€โ”€ data/          # Data loading + tests
โ”‚   โ””โ”€โ”€ view/          # chrome, configs, sources, runtime, tests, modals
โ”‚
โ””โ”€โ”€ support/           # Shared utilities
    โ”œโ”€โ”€ decode.rs      # Base64 decoding
    โ”œโ”€โ”€ geoip.rs       # MaxMind GeoIP lookups
    โ”œโ”€โ”€ net.rs         # Network utilities
    โ”œโ”€โ”€ time.rs        # Timestamp helpers
    โ””โ”€โ”€ url.rs         # URL detection helpers

File Conventions

  • mod.rs: Module root, pub re-exports
  • Names: Snake_case for files/modules, PascalCase for types, snake_case for functions
  • Tests: #[cfg(test)] mod tests { ... } in same file or tests/ submodule
  • Records/DTOs: In db/record/ โ€” thin structs matching DB rows
  • Repository: In db/repository/ โ€” SQL query functions separated by entity