Skip to content

03 Architecture

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

03. System Architecture & Engineering

Dual-Engine Technical Architecture, Package Boundaries & Data Flow


๐Ÿ—๏ธ High-Level System Architecture

GitVerse is engineered in Go 1.25+ as a dual-engine architecture: a single analytical core compiled into both a high-performance command-line binary (cmd/gitverse) and lightweight serverless HTTP handlers running on Vercel's Edge Network (api/*).

graph TD
    subgraph Client Layer
        WebUser[Web Browser Client]
        TermUser[Terminal CLI Client]
    end

    subgraph Entrypoints
        VercelFuncs["Vercel Go Serverless Handlers (api/*)"]
        CLIMain["CLI Entrypoint (cmd/gitverse/main.go)"]
    end

    subgraph GitVerse Core Engine
        Engine["internal/engine (Calculation & Delta Math)"]
        Catalog["internal/catalog (15 Badges, Tiers, Metadata)"]
        GHClient["internal/github (Scraping, OAuth, GraphQL/REST)"]
        WebUI["internal/webui (HTML Templates & Asset Pipeline)"]
    end

    subgraph External Boundaries
        GHWeb["GitHub Public HTML (Profile Modals)"]
        GHAPI["GitHub REST & GraphQL API"]
        GHOAuth["GitHub OAuth Consent Server"]
    end

    WebUser -->|HTTPS| VercelFuncs
    TermUser -->|Exec| CLIMain

    VercelFuncs --> Engine
    VercelFuncs --> WebUI
    CLIMain --> Engine

    Engine --> Catalog
    Engine --> GHClient

    GHClient -->|Scrape /achievements| GHWeb
    GHClient -->|Fetch Milestones & PRs| GHAPI
    GHClient -->|Token Exchange| GHOAuth
Loading

๐Ÿ“ฆ Package Boundaries & Directory Layout

The codebase strictly adheres to standard Go project conventions:

GitVerse/
โ”œโ”€โ”€ api/                           # Vercel Serverless Go entrypoints
โ”‚   โ”œโ”€โ”€ index.go                   # Root redirect / landing proxy
โ”‚   โ”œโ”€โ”€ login/index.go             # Initiates GitHub OAuth handshake
โ”‚   โ”œโ”€โ”€ callback/index.go          # Handles OAuth code exchange
โ”‚   โ”œโ”€โ”€ result/index.go            # Serves public/private achievement reports
โ”‚   โ”œโ”€โ”€ private/index.go           # Processes direct PAT authentication
โ”‚   โ”œโ”€โ”€ stars/index.go             # Edge-cached repository stargazers proxy
โ”‚   โ””โ”€โ”€ markdown/index.go          # Generates dynamic markdown badge snippets
โ”œโ”€โ”€ cmd/
โ”‚   โ”œโ”€โ”€ gitverse/                  # Main terminal CLI entrypoint
โ”‚   โ”‚   โ””โ”€โ”€ main.go
โ”‚   โ””โ”€โ”€ gitverse-devserver/        # Local development HTTP server
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ internal/
โ”‚   โ”œโ”€โ”€ catalog/                   # Canonical achievement specifications
โ”‚   โ”‚   โ”œโ”€โ”€ achievements.go        # Definitions of all 15 badges and tiers
โ”‚   โ”‚   โ””โ”€โ”€ types.go               # Badge, Tier, and Status domain types
โ”‚   โ”œโ”€โ”€ engine/                    # Core calculation & reconciliation unit
โ”‚   โ”‚   โ”œโ”€โ”€ engine.go              # Evaluates badges against contribution events
โ”‚   โ”‚   โ””โ”€โ”€ deltas.go              # Computes exact next-tier gap metrics
โ”‚   โ”œโ”€โ”€ github/                    # GitHub communication layer
โ”‚   โ”‚   โ”œโ”€โ”€ client.go              # Resilient HTTP client with retry & backoff
โ”‚   โ”‚   โ”œโ”€โ”€ scraper.go             # High-precision HTML parser for badge modals
โ”‚   โ”‚   โ””โ”€โ”€ oauth.go               # OAuth 2.0 flow & ephemeral token management
โ”‚   โ””โ”€โ”€ webui/                     # Presentation layer
โ”‚       โ”œโ”€โ”€ templates/             # Embedded HTML5 templates
โ”‚       โ”œโ”€โ”€ renderer.go            # Go html/template execution
โ”‚       โ””โ”€โ”€ assets/                # Static CSS, SVG, and branding assets
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ gendocs/                   # Static page pre-rendering & drift checker
โ”œโ”€โ”€ site/                          # Prerendered static pages (Explore, About, Privacy)
โ”œโ”€โ”€ vercel.json                    # Vercel routing, rewrites, and headers
โ””โ”€โ”€ go.mod                         # Go module definition (Go 1.25+)

๐Ÿ”„ Core Request Lifecycles

1. Public Profile Analysis Lifecycle

sequenceDiagram
    participant User as Web/CLI User
    participant App as GitVerse Engine
    participant Scraper as internal/github Scraper
    participant GH as GitHub Web & API

    User->>App: Request analysis for username
    App->>Scraper: Fetch profile achievements HTML
    Scraper->>GH: GET https://github.com/username?tab=achievements
    GH-->>Scraper: HTML Response with badge tokens
    Scraper->>GH: GET https://github.com/users/username/achievements/{badge} (Detail Modal)
    GH-->>Scraper: HTML Response with unlock timestamps & tier milestones
    Scraper-->>App: Raw Achievement Records
    App->>App: Reconcile with internal/catalog rules
    App->>App: Calculate Next-Tier Deltas & Provenance
    App-->>User: Rendered Web Report or ANSI CLI Table
Loading

2. Ephemeral Private Repository Lifecycle

sequenceDiagram
    participant User as Developer
    participant App as GitVerse Serverless
    participant GH as GitHub OAuth / API

    User->>App: Initiate Private Scan (OAuth or PAT)
    App->>GH: Request repo-scoped token exchange
    GH-->>App: Ephemeral Access Token (In-Memory Only)
    App->>GH: Query GraphQL for private PRs, reviews & discussions
    GH-->>App: Private Contribution Milestones
    App->>App: Calculate Aggregated Achievements & Deltas
    App->>GH: POST /applications/{client_id}/grant (Revoke Token Immediately)
    GH-->>App: 204 Revocation Confirmed
    App-->>User: Rendered Private Achievement Report (Zero Token Retained)
Loading

โšก Caching, Rate Limiting & Resilience

  1. Exponential Backoff: internal/github implements jittered exponential backoff when encountering HTTP 429 (Too Many Requests) or secondary GitHub rate limits.
  2. Edge CDN Caching: Endpoints that serve aggregated or public metrics (such as /api/stars) set Cache-Control: s-maxage=60, stale-while-revalidate=120, offloading 99% of requests directly to Vercel's global edge network.
  3. Bot Token Fallback: If an unauthenticated user query triggers a GitHub rate limit, GitVerse can seamlessly fall back to an internal pooled GitHub App / Bot token (GH_BOT_TOKEN) to guarantee high availability for public queries.

Clone this wiki locally