Overview
GitHub Wrapped is built as a modern Next.js application that transforms GitHub repository data into beautiful, shareable year-in-review visualizations. The architecture follows a clear separation of concerns with distinct layers for data fetching, analytics processing, and presentation.High-Level Architecture
Data Flow
The application follows a streamlined data pipeline:User Input
Users enter a repository in format
owner/repo and select a year through the RepositoryInput component.Validation
The
/api/validate endpoint validates the repository exists and is public before proceeding.Cache Check
The system checks Redis (if configured) or in-memory cache for existing wrapped data to avoid redundant API calls.
GitHub API Fetching
If no cache exists,
GitHubService (lib/github.ts:11) makes parallel requests to GitHub’s REST API using Octokit to fetch:- Repository info, contributors, commits
- Languages, releases, issues, pull requests
- Stars, forks, and community metrics
Analytics Processing
AnalyticsEngine (lib/analytics.ts:24) processes raw GitHub data to calculate:- Commit statistics (by month, day, hour)
- Contributor rankings and activity
- Language distribution and trends
- Community growth metrics
- Monthly activity snapshots
Component Architecture
Frontend Components
Input Layer
RepositoryInput.tsx- Repository search and validationPeriodSelector.tsx- Year/period selection- Form validation and error handling
Presentation Layer
WrappedStory.tsx- Main story container and navigationWrappedSlide.tsx- Individual slide components (8-12 slides)UserWrappedStory.tsx/UserWrappedSlide.tsx- User-specific wrapped
UI Components
- Radix UI primitives for accessible components
- Custom styled components in
components/ui/ - Theme provider for dark/light mode
Layout Components
hero.tsx- Landing page hero sectiontheme-toggle.tsx- Theme switching- Root layout with metadata and providers
Backend Services
GitHub Service (lib/github.ts)
GitHub Service (lib/github.ts)
Responsibilities:
- Octokit client initialization with optional authentication
- Rate limit checking and management
- Repository validation and info retrieval
- Paginated data fetching for commits, contributors, issues, PRs
- User profile and repository queries
validateRepository()- Checks repo existence and accessibilitygetCommits()- Fetches commits with date filteringgetContributors()- Retrieves contributor statisticsgetLanguages()- Gets language breakdowngetUserRepos()- Fetches user’s repositories
Analytics Engine (lib/analytics.ts)
Analytics Engine (lib/analytics.ts)
Responsibilities:
- Transforms raw GitHub data into meaningful insights
- Calculates aggregated statistics and trends
- Identifies patterns in commit activity
- Ranks contributors and languages
- Generates monthly activity snapshots
generateWrapped()- Main entry point for repository wrappedgenerateUserWrapped()- Generates user-level wrapped datacalculateCommitStats()- Analyzes commit patternscalculateContributorStats()- Ranks top contributorsbuildMonthlySnapshots()- Creates time-series data
Cache Layer (lib/cache.ts)
Cache Layer (lib/cache.ts)
Responsibilities:
- Dual-layer caching: Redis (production) + in-memory (fallback)
- 24-hour TTL for wrapped data
- Validation result caching
- Automatic expiration and cleanup
- Uses Upstash Redis when configured
- Falls back to Map-based in-memory cache
- Type-safe cache entries with expiration tracking
API Route Organization
The application exposes several API endpoints through Next.js App Router:| Route | Purpose | Method |
|---|---|---|
/api/validate | Validate repository existence | POST |
/api/wrapped | Generate repository wrapped | POST |
/api/wrapped/user | Generate user wrapped | POST |
/api/summary | Get quick repository summary | POST |
/api/performance | Performance metrics endpoint | POST |
/api/og | Open Graph image generation | GET |
/api/auth/[...all] | Authentication endpoints (better-auth) | ALL |
/api/user/repos | Get authenticated user’s repos | GET |
Authentication Flow
GitHub Wrapped uses better-auth for authentication:- Users can optionally sign in with GitHub OAuth
- Authenticated requests use the user’s GitHub token for higher rate limits
- Session management handled by better-auth with PostgreSQL storage
- Auth state persisted across requests via secure cookies
Caching Strategy
Production (Redis)
- Upstash Redis for distributed caching
- Persistent across deployments
- Shared cache for all users
- 24-hour expiration
Development (In-Memory)
- Map-based in-memory cache
- Automatic fallback if Redis unavailable
- Per-process cache (not shared)
- Same 24-hour expiration
Type Safety
The entire application is built with TypeScript, with comprehensive type definitions intypes/index.ts:
WrappedData- Repository wrapped data structureUserWrappedData- User-level wrapped dataCommitStats- Commit analyticsContributor- Contributor informationLanguageStats- Language distributionMonthlySnapshot- Time-series activity data
Performance Optimizations
Pagination Limits
Request limits (typically 5-10 pages max) prevent rate limit exhaustion on large repositories.
Sampling for Expensive Operations
Line-by-line commit stats are sampled (max 20 commits) to balance detail with performance.
Deployment Architecture
The application is designed for deployment on Vercel:- Hosting: Vercel Edge Network
- Database: PostgreSQL (for auth sessions via Prisma)
- Cache: Upstash Redis (serverless Redis)
- CDN: Automatic static asset optimization
- Environment: Serverless functions for API routes
All API routes run as serverless functions, allowing automatic scaling and geographic distribution.