# jarryuser/github-visualizer architecture

> Architecture diagram of the GitHub repository jarryuser/github-visualizer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jarryuser/github-visualizer
- Repository: https://github.com/jarryuser/github-visualizer

## Overview

1. **System shape**
   - This is a client-side TypeScript dashboard hosted on **GitHub Pages**, with a small **Cloudflare Worker** acting as the only server-side component.
   - The browser app renders GitHub profile analytics; the Worker protects the GitHub token and caches API responses.

2. **Front-end shell**
   - `index.html` is the only HTML entry point; there is no UI framework.
   - `src/main.ts` is the orchestrator: it reads URL state, switches between tabs/views, triggers profile loading, and coordinates rendering.

3. **UI state and routing**
   - The app is URL-driven via query parameters such as `?user=...`, `?tab=compare&a=...&b=...`, and `?embed=1`.
   - This makes profile views shareable and allows the same codebase to serve the main dashboard, comparison mode, and the compact embed card.

4. **Data access boundary**
   - `src/api.ts` is the browser’s single gateway for GitHub data.
   - It sends requests to the Worker proxy instead of calling `api.github.com` directly, so the browser bundle never contains secrets.

5. **Cloudflare Worker proxy**
   - `worker/index.ts` is the server-side boundary.
   - It enforces a small allowlist of GitHub routes, attaches the `GITHUB_TOKEN` secret, and returns only the proxied responses needed by the app.

6. **Caching and freshness**
   - The Worker uses **Workers KV** as an edge cache.
   - Different endpoints have different TTLs: profile and repo metadata are cached for minutes, language stats longer, and `/rate_limit` very briefly so the header badge stays current.
   - `?fresh=1` bypasses cache for a one-off refresh.

7. **Profile data flow**
   - On profile load, the app fetches core profile data and repositories in parallel, then fans out to repo-language endpoints, contribution data, and recent events.
   - The README describes this as a `Promise.all`-heavy pipeline to keep load times low and to render most widgets once the main profile payload arrives.

8. **Visualization subsystem**
   - The main charts are split into focused modules:
     - `streak.ts` for contribution heatmap and streak counters
     - `commitHeatmap.ts` for the 7×24 coding-hours grid
     - `languages.ts` for the animated language breakdown
     - `activityChart.ts` for weekly activity trend
   - These modules use **D3.js** for SVG rendering and theme-aware colors.

9. **Profile content modules**
   - `repos.ts` renders top repositories and their metadata.
   - `healthScore.ts` computes and displays repository health indicators such as description, license, activity, and topics.
   - `profileReadme.ts` fetches and renders `{username}/{username}/README.md` when present.
   - `embed.ts` builds the compact iframe-friendly profile card.

10. **Comparison mode**
   - `compare.ts` handles the side-by-side profile view.
   - It compares stats, language overlap, and heatmaps, using the same underlying API layer but a different presentation boundary.

11. **Cross-cutting presentation**
   - `styles/main.css` defines the visual system, including GitHub-dark/light styling and layout for all tabs and cards.
   - Theme selection is persistent in browser storage and influences chart rendering as well as page styling.

12. **External services**
   - Primary data source: **GitHub REST API v3**.
   - Contribution history comes from `github-contributions-api` because GitHub’s native heatmap data is GraphQL-based.
   - Deployment is split: front-end to **GitHub Pages**, Worker to **Cloudflare Workers** with KV.

13. **Build and runtime boundaries**
   - The front-end is built with **Vite** and TypeScript; `tsconfig.json` covers `src/`.
   - The Worker has its own TypeScript config and runtime config (`tsconfig.worker.json`, `wrangler.toml`), which cleanly separates browser code from edge code.

14. **Important architectural constraint**
   - The browser never receives the GitHub token.
   - All sensitive API access, quota handling, and caching are centralized in the Worker, which is the key security and performance boundary of the system.

