How abhixdd/ghgrab works
1. Project shape
- ghgrab is primarily a Rust CLI application that exposes one core binary and a library crate.
- The repo also contains distribution wrappers for npm, Python, and Nix, but they all ultimately point to the same Rust implementation.
2. Top-level command model
- The user-facing surface has three main modes:
- Interactive browsing of GitHub repositories and files.
- Release download for GitHub release assets.
- Agent mode for machine-readable, non-interactive automation.
- The README and file layout suggest these modes are routed from a shared CLI entrypoint into separate command handlers.
3. Rust core boundary
- The Rust source under src/ is the architectural center.
- src/lib.rs likely exposes shared logic, while src/main.rs and src/bin/ghg.rs are executable entrypoints.
- src/cli.rs is the command-line parsing layer that dispatches into higher-level operations.
4. GitHub data access layer
- src/github.rs is the integration boundary to GitHub APIs and repo/release metadata.
- This layer is responsible for repo discovery, repository tree enumeration, search, and release asset lookup.
- Authentication is supported through saved config, GHGRAB_GITHUB_TOKEN, GITHUB_TOKEN, or one-shot --token overrides.
5. Download and file retrieval pipeline
- src/download.rs is the file transfer boundary.
- It handles downloading repository paths, folders, and release assets, plus special handling for larger or special-case content.
- The README’s GitHub LFS support indicates this layer also resolves large-file download behavior, not just simple content fetches.
6. Release selection subsystem
- src/release.rs is a dedicated workflow for GitHub releases.
- It selects the best asset based on OS/architecture, optional regex, file type, prerelease rules, and user overrides.
- When selection is ambiguous, the CLI falls back to an interactive choice flow rather than guessing silently.
7. Interactive TUI subsystem
- src/ui/ contains the terminal interface built on the ratatui ecosystem.
- Components are split by responsibility: browser, input, preview, repo search, searching state, toast notifications, and syntax highlighting.
- This UI is the main boundary between the user and the underlying repo/download logic, providing browsing, selection, preview, and keyboard-driven navigation.
8. App state and orchestration
- src/agent.rs and the UI modules imply a shared application state model coordinating user input, navigation, search, preview, and download actions.
- The TUI is not just presentation; it orchestrates transitions between home, repo search, browser, and preview states.
9. Agent mode / automation boundary
- The agent command is a separate non-interactive API-like surface.
- It prints a stable JSON envelope with api_version, ok, command, and either data or error, making it suitable for scripts, CI, and other agents.
- This is a clean architectural boundary: human-oriented TUI vs machine-oriented structured output.
10. Configuration and theming
- src/config.rs likely owns local settings such as download path and token persistence.
- Theme customization is handled through TOML files, with defaults falling back to a built-in Tokyo Night palette via src/ui/theme.rs.
- This separates runtime preferences from command execution and keeps the UI styling configurable without changing code.
11. Packaging and runtime distribution
- The presence of package.json, bin/ghgrab.js, setup.py, pyproject.toml, and scripts/install.js shows the Rust binary is packaged for multiple ecosystems.
- These wrappers are distribution-only layers; they do not define product behavior, but they materially affect how the binary is installed and launched.
12. Testing and CI
- tests/ covers CLI behavior, app state, and release selection, which aligns with the project’s main risk areas.
- GitHub Actions workflows in .github/workflows/ handle build and CI validation, reinforcing that the repo is organized around a single Rust core with packaging and release automation around it.
13. How the main data flow works
- Input starts as either a repo URL, search term, or release target.
- The CLI/agent layer parses the command, the GitHub layer resolves metadata, the UI may present choices, and the download layer writes files locally.
- Configuration and tokens influence all of these stages, but the execution path remains centered on GitHub discovery → selection → download.
14. Architecture summary for a diagram
- A good diagram should show one central Rust core with four major internal boundaries: CLI/dispatch, GitHub API integration, download/release logic, and TUI/agent presentation.
- Around that core are local config/theme storage, GitHub as the external service, and distribution wrappers for npm/Python/Nix.
Main entry points: cli.rs Command router · mod.rs TUI shell · main.rs Main CLI · github.rs GitHub client
Components 20
Rust core
Primary application logic and runtime orchestration
- Library core · Shared crate entry for core logic
src/lib.rs - Main CLI · Primary executable entrypoint
src/main.rs - Ghg binary · Secondary executable entrypoint
src/bin/ghg.rs - Command router · Parses commands and dispatches modes
src/cli.rs - Agent mode · Non-interactive structured command surface
src/agent.rs - Config store · Local config, tokens, and download settings
src/config.rs - GitHub client · Repo search, tree lookup, metadata, and auth
src/github.rs - Download engine · Fetches files, folders, assets, and LFS content
src/download.rs - Release selector · Chooses release assets by platform and filters
src/release.rs
Terminal UI
Interactive browsing and preview experience
- TUI shell · Top-level interactive application shell
src/ui/mod.rs - Repo browser · Navigates repositories and file trees
src/ui/components/browser.rs - Repo search · Searches repositories and surfaces results
src/ui/components/repo_search.rs - Preview pane · Shows file and asset previews
src/ui/components/preview.rs - Input field · Keyboard input and command entry
src/ui/components/input.rs - Theme system · Color palette and styling defaults
src/ui/theme.rs
Distribution
Packaging and installer wrappers
- NPM wrapper · JavaScript install/launch wrapper
bin/ghgrab.js - Python package · Python packaging surface for the binary
setup.py - Nix package · Nix-based build and install packaging
flake.nix
Quality
Tests and CI validation
- Test suite · CLI, state, and release behavior tests
tests - CI workflows · Build and continuous integration checks
.github/workflows/ci.yml
Connections 29
- Main CLI → Command router: dispatches · Main executable hands off to command routing
- Ghg binary → Command router: dispatches · Secondary binary uses the same CLI layer
- Command router → Config store: loads · Reads settings and token sources
- Command router → GitHub client: queries · Resolves repositories, trees, and metadata
- Command router → Download engine: invokes · Starts file and asset retrieval
- Command router → Release selector: selects · Routes release-target commands into asset selection
- Command router → TUI shell: launches · Interactive commands enter the TUI shell
- Command router → Agent mode: runs · Agent commands produce structured output
- Agent mode → GitHub client: uses · Automation still relies on GitHub metadata access
- Agent mode → Download engine: uses · Agent mode can trigger downloads
- TUI shell → Repo browser: contains · Browser state is part of the interactive shell
- TUI shell → Repo search: contains · Repo search is a core UI mode
- TUI shell → Preview pane: contains · Previewing is integrated into the shell
- TUI shell → Input field: contains · Keyboard input drives UI navigation
- TUI shell → Theme system: styles · Shell uses the theme system for presentation
- Repo browser → GitHub client: browses · Fetches and navigates repository content
- Repo search → GitHub client: searches · Finds repositories through GitHub APIs
- Preview pane → Download engine: renders · Preview content is sourced from downloaded data
- Release selector → GitHub client: inspects · Finds and filters release assets and metadata
- Release selector → Download engine: chooses · Selected asset proceeds into transfer pipeline
- Config store → Theme system: configures · Local settings can override UI appearance
- NPM wrapper → Main CLI: wraps · NPM installer launches the Rust binary
- Python package → Main CLI: wraps · Python packaging points at the Rust executable
- Nix package → Main CLI: wraps · Nix build/install targets the Rust binary
- Test suite → Command router: covers · Validates command behavior
- Test suite → Agent mode: covers · Checks JSON envelope behavior
- Test suite → Release selector: covers · Verifies release asset selection
- CI workflows → Test suite: runs · Workflows execute the validation suite
- CI workflows → Main CLI: builds · CI builds the primary binary