GitHub Contribution Graph Widget
Goal
Add a GitHub-style contribution graph at the top of the projects section, showing private contribution data pulled from the GitHub API with server-side caching.
Backend
New endpoint: GET /github/contributions
File: backend/routers/github.py
- Queries GitHub GraphQL API with PAT (
GITHUB_TOKENenv var) - Query fetches
contributionsCollection.contributionCalendarfor userghostmonk - Returns:
totalContributions, array of weeks containingcontributionDays(date, count, level) - Cache: store response in
github_cacheMongoDB collection withfetched_attimestamp - Cache TTL: 1 hour — if cached data is fresh, return it without hitting GitHub
- No auth required on endpoint (public display data)
- Returns 503 if
GITHUB_TOKENnot configured - Register router in
backend/app.py
GraphQL Query
query {
user(login: "ghostmonk") {
contributionsCollection {
contributionCalendar {
totalContributions
weeks {
contributionDays {
date
contributionCount
contributionLevel
}
}
}
}
}
}contributionLevel values: NONE, FIRST_QUARTILE, SECOND_QUARTILE, THIRD_QUARTILE, FOURTH_QUARTILE.
Frontend
Component: ContributionGraph
File: frontend/src/modules/projects/components/ContributionGraph.tsx
Layout:
- Header: “{N} contributions in the last year” (left), profile link (right)
- Grid: 53 columns x 7 rows, each cell a colored square
- Month labels across top
- Day labels (Mon, Wed, Fri) on left side
- “Less / More” legend at bottom right with 5 color swatches
- Entire widget links to
https://github.com/ghostmonk
States:
- Loading: shimmer/skeleton placeholder
- Error/no data: widget does not render
- Success: full graph
Placement
In [...slugPath].tsx, between <h1> and <SectionListView>, conditionally rendered when section.content_type === 'project'.
Styling
Color tokens in template CSS for 5 contribution levels, with dark mode variants matching GitHub’s green scale. Component styles use template token system.
Environment
- New env var:
GITHUB_TOKEN(backend only, GitHub PAT with private contribution visibility) - Add to
.env.exampledocumentation
Implementation Steps
- Create
backend/routers/github.pywith endpoint, GitHub GraphQL fetch, and MongoDB caching - Register router in
backend/app.py - Add contribution level color tokens to template CSS (
tokens.css) - Create
ContributionGraphcomponent with grid rendering and data fetching - Add component CSS to template
components.css - Wire component into
[...slugPath].tsxfor project sections - Add
GITHUB_TOKENto.envand docker-compose