Main entry points: [`src/main.ts`](https://github.com/jarryuser/github-visualizer/blob/main/src/main.ts) (Main app), [`worker/index.ts`](https://github.com/jarryuser/github-visualizer/blob/main/worker/index.ts) (Worker proxy), [`src/api.ts`](https://github.com/jarryuser/github-visualizer/blob/main/src/api.ts) (API gateway), [`index.html`](https://github.com/jarryuser/github-visualizer/blob/main/index.html) (index.html)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser app"]
  node_index_html["index.html<br/>entry shell<br/>[index.html]"]
  node_main_ts["Main app<br/>orchestrator<br/>[main.ts]"]
  node_api_ts["API gateway<br/>client api<br/>[api.ts]"]
  node_compare_ts["Compare view<br/>[compare.ts]"]
  node_embed_ts["Embed card<br/>view<br/>[embed.ts]"]
  node_profile_readme_ts["Profile README<br/>content fetcher<br/>[profileReadme.ts]"]
  node_styles_css["Main styles<br/>theme system<br/>[main.css]"]
end

subgraph group_visuals["Presentation modules"]
  node_repos_ts["Repos panel<br/>content view<br/>[repos.ts]"]
  node_health_score_ts["Health score<br/>analysis view<br/>[healthScore.ts]"]
  node_streak_ts["Streaks<br/>chart module<br/>[streak.ts]"]
  node_commit_heatmap_ts["Commit grid<br/>chart module<br/>[commitHeatmap.ts]"]
  node_languages_ts["Languages<br/>chart module<br/>[languages.ts]"]
  node_activity_chart_ts["Activity trend<br/>chart module<br/>[activityChart.ts]"]
end

subgraph group_edge["Cloudflare edge"]
  node_worker_index_ts["Worker proxy<br/>edge proxy<br/>[index.ts]"]
end

subgraph group_ops["Build and deploy"]
  node_vite_config["Vite config<br/>build config<br/>[vite.config.ts]"]
  node_worker_tsconfig["Worker config<br/>runtime config"]
  node_wrangler_toml["Wrangler config<br/>deploy config<br/>[wrangler.toml]"]
end

node_index_html -->|"boots app"| node_main_ts
node_main_ts -->|"loads data"| node_api_ts
node_main_ts -->|"compare mode"| node_compare_ts
node_main_ts -->|"embed mode"| node_embed_ts
node_main_ts -->|"renders repos"| node_repos_ts
node_main_ts -->|"renders health"| node_health_score_ts
node_main_ts -->|"renders streaks"| node_streak_ts
node_main_ts -->|"renders grid"| node_commit_heatmap_ts
node_main_ts -->|"renders langs"| node_languages_ts
node_main_ts -->|"renders trend"| node_activity_chart_ts
node_main_ts -->|"loads README"| node_profile_readme_ts
node_main_ts -->|"applies theme"| node_styles_css
node_api_ts -->|"proxy calls"| node_worker_index_ts
node_worker_index_ts -->|"returns data"| node_api_ts
node_worker_index_ts -->|"deploys with"| node_wrangler_toml
node_vite_config -->|"builds"| node_main_ts
node_worker_tsconfig -->|"types"| node_worker_index_ts

click node_index_html "https://github.com/jarryuser/github-visualizer/blob/main/index.html"
click node_main_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/main.ts"
click node_api_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/api.ts"
click node_compare_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/compare.ts"
click node_embed_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/embed.ts"
click node_profile_readme_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/profileReadme.ts"
click node_repos_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/repos.ts"
click node_health_score_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/healthScore.ts"
click node_streak_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/streak.ts"
click node_commit_heatmap_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/commitHeatmap.ts"
click node_languages_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/languages.ts"
click node_activity_chart_ts "https://github.com/jarryuser/github-visualizer/blob/main/src/activityChart.ts"
click node_worker_index_ts "https://github.com/jarryuser/github-visualizer/blob/main/worker/index.ts"
click node_styles_css "https://github.com/jarryuser/github-visualizer/blob/main/styles/main.css"
click node_vite_config "https://github.com/jarryuser/github-visualizer/blob/main/vite.config.ts"
click node_worker_tsconfig "https://github.com/jarryuser/github-visualizer/blob/main/tsconfig.worker.json"
click node_wrangler_toml "https://github.com/jarryuser/github-visualizer/blob/main/wrangler.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_index_html,node_main_ts,node_api_ts,node_compare_ts,node_embed_ts,node_profile_readme_ts,node_styles_css toneBlue
class node_repos_ts,node_health_score_ts,node_streak_ts,node_commit_heatmap_ts,node_languages_ts,node_activity_chart_ts toneAmber
class node_worker_index_ts toneMint
class node_vite_config,node_worker_tsconfig,node_wrangler_toml toneRose
```

## Components

### Browser app

Client-side TypeScript dashboard rendered from a single HTML entry point.

- [index.html](https://github.com/jarryuser/github-visualizer/blob/main/index.html): entry shell · Single HTML entry point for the browser app. · `index.html`
- [Main app](https://github.com/jarryuser/github-visualizer/blob/main/src/main.ts): orchestrator · Reads URL state, switches tabs and views, and coordinates profile loading and rendering. · `src/main.ts`
- [API gateway](https://github.com/jarryuser/github-visualizer/blob/main/src/api.ts): client api · Browser-side gateway for GitHub data; sends requests through the Worker proxy. · `src/api.ts`
- [Compare view](https://github.com/jarryuser/github-visualizer/blob/main/src/compare.ts): view · Side-by-side profile comparison mode and shared stats. · `src/compare.ts`
- [Embed card](https://github.com/jarryuser/github-visualizer/blob/main/src/embed.ts): view · Compact iframe-friendly profile card. · `src/embed.ts`
- [Profile README](https://github.com/jarryuser/github-visualizer/blob/main/src/profileReadme.ts): content fetcher · Fetches and renders a user's repository README when present. · `src/profileReadme.ts`
- [Main styles](https://github.com/jarryuser/github-visualizer/blob/main/styles/main.css): theme system · Global visual system, layout, and GitHub-dark/light styling. · `styles/main.css`

### Presentation modules

Focused view and chart modules used by the dashboard.

- [Repos panel](https://github.com/jarryuser/github-visualizer/blob/main/src/repos.ts): content view · Renders top repositories and their metadata. · `src/repos.ts`
- [Health score](https://github.com/jarryuser/github-visualizer/blob/main/src/healthScore.ts): analysis view · Computes repository health indicators such as description, license, activity, and topics. · `src/healthScore.ts`
- [Streaks](https://github.com/jarryuser/github-visualizer/blob/main/src/streak.ts): chart module · Contribution heatmap and streak counters. · `src/streak.ts`
- [Commit grid](https://github.com/jarryuser/github-visualizer/blob/main/src/commitHeatmap.ts): chart module · 7×24 coding-hours heatmap. · `src/commitHeatmap.ts`
- [Languages](https://github.com/jarryuser/github-visualizer/blob/main/src/languages.ts): chart module · Animated language breakdown visualization. · `src/languages.ts`
- [Activity trend](https://github.com/jarryuser/github-visualizer/blob/main/src/activityChart.ts): chart module · Weekly activity trend chart. · `src/activityChart.ts`

### Cloudflare edge

Worker boundary that proxies GitHub data and caches responses.

- [Worker proxy](https://github.com/jarryuser/github-visualizer/blob/main/worker/index.ts): edge proxy · Cloudflare Worker that allowlists GitHub routes, attaches the token, and returns proxied responses. · `worker/index.ts`

### Build and deploy

Tooling and deployment configuration for browser and worker runtimes.

- [Vite config](https://github.com/jarryuser/github-visualizer/blob/main/vite.config.ts): build config · Browser build configuration for the TypeScript front end. · `vite.config.ts`
- [Worker config](https://github.com/jarryuser/github-visualizer/blob/main/tsconfig.worker.json): runtime config · TypeScript configuration for the edge runtime. · `tsconfig.worker.json`
- [Wrangler config](https://github.com/jarryuser/github-visualizer/blob/main/wrangler.toml): deploy config · Cloudflare Worker deployment and runtime configuration. · `wrangler.toml`

## Connections

- index.html → Main app: boots app · The HTML entry point loads the orchestrator script.
- Main app → API gateway: loads data · Main app delegates all GitHub fetching to the API gateway.
- Main app → Compare view: compare mode · URL state can switch the app into side-by-side comparison.
- Main app → Embed card: embed mode · URL state can switch the app into compact embed rendering.
- Main app → Repos panel: renders repos · The orchestrator feeds profile repository data into the repos panel.
- Main app → Health score: renders health · Repository metadata is summarized in the health score view.
- Main app → Streaks: renders streaks · Contribution history is visualized in the streak module.
- Main app → Commit grid: renders grid · The coding-hours grid is drawn as part of profile analytics.
- Main app → Languages: renders langs · Language data is passed to the animated breakdown chart.
- Main app → Activity trend: renders trend · Weekly activity data drives the trend chart.
- Main app → Profile README: loads README · The app fetches a profile README when available.
- Main app → Main styles: applies theme · Theme state influences page styling and chart presentation.
- API gateway → Worker proxy: proxy calls · Browser requests go through the Cloudflare Worker instead of GitHub directly.
- Worker proxy → API gateway: returns data · The Worker returns proxied GitHub responses to the browser.
- Worker proxy → Wrangler config: deploys with · Wrangler config defines how the Worker is deployed and run.
- Vite config → Main app: builds · Vite bundles the browser TypeScript application.
- Worker config → Worker proxy: types · Worker-specific TypeScript config covers the edge runtime.
