How gnostr-org/gnostr works
Project Type & Purpose
• This is a Rust-based, CLI/TUI “git+nostr” workflow utility called gnostr, organized as a Cargo workspace with multiple crates.
• Its core deliverable is a terminal application combining Git operations with the Nostr protocol (P2P messaging over relays), plus a number of companion tools (asyncgit library, crawlers, testing crates, QR generator, etc.).
File-Structure & Architectural Patterns
• Top-level Cargo.toml defines a workspace:
• Root crate in /src for the main gnostr binary (and sub-bins like git_remote_nostr).
• Library modules under src/lib (business logic: chat, git, Nostr, UI components, subcommands).
• Sub-crates at root level (asyncgit, crawler, filetreelist, git2-hooks, qr, scopetime, etc.) that encapsulate reusable functionality.
• Notice:
• A modular, crate-per-capability pattern (separation by domain: Git sync, Nostr p2p, UI, subcommands).
• A Tokio-based, event-driven runtime (global runtime in lib/global_rt.rs).
• MVC-like separation in the main crate:
– Controllers / sub_commands dispatch → Git/Nostr services → update Model → View (TUI) renders.
Key Components
A. CLI & TUI Frontend
• Entry point: src/main.rs & src/bin/...
• Argument parser: src/lib/args.rs → builds command objects
• Subcommands layer: src/lib/sub_commands/* (e.g., fetch, push, chat, tui)
• UI layer: TUI framework modules (components/, popups/, tabs/, ui/, tui.rs)
B. Core Application Logic
• Command dispatcher: maps CLI input to business logic
• State manager: repo_state.rs, queue.rs, watcher.rs
• Async event loop: Tokio runtime + channels in global_rt.rs
C. Git Integration (asyncgit)
• asyncgit crate: sits as a dependency—handles all Git operations asynchronously
• Sync engine: src/lib/git_events.rs, src/lib/git/utils.rs, asyncgit/src/sync/*
• Local FS: repository files, default config (default_config.conf)
D. Nostr Integration
• Core Nostr crate: modules in src/lib/gnostr/*
• P2P & Relay management: src/lib/chat/p2p.rs, relay_manager.rs in crawler crate
• Network layer: WebSockets / HTTP (external relays)
E. Data Stores & Config
• Local config: key_config.rs, login (user, key encryption)
• On-disk: local Git repos (FS), possibly SQLite (nostr-sqlite.rs example)
• External services: Nostr relays, Git remotes
Relationships & Data Flow
• User → TUI/CLI → Command Dispatcher
• Dispatcher calls either:
• Git Service (asyncgit) → FS & Git remote via network → returns results
• Nostr Service → opens WebSocket to relays → publishes/subscribes events
• Results → Model / State Manager → View (UI) updates
• Background tasks (watcher, event subscriptions) push updates into the same event loop
Architectural Patterns & Principles
• Modular crates for reusability: asyncgit, crawler, filetreelist, etc.
• Event-driven with Tokio: decouples UI from I/O
• Command pattern for subcommands
• MVU (Model-View-Update) style in TUI layer: state + view + update cycle