How juliuskreutz/stardb-exporter works
Project type and purpose
• From the file tree and README, this is a single‑binary Rust CLI/TUI application (“stardb‑exporter”) whose job is to sniff network packets from Genshin Impact (GI) or Honkai: Star Rail (HSR) via libpcap, decode their game‑specific protocols, and export the resulting data (automatically copying it to the clipboard).
File structure
• Top‑level:
• Cargo.toml, build.rs, flake.nix → Build system and reproducible environment
• src/main.rs, src/app.rs → Application entry point and core orchestrator
• src/games/… → Protocol parsers for each game (gi.rs, hsr.rs) plus shared parsing glue (mod.rs)
• src/ui/… → TUI screens and widgets (login, menu, waiting, pulls, achievements, error, etc.)
• keys/… → Protocol decryption keys for each game
• External integration:
• libpcap (via system package/cap_net_raw capability) for packet capture
• Clipboard API (Rust crate) to copy export JSON to the user’s clipboard
README for additional insights
• Uses raw 802.11 (monitor mode) or WinPcap in WinPcap API‑compatible mode
• Flow: user launches exporter, enters monitor mode, app reports “Device ready~!”, user triggers game action, exporter grabs data and copies it to clipboard, user pastes into stardb.gg/import.
a. Main components
1. CLI/TUI Frontend
• Responsible for all on‑screen interaction (menus, status, errors).
2. Application Core (State Machine)
• Manages lifecycle: initialization → device ready → capture → parsing → export → done/error.
3. Network Capture Layer
• libpcap binding that opens the interface in monitor/raw mode and feeds raw packets.
4. Protocol Parsers
• Game‑specific modules (GI, HSR) that take raw packet streams, decrypt and deserialize messages.
5. Output/Export
• Serializes parsed data into JSON (or internal format) and pushes to clipboard.
6. Configuration & Keys
• Key store loaded at startup to decrypt game traffic.
7. Build/Deploy (auxiliary)
• Cargo, build.rs, flake.nix for reproducible builds; GitHub Actions workflows for clippy & release.
b. Relationships & interactions
• User → CLI/TUI Frontend (input events)
• Frontend ↔ Application Core (dispatch user actions & render state)
• Core → Network Capture Layer (start/stop sniffing)
• Layer → Protocol Parsers (stream of raw packets)
• Parsers → Application Core (parsed game data events)
• Core → Frontend (update UI screens on new data)
• Core → Output/Export (on completion, serialize & copy to clipboard)
c. Architectural patterns/design principles
• Separation of concerns: UI, core state machine, capture, parsing, export
• Pluggable parsers: Each game has its own parser module under src/games
• Theme abstraction: UI visuals pulled from src/themes at runtime
• Single‑process, event‑driven architecture
d. Key technologies/frameworks/libraries
• Rust/Cargo (build & dependency management)
• libpcap (via pcap crate) for packet capture
• TUI toolkit (e.g., tui-rs + crossterm) for terminal UI
• Clipboard crate for cross‑platform clipboard access
• Nix (flake.nix) for reproducible development environment
Elements
• Another for “UI” (Frontend, Themes)
• Another for “External Dependencies” (libpcap, OS capabilities, clipboard)
Final advice
• Be as granular as helpful: split UI into screens if needed, show theme loading as separate step.
• Build tools (Cargo, GitHub Actions, flake.nix) outside the runtime path but visibly connected to the source directory to illustrate CI/CD boundaries.