Skip to content

bolin8017/caffecode

CaffeCode
每天一杯咖啡配一道題,把刷題變成習慣,輕鬆備好技術面試。

CI Website License

Website · Telegram Bot · LINE Bot · Getting Started · Contributing


A daily LeetCode problem delivery platform with AI-generated C++ explanations in Traditional Chinese. Browse curated problem lists on the web, connect Telegram / LINE / Email, and receive a personalized problem every day at your preferred time.

Features

  • 45 curated lists — Blind 75, NeetCode 150, NeetCode All, Grind 75, company lists (FAANG, Google, Meta, Amazon, Apple, Bloomberg, Microsoft), topic & algorithm lists
  • 810+ problems with AI-generated content — explanation, C++ solution, complexity analysis, pseudocode, alternative approaches, follow-up questions
  • Automated metadata syncsync_leetcode.py fetches all ~3100 free LeetCode problems via GraphQL API + contest ratings
  • Zero runtime LLM calls — all content pre-generated offline via Claude Sonnet
  • 3 notification channels — Telegram, LINE, Email; connect any combination
  • 2 delivery modes — follow a list sequentially, or filter by difficulty rating + topic
  • Per-user push hour — configurable delivery time in your local timezone
  • Feedback & calibration — rate difficulty & content quality; system suggests optimal difficulty range
  • Solve tracking — mark problems as solved from web or Telegram inline button
  • Coffee Garden/garden gamification page: each LeetCode topic maps to a coffee variety with uncapped leveling system (Lv. 0–4 stages, then +1 per 5 solves). Auto-awarded badges for milestones, streaks, skill mastery, and variety
  • Streak tracking — timezone-aware daily solve streak on dashboard
  • Admin monitoring — health dashboard, worker run history, per-channel test/reset
  • SEO-optimized — structured data (JSON-LD), dynamic OG images, canonical URLs, web manifest, and dynamic sitemap

Architecture

                  ┌──────────────────────────┐
                  │   Supabase (PostgreSQL)  │
                  │   Auth · RLS · RPC       │
                  │   pg_cron · pg_net       │
                  └───────────┬──────────────┘
                              │
                   hourly HTTP POST
                   (Bearer CRON_SECRET)
                              │
                  ┌───────────┴──────────────┐
                  │   Next.js 16 (Vercel)    │
                  │                          │
                  │  Public pages (SEO)      │
                  │  OAuth (GitHub/Google)   │
                  │  Dashboard/Settings      │
                  │  Admin monitoring        │
                  │  /api/cron/push          │ ← pg_cron target
                  │  /api/{telegram,line}/webhook
                  └───────────┬──────────────┘
                              │
                   ┌──────────┴──────────┐
                   │  packages/shared    │
                   │                     │
                   │  Push pipeline      │
                   │  Channel senders    │
                   │  Problem selection  │
                   │  Notification fmt   │
                   └─────────────────────┘

One Next.js deployment on Vercel hosts both the site and the hourly cron endpoint. packages/shared provides the push pipeline, channel senders, problem selection, and formatters.

Tech Stack

Layer Technology
Frontend Next.js 16 (App Router), React 19, TypeScript, Tailwind CSS v4
Auth Supabase Auth (GitHub + Google OAuth)
Database Supabase PostgreSQL — RLS, RPC functions, service_role access
Cron Supabase pg_cron + pg_net/api/cron/push (hourly)
Notifications Telegram Bot API, LINE Messaging API, Resend (React Email)
Shared @caffecode/shared — push pipeline, channel senders, problem selection, formatters
Monorepo pnpm workspaces + Turborepo
Observability Sentry (errors), PostHog (analytics), Pino (structured logging)
Security CSP headers, Zod validation, webhook HMAC verification, timingSafeEqual auth
Testing Vitest (757 TS) + Playwright E2E (57) + pytest (54 Python)
CI/CD GitHub Actions, Vercel

Project Structure

apps/
  web/              Next.js 16 — public pages, auth, dashboard, settings, admin, cron route
packages/
  shared/           Push pipeline, channel senders, problem selection, formatters
supabase/
  config.toml       Supabase CLI configuration
  migrations/       Versioned SQL migrations (applied via Supabase CLI or MCP)
docs/
  supabase-schema.sql   Full schema reference
  staging-setup.md      Staging environment guide
  content-spec.md       Content generation specification
scripts/
  sync_leetcode.py      Fetch LeetCode metadata into data/problems/ (GraphQL + ratings)
  build_database.py     Data importer for lists and problems (skips metadata-only)
  generate_topic_lists.py  Assign orphan problems to topic-based curated lists
  ipv4-only.cjs         Forces IPv4 for local dev on WSL2

Getting Started

Prerequisites

  • Node.js 22+ (CI and Vercel use Node 24 LTS; .nvmrc is pinned to 24)
  • pnpm 10+ (repo uses packageManager: "pnpm@10.33.0"; enable via corepack enable)
  • A Supabase project

Installation

git clone https://github.com/bolin8017/caffecode.git
cd caffecode
pnpm install

Environment Variables

Copy and fill in the env file:

cp apps/web/.env.example apps/web/.env.local

See apps/web/.env.example for required variables. SUPABASE_SERVICE_ROLE_KEY must be the service_role key — anon is denied by RLS.

Database Setup

  1. Create a Supabase project.
  2. Run docs/supabase-schema.sql in the SQL editor to create all tables, indexes, RLS policies, and RPC functions.
  3. Apply migrations from supabase/migrations/ if needed.
  4. Sync LeetCode problem metadata and import content:
# Fetch all problem metadata (titles, difficulty, ratings, topics)
python3 scripts/sync_leetcode.py                   # full sync (~3100 free problems)
python3 scripts/sync_leetcode.py --dry-run         # preview without writing
python3 scripts/sync_leetcode.py --ids 1,42,200    # sync specific problems only

# Import problems WITH content into Supabase (metadata-only files are skipped)
python3 scripts/build_database.py --list blind75   # single list
python3 scripts/build_database.py --list all       # all lists

Development

pnpm build          # shared → web (Turborepo manages order)
pnpm dev            # start web dev server on localhost:3000

WSL2 note: Dev scripts preload scripts/ipv4-only.cjs to force IPv4 DNS resolution. WSL2 lacks IPv6, and Node.js fetch tries IPv6 first (Happy Eyeballs), causing external API calls to fail. Production is unaffected.

Running Tests

# All TypeScript tests via Turborepo
pnpm test

# Individually
cd packages/shared && pnpm exec vitest run   # 186 tests
cd apps/web && pnpm exec vitest run          # 571 tests

# E2E tests (requires dev server running)
cd apps/web && pnpm exec playwright test     # 57 tests

# Python tests (sync script)
cd scripts && python3 -m pytest tests/ -v    # 54 tests

Deployment

Target Platform Method Config
Web Vercel git push origin main GitHub integration
Cron trigger Supabase pg_cron pg_net HTTP POST hourly to /api/cron/push Vault secret + CRON_SECRET

Set environment variables from each .env.example in the respective platform dashboard.

Contributing

Contributions are welcome! Please read the Contributing Guide before submitting a pull request.

License

AGPL-3.0

About

Daily LeetCode push to Email, Telegram & LINE — one coffee, one problem.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors