Inspiration

Open source already feels like a team sport. We asked: what if we turned that momentum into a weekly, social game right inside Reddit? Code Derby lets people “draft” three GitHub repos and compete on a live leaderboard—no install, just a Reddit post.

What it does

  • Pick 3 GitHub repositories (owner/repo).
  • Each week, activity turns into points: Releases (+8), Merged PRs (+5), Closed Issues (+2), Star Δ (+1, cap 20/repo), NPM Δ/5k (+1).
  • A live leaderboard updates during the week (UTC Monday–Sunday).
  • Health panel surfaces server status (mock/real mode, current week, entry count).

How we built it

  • Devvit Web hosts the app as a WebView inside a subreddit post.
  • Frontend: React + TypeScript with a dark, tech-style theme (tabs + glass UI).
  • Server: Express on Devvit Web Server; routes for /api/leaderboard, /api/roster/submit, /api/health, and a diagnostic /api/gh/stars.
  • Storage: Devvit Redis for weekly entries and scoring caches.
    • code-derby:entries:<week> (hash; field=user) stores a user’s 3 repos & score.
    • code-derby:star-baseline:<week> holds weekly star baselines.
    • code-derby:star-now:<repo> caches current stars for 5 minutes.
  • Scoring modes:
    • Mock (default) – deterministic, reproducible scores so the app works even while external allowlist is pending.
    • Real – GitHub + npm APIs, with weekly baselines and short-lived HTTP caches.
  • UX details: optimistic submit → toast → auto-switch to Leaderboard; week range computed in UTC; no-store on leaderboard responses to avoid stale caching.

Challenges

  • Allowlist timing: external domains (GitHub/npm) may be pending. We implemented a Mock Scoring mode so the gameplay and UX are still fully reviewable.
  • Weekly windows: normalizing week boundaries globally (UTC Mon–Sun) and persisting metadata so refreshes never show “Invalid Date”.
  • Reddit context: resolving usernames reliably from headers and failing gracefully when context is missing.

Accomplishments we’re proud of

  • A polished, mobile-first WebView experience with clear information hierarchy.
  • Reliable data flow: draft → persist → leaderboard refresh without stale states.
  • Health diagnostics that make judging easy (one glance to see mode and counts).
  • Open source

What we learned

  • How to combine Devvit Web with a custom Express server and Redis for stateful mini-apps inside Reddit.
  • Designing for partial connectivity (mock-first), then upgrading to real data sources.
  • Small UI touches like per-tab fetch, UTC wording, and subtle animations.

What’s next

  • Enable Real Scoring when allowlist is approved (GitHub + npm).
  • Add more metrics (issues opened, commit volume, release cadence multipliers).
  • Community leagues per subreddit, weekly recap posts, and “draft locks” automation.
  • Public season standings and simple anti-gaming heuristics.

Try it

1) Open the demo Reddit post.
2) Go to Draft, enter three owner/repo, submit.
3) Switch to Leaderboard to watch points update (and see the UTC week range).
4) Check About for rules and server status.

Share this project:

Updates