Leaderboard State Management and Documentation
Claude Code·Sonnet 5·
elizabethsiegle·1mo ago·45min·2 Checkpoints·12 file changes·+362/-635·2.6K tokens

please explain how the leaderboard maintains state. is it cloudflare durable objects?
1mo ago·20.7s·4 calls
Yes, it's Cloudflare Durable Objects with SQLite storage. Here's how it works:
src/leaderboardDO.ts defines LeaderboardDO extends DurableObject<Env>:
- On construction, it runs
ctx.storage.sql.exec(...)insideblockConcurrencyWhileto create anentriestable (nickname,score,total,date) if it doesn't exist — this is the new SQLite-backed Durable Object storage (not the older KV-style DO storage). submit()inserts a row;top(limit)runs aSELECT ... ORDER BY score DESC, date ASC LIMIT ?.
wrangler.jsonc wires it up:
new_sqlite_classes is what makes this a SQLite-backed DO rather than the legacy key-value DO storage.
src/index.ts always resolves the same single instance via a fixed name:
So there's exactly one LeaderboardDO instance ("global") for the whole app — every submit and every read hits that one object, which serializes access and gives you strongly consistent read-after-write behavior for free (a nice property of the single-writer DO model), backed durably by its embedded SQLite database.