Skip to content

04 Codebase Tour

Vicky Patel edited this page Nov 18, 2026 · 1 revision

04. Codebase Tour & Directory Walkthrough

A Developer's Architectural Map of the GitVerse Repository


🗺️ Project Structure Overview

GitVerse maintains a clean separation of concerns between core analytical domain logic (internal/), entrypoint binaries (cmd/), serverless edge API handlers (api/), and user interface assets (site/, internal/webui/).

graph TD
    Root[GitVerse Root] --> Cmd[cmd/]
    Root --> Internal[internal/]
    Root --> Api[api/]
    Root --> Site[site/]
    Root --> Scripts[scripts/]

    Cmd --> CLIBin[cmd/gitverse]
    Cmd --> DevServ[cmd/gitverse-devserver]

    Internal --> Cat[internal/catalog]
    Internal --> Eng[internal/engine]
    Internal --> GH[internal/github]
    Internal --> UI[internal/webui]

    Api --> VercelEndpoints[api/*.go]
Loading

📂 Detailed Module Breakdown

1. cmd/ — Application Entrypoints

  • cmd/gitverse/main.go:
    • The entrypoint for the terminal command-line interface.
    • Parses flags (--all, --json, --raw, --token, --version).
    • Automatically queries local gh auth token via exec.Command if no token is provided.
    • Invokes internal/engine and formats results as either rich ANSI tables or JSON.
  • cmd/gitverse-devserver/main.go:
    • Standalone local HTTP server used for local web development without needing the full Vercel CLI.
    • Mounts routes (/, /check/, /achievements/, /api/stars, etc.) and re-renders templates dynamically on file save.

2. internal/catalog/ — Domain Models & Specifications

  • types.go:
    • Defines the core data structures: Badge, Tier, Threshold, Status (earnable, disabled, retired, internal), and Provenance (official, calibrated, counted).
  • achievements.go:
    • The canonical registry of all 15 GitHub achievements.
    • Stores exact tier numerical milestones (e.g., Pull Shark: 2, 16, 128, 1024; Starstruck: 16, 128, 512, 4096).
    • Holds official SVG asset URLs, titles, and descriptions.

3. internal/engine/ — Calculation & Delta Logic

  • engine.go:
    • Accepts raw contribution records from internal/github and reconciles them against internal/catalog.
    • Determines which tier badge has been unlocked.
    • Assigns confidence provenance levels to each metric.
  • deltas.go:
    • Computes remaining numbers to achieve the next tier: $$\Delta = \text{NextThreshold} - \text{CurrentCount}$$
    • Computes progress percentage for progress bar rendering.

4. internal/github/ — Communication & Scraping

  • scraper.go:
    • Uses Go's golang.org/x/net/html to parse public GitHub profile achievement HTML pages.
    • Extracts unlock dates, tier numbers, and milestone badges.
  • client.go:
    • Configures an HTTP client with custom user agents, timeouts, connection pooling, and retry logic.
  • oauth.go:
    • Manages GitHub OAuth 2.0 token exchange, encrypted state validation (HMAC-SHA256), and instantaneous token revocation calls (POST /applications/{client_id}/grant).

5. internal/webui/ — Presentation Layer & Templating

  • templates/:
    • Contains Go HTML templates (base.html, track.html, explore.html, about.html, privacy.html, result.html).
  • renderer.go:
    • Compiles and caches HTML templates at startup using html/template.
    • Exposes helper functions for formatting numbers, dates, and SVG badges.

6. api/ — Vercel Serverless Handlers

  • api/stars/index.go:
    • Micro-handler that queries the live stargazers count of TheVicky1/GitVerse using GH_BOT_TOKEN.
    • Sets edge CDN headers Cache-Control: public, s-maxage=60.
  • api/login/index.go:
    • Generates secure OAuth authorization redirect URLs with anti-CSRF state tokens.
  • api/callback/index.go:
    • Receives GitHub's authorization code, exchanges it for an access token, triggers internal/engine, and redirects to the results view.
  • api/result/index.go:
    • Renders the final achievement report page for public handles or verified private sessions.
  • api/markdown/index.go:
    • Generates dynamic SVG and Markdown badge snippets for profile embedding.

7. scripts/gendocs/ — Static Site Generation & Drift Checks

  • main.go:
    • Reads internal/catalog and generates static HTML files in site/ (e.g. site/explore/index.html, site/about/index.html).
    • Ensures static SEO pages never drift from the underlying Go codebase.
    • Run automatically during CI tests to verify 0-drift.

Clone this wiki locally