System Components
The architecture consists of three main components:1. GitHub Actions (Data Collection)
A scheduled workflow fetches contribution data from GitHub’s GraphQL API and WhatPulse statistics, storing them as JSON files that are deployed with the Worker. Key Script:scripts/stats.ts
2. Cloudflare Workers (Request Handling)
The Worker serves as an edge function that processes HTTP requests and returns dynamically generated SVG images. Entry Point:src/worker.ts
3. GitHub GraphQL API
Provides contribution data including:- Total contributions count
- Daily contribution levels (NONE, FIRST_QUARTILE, SECOND_QUARTILE, THIRD_QUARTILE, FOURTH_QUARTILE)
- Contribution dates and calendar weeks
Data Flow
File Structure
File Responsibilities
| File | Purpose |
|---|---|
worker.ts | Routes requests, parses query parameters, loads data, orchestrates rendering |
render.ts | Contains all SVG generation logic, styles, and HTML templates |
stats.ts | Fetches and transforms data from GitHub and WhatPulse APIs |
stats.json | Static snapshot of contribution data (regenerated on deploy) |
Request Lifecycle
- Request Received: Worker receives HTTP request at edge location
- Parameter Parsing: Extract
theme(light/dark) andsection(top/main/link/fallback) - Data Loading: Import pre-generated
stats.jsoncontaining contribution history - Location Detection: Extract visitor location from Cloudflare request object
- Layout Calculation: Compute SVG dimensions based on data and responsive breakpoints
- Rendering: Generate SVG with CSS-in-JS styles and HTML content
- Response: Return SVG with appropriate headers and cache directives
Configuration
The system uses query parameters for runtime configuration:?theme=light|dark- Color scheme selection?section=top|link-*|fallback- Component selection?i=<number>- Animation index for link components
The Worker uses
no-cache headers to ensure GitHub always displays the latest version, even though the underlying data only updates when deployed.Deployment Strategy
The application follows a two-phase deployment:- Build Phase: Run
pnpm statsto fetch latest data - Deploy Phase: Bundle Worker code and stats.json to Cloudflare’s edge network