Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:

Node.js 18+

JavaScript runtime required for Next.js.Check version:
node --version
# Should output v18.x.x or higher

pnpm (recommended)

Fast, disk-efficient package manager.Install:
npm install -g pnpm
Or use npm/yarn if preferred.

Git

Version control system.Check version:
git --version

PostgreSQL (optional)

Required only if using authentication.Can use hosted services like Supabase or Neon.

Initial Setup

1

Clone the Repository

git clone https://github.com/yourusername/github-wrapped.git
cd github-wrapped
2

Install Dependencies

pnpm install
This installs all packages listed in package.json.
First install may take 2-3 minutes. Subsequent installs are cached and much faster.
3

Configure Environment Variables

Create a .env.local file in the project root:
touch .env.local
Add the following variables:
.env.local
# Optional: GitHub Personal Access Token
# Get one at: https://github.com/settings/tokens
# Increases rate limit from 60/hour to 5,000/hour
GITHUB_TOKEN=ghp_your_token_here

# Optional: Redis Cache (for production-like caching)
# Sign up at: https://upstash.com
UPSTASH_REDIS_REST_URL=https://your-redis.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_token_here

# Required for Authentication (optional feature)
# PostgreSQL connection string
DATABASE_URL=postgresql://user:password@localhost:5432/github_wrapped

# better-auth configuration
BETTER_AUTH_SECRET=your-random-secret-here
BETTER_AUTH_URL=http://localhost:3000

# GitHub OAuth App (for auth feature)
GITHUB_CLIENT_ID=your_client_id
GITHUB_CLIENT_SECRET=your_client_secret
Only GITHUB_TOKEN is recommended for development. Other variables are optional.
4

Set Up Database (if using auth)

If you’re using authentication features:
# Generate Prisma client
pnpm prisma generate

# Run database migrations
pnpm prisma migrate dev
Skip this step if you’re not working on auth features.
5

Start Development Server

pnpm dev
This starts the Next.js development server on http://localhost:3000.
▲ Next.js 16.0.7
- Local:        http://localhost:3000
- Environments: .env.local

✓ Ready in 2.3s

Available Scripts

The project includes several npm scripts defined in package.json:
# Start development server with hot reload
pnpm dev

# Runs on http://localhost:3000
# Auto-reloads on file changes

Development Workflow

Hot Reload

Next.js provides automatic hot reload for:
  • React components - Instant updates without losing state
  • API routes - Automatic restart on changes
  • Styles - Live CSS updates
  • TypeScript - Type checking in background
If hot reload stops working, restart the dev server with Ctrl+C then pnpm dev.

File Watching

The dev server watches these directories:
  • app/ - Pages and API routes
  • components/ - React components
  • lib/ - Business logic
  • types/ - Type definitions
  • public/ - Static assets

TypeScript Integration

TypeScript errors appear in:
  1. Terminal - Real-time type checking
  2. Browser - Overlay with error details
  3. IDE - Inline errors (VS Code, etc.)
# Manual type check
npx tsc --noEmit

Debugging Tips

Browser DevTools

Install React DevTools browser extension.Features:
  • Inspect component tree
  • View props and state
  • Track re-renders
  • Profile performance
Monitor API requests:
  1. Open DevTools (F12)
  2. Go to Network tab
  3. Filter by “Fetch/XHR”
  4. Inspect API calls to /api/wrapped, /api/validate, etc.
Look for:
  • Response times
  • Status codes
  • Request/response payloads
  • Rate limit headers
Use strategic console logs:
// Client components
console.log('User input:', { owner, repo, year })

// API routes
console.log('Fetching wrapped data for:', owner, repo)

// Services
console.log('GitHub API response:', data)
Remove console.logs before committing to production!
Add .vscode/launch.json:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "pnpm dev"
    },
    {
      "name": "Next.js: debug client-side",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000"
    }
  ]
}
Then press F5 to start debugging with breakpoints.

Common Issues

Error:
Error: listen EADDRINUSE: address already in use :::3000
Solutions:
# Option 1: Kill process on port 3000
# macOS/Linux
lsof -ti:3000 | xargs kill -9

# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F

# Option 2: Use different port
pnpm dev -- -p 3001
Error:
Type error: Cannot find module '@/types'
Solution:
# Reinstall dependencies
rm -rf node_modules .next
pnpm install

# Restart dev server
pnpm dev
Error:
{ "error": "API rate limit exceeded" }
Solutions:
  1. Add GITHUB_TOKEN to .env.local
  2. Wait for rate limit reset (check headers)
  3. Use cache to avoid repeated requests
Check remaining requests:
curl -H "Authorization: token YOUR_TOKEN" \
  https://api.github.com/rate_limit
Error:
Error connecting to Redis
Solution:The app automatically falls back to in-memory cache. This is expected in development.To use Redis in development:
  1. Sign up for Upstash Redis
  2. Create a database
  3. Add credentials to .env.local
Error:
Module not found: Can't resolve '@/components/Button'
Solution:
# Clear Next.js cache
rm -rf .next

# Restart dev server
pnpm dev

Testing Features Locally

Test Repository Input

  1. Go to http://localhost:3000
  2. Enter a repository (e.g., facebook/react)
  3. Select year (e.g., 2024)
  4. Click “Generate Wrapped”

Test API Endpoints

Use curl or Postman to test API routes:
# Validate repository
curl -X POST http://localhost:3000/api/validate \
  -H "Content-Type: application/json" \
  -d '{"owner":"facebook","repo":"react"}'

# Generate wrapped
curl -X POST http://localhost:3000/api/wrapped \
  -H "Content-Type: application/json" \
  -d '{"owner":"facebook","repo":"react","year":2024}'

Test Dark Mode

  1. Click the theme toggle in the navbar
  2. Verify all components render correctly
  3. Check localStorage: localStorage.getItem('theme')

Test Mobile Responsiveness

  1. Open DevTools (F12)
  2. Click device toolbar (Ctrl+Shift+M)
  3. Test different screen sizes:
    • Mobile: 375px (iPhone)
    • Tablet: 768px (iPad)
    • Desktop: 1920px

Performance Profiling

Next.js Build Analysis

# Analyze bundle size
pnpm build

# Output shows page sizes:
# ┌ ○ /               1.2 kB
# ├ ○ /wrapped/[...] 2.5 kB
# └ λ /api/wrapped   0 B

React Profiler

  1. Install React DevTools
  2. Open Profiler tab
  3. Click “Record”
  4. Interact with the app
  5. Stop recording
  6. Analyze render times

Environment-Specific Configuration

Development Mode

Development mode includes:
  • Hot reload
  • Detailed error messages
  • Unminified code
  • Source maps
  • Rate limit bypass (in lib/github.ts:23)

Production Mode

Production builds include:
  • Minified code
  • Optimized images
  • Static generation
  • Tree shaking
  • Code splitting

Next Steps

Project Structure

Learn about the codebase organization

Architecture

Understand the system design

Contributing

Start contributing to the project

API Reference

Explore API endpoints
Join our Discord community for real-time help with development!

Build docs developers (and LLMs) love