updated 2026-11-26·5 min read
Platform Architecture
How Flynn runs exams locally without lag, authenticates sessions, keeps timers honest, and generates deterministic seeds.
When a number-series subtest gives you 25 seconds per item, waiting 120ms to 450ms for an API roundtrip every time you click “Next” ruins pacing fast. I kept clicks instant by running the entire exam runner locally in the browser while handing auth, telemetry beacons, and final grading to Cloudflare Pages Functions and Turso, so flaky school Wi-Fi doesn’t eat your timer. See Getting Started for user modes and Database & Empirical Evaluation for the Turso schema.
Stack Overview
| Layer | Stack | What It Does | Fail-Safe |
|---|---|---|---|
| UI | React 19 + Tailwind CSS v4 | Single-shell views, 100dvh exam lock | Local client state |
| Simulation | TypeScript | Procedural AIG, cubes, figure SVGs | Deterministic math |
| Edge Auth | Cloudflare Pages Functions + Better Auth | OAuth/guest sessions, 4h JWTs, JWKS cache | Guest UUID fallback |
| Telemetry | navigator.sendBeacon + fetch keepalive | Answer choices, render-to-click dwell times | Non-blocking fallback |
| Database | Turso (libSQL) | User profiles, item banks, session results | LocalStorage fallback |
Auth vs. Session Grading
Auth (/api/auth/*)
Handles Google and GitHub OAuth 2.0 PKCE login, anonymous guest linking, and 4-hour JWT minting via Better Auth.
Session Grading (/api/v1/sessions/*)
Handles session creation, telemetry logging, and deterministic server-side grading on Turso.
Short-lived 15-minute tokens don’t survive a 195-minute UTBK-SNBT simulation or an 86-minute I-S-T 2000R battery. Because of that, auth.ts configures Better Auth’s jwt() plugin with a 4-hour expiration (240 minutes), and _authGuard.ts caches the JWKS endpoint via jose (createRemoteJWKSet) in edge memory to verify bearer tokens when starting a session.
- Start session and derive master seed
POST /api/v1/sessions/start creates a test_sessions row, generates a 32-bit master_seed, runs Attempt 2+ procedural overlays, and strips correct_option_id.
- Simulate locally at zero latency
The client renders prompts, SVG geometry, and an isolated UTC-anchored countdown leaf without waiting on network roundtrips.
- Stream non-blocking telemetry beacons
Answer selections send dwell_time_ms and pointer signals via navigator.sendBeacon (or keepalive fetch) to /api/v1/sessions/telemetry.
- Re-simulate and grade on completion
POST /api/v1/sessions/finish replays the procedural overlay and option shuffle from master_seed on the server and stores final scores.
Focus Mode and Background-Safe Timers
When you enter Take Mode (/take), Flynn hides the sidebar and top header and locks the viewport shell to h-[100dvh] so you can’t misclick out of an exam.
Timers anchor to a fixed UTC deadline instead of trusting setInterval ticks, for browsers throttle setInterval as soon as you switch tabs. ExamTimer computes deadlineTimestamp - Date.now() on every tick inside a memo-isolated leaf component: if you minimize the window or switch tabs, the deadline stays put and the clock catches up immediately when focus returns, without re-rendering the question text or SVG canvas every second.
Telemetry and Bot Checks
Every option click fires asynchronously via navigator.sendBeacon('/api/v1/sessions/telemetry', payload), falling back to fetch with { keepalive: true } if sendBeacon isn’t available or returns false (TursoEdgeAdapter.ts). Question transitions never wait on network I/O (see Privacy & Telemetry for the exact fields stored).
To catch automated scripts, Flynn checks response timing and pointer geometry:
- Dwell time (render to click):
ModuleRunPage.tsxmeasuresperformance.now()from item render to selection and logs a warning under25ms. On the server,telemetry.tssetsbot_flag = 1whendwellTimeMs < 200, andfinish.tsmarks non-practice sessionsis_verified = 0if average dwell time falls below150msor more than half of items are flagged. - Mouse geometry and jitter: For non-touch, non-keyboard clicks,
telemetry.tsalso flagstrajectoryStraightness > 0.985oractuationJitterMs < 5.0.

Deterministic Seeds with SplitMix32
Sending answer keys down to the browser lets anyone inspect the network tab mid-test, so correct_option_id stays on the server. Instead, both the client and edge workers share a single 32-bit master_seed and run a SplitMix32 PRNG: when you submit, POST /api/v1/sessions/finish replays the exact procedural Attempt 2+ variants and option shuffles from that seed without trusting client-side keys.
Implementation & Math: SplitMix32 Deterministic PRNG (src/data/ist/aig/prng/splitmix32.ts)
Both client and edge generators derive itemSeed = hashSeed(masterSeed, subtestId, itemIndex) and step via the golden-ratio Weyl recurrence:
export class SplitMix32 {
private state: number
constructor(seed: number) {
this.state = seed | 0
}
public next(): number {
this.state = (this.state + 0x9e3779b9) | 0
let z = this.state
z = Math.imul(z ^ (z >>> 16), 0x21f0aaad)
z = Math.imul(z ^ (z >>> 15), 0x735a2d97)
return (z ^ (z >>> 15)) >>> 0
}
public nextFloat(): number {
return this.next() / 4294967296
}
public nextInt(min: number, max: number): number {
return min + Math.floor(this.nextFloat() * (max - min + 1))
}
}Option shuffling skips items where order carries meaning (isOptionShuffleEligible in start.ts): IST FA, WU, and MA visual options, IELTS True/False/Not Given, UTBK PK Data Sufficiency and Quantity Comparison (P vs Q), options that reference other choice letters (A and B), and monotonic numeric choices on SAT-tagged modules. (SAT and IELTS never shipped as active modules, albeit the shuffle guard stayed in start.ts.)