Skip to content

Workspace Architecture

Ken Tobias edited this page Jun 10, 2026 · 7 revisions

Workspace Architecture

retch is structured as a Cargo workspace to keep the codebase modular, clean, and reusable.

Repository Layout

.
├── Cargo.toml            # Root workspace config
├── Cargo.lock
├── Justfile              # Command runner scripts
├── README.md
├── docs/                 # Manual pages & documentation
├── src/                  # retch-cli source code
│   ├── cli.rs            # Clap arguments and flags
│   ├── config.rs         # TOML parsing & merge logic
│   ├── display.rs        # Output formatting and rendering
│   ├── fetch.rs          # Thin re-export shim → retch_sysinfo::fetch
│   ├── gpu.rs            # Thin re-export shim → retch_sysinfo::gpu
│   ├── logo.rs           # Logo rendering (Kitty/iTerm2/Sixel/Chafa/ASCII)
│   ├── theme.rs          # Theme definitions and color resolution
│   └── main.rs           # Entry point and config creation
└── crates/
    └── sysinfo/          # retch-sysinfo subcrate (standalone library)
        ├── Cargo.toml
        └── src/
            ├── lib.rs        # Public API surface
            ├── fetch.rs      # Parallel scoped-thread fetching pipeline
            ├── gpu.rs        # GPU detection and PCI ID lookup
            ├── display.rs    # Display detection and EDID parsing
            ├── network.rs    # Network interfaces, IP resolution, and Wi-Fi
            ├── audio.rs      # Audio server and device detection
            ├── bluetooth.rs  # Bluetooth controller state and connected devices
            └── battery.rs    # Cross-platform battery implementation

Cargo Workspace

The root Cargo.toml specifies the workspace members:

[workspace]
members = [
    ".",
    "crates/sysinfo",
]

1. retch-cli (Root Package)

The main binary command-line interface. It handles terminal detection, configuration parsing, logo rendering, and output formatting. The system information fetching and hardware detection logic has been extracted into retch-sysinfo; src/fetch.rs and src/gpu.rs are thin re-export shims so all existing call sites continue to compile unchanged.

2. crates/sysinfo (retch-sysinfo v0.1.10)

The core system information library. All hardware detection and slow external queries live here, executed concurrently using std::thread::scope.

  • fetch.rs: Parallel fetching pipeline. Spawns scoped threads for slow queries (GPU, packages, IPs, active interface, motherboard, BIOS, displays, audio, WiFi, Bluetooth, UI theme/fonts, camera, gamepad) and collects results into SystemInfo. Exposes CollectOptions to decouple collection from the CLI argument parser, making the library usable without clap.
  • gpu.rs: GPU detection across Linux (/proc, /sys, PCI ID database lookup), macOS (system_profiler), and Windows (WMI/registry).
  • display.rs: Display detection and EDID parsing. On Linux, reads /sys/class/drm and raw EDID bytes directly, falling back to xrandr. Parses monitor names, preferred resolutions, refresh rates, and serial numbers from EDID Detailed Timing Descriptor (DTD) blocks.
  • network.rs: Network interface detection, IP resolution, and Wi-Fi. Detects the active interface and local IP via /proc/net/route (Linux native) or platform routing commands, fetches the public IP, builds the formatted interface list with per-interface IPv4/IPv6 addresses, and detects the connected Wi-Fi SSID and link parameters via iw/nmcli (Linux), airport (macOS), or netsh (Windows). Also exposes lookup_pci_vendor for shared use by bluetooth detection.
  • audio.rs: Audio server and device detection. On Linux, scans the process list for PipeWire/PulseAudio and reads hardware card names from /proc/asound codec files. On macOS, queries system_profiler SPAudioDataType. On Windows, queries wmic Win32_SoundDevice.
  • bluetooth.rs: Bluetooth controller state and connected device detection. On Linux, reads /sys/class/bluetooth sysfs entries, resolves adapter hardware via USB (/usr/share/hwdata/usb.ids) and PCI ID databases, and queries connected devices via bluetoothctl. On macOS, parses system_profiler SPBluetoothDataType. On Windows, probes via PowerShell Get-Service/Get-PnpDevice.
  • battery.rs: Cross-platform battery statistics — reads /sys/class/power_supply/ on Linux, calls native CoreFoundation IOPSCopyPowerSourcesInfo APIs on macOS, and queries WMI on Windows.

Clone this wiki locally