Architecture
System Overview
User ──► CLI (cobra) ──► Cache Store (disk)
│ │
│ ▼
│ Fresh cache? ──Yes──► Filter in-memory ──► Output
│ │
│ No
│ ▼
└──────► GitHub GraphQL Client ──► Output
│
▼
Save to cache
The tool is a single Go binary with four layers: CLI commands, business logic (filtering, display), cache store, and GitHub API client.
Key Components
| Component | Responsibility | Technology |
|---|---|---|
cmd/ (root, issue, pr, cache, repo, mock) |
CLI interface, flag parsing, command handlers | cobra |
internal/cache/ |
On-disk JSON cache read/write, freshness checks | Go standard library |
internal/github/ |
GitHub GraphQL API client, query building, response parsing | Go net/http |
internal/gitremote/ |
Git remote URL detection and parsing | Go os/exec |
internal/mockserver/ |
In-process mock GitHub GraphQL server, scenario builder, simulation generator | Go net/http/httptest |
internal/version/ |
Build version resolution from ldflags or Go build info | Go runtime/debug |
Data Flow
- User invokes a CLI command (e.g.
gh-cached issue list). - The command handler resolves the target repository from
--repoflag or git remote. - A
cache.Storechecks whether the full cache is fresh for that repo. - If fresh, cached JSON files are loaded into memory and filtered according to CLI flags.
- If stale or missing, a
github.Clientmakes GraphQL API calls, saves results to cache, and returns them. - Results are formatted (tabular or JSON) and printed to stdout.
Infrastructure
- CI/CD: GitHub Actions (
.github/workflows/build.yml) - Builds for 4 platforms: darwin-amd64, darwin-arm64, linux-amd64, windows-amd64
- On push to main: creates/updates a
latestprerelease with all binaries - Distribution:
go installfrom source, or pre-built binaries from GitHub Releases - Testing: Mock server (
internal/mockserver) provides anhttptest.Serverthat mirrors the GitHub GraphQL API contract for integration tests without network access - No observability: The tool is a CLI with no runtime metrics, logging, or tracing
- No hosting: Fully client-side, no server component (mock server is for testing only)
Architecture Decisions
- GraphQL-only API access (no REST endpoints used), documented in code and README
- File-per-item cache layout (
issues/42.json,prs/10.json) for efficient individual lookups - Token resolution chain:
GH_TOKEN>GITHUB_TOKEN>gh auth token - Authoritative cache mode: when full cache is fresh,
viewcommands serve from cache without API fallback - Mock server uses
httptest.Serverwith route-based query matching (string contains) for simplicity - Simulation generator uses an event-based timeline with weighted time sampling for realistic activity bursts