0%
System Architecture Case Study

Sim Racing Team Platform

A production-grade orchestration engine spanning 43,000+ lines of code. The digital nervous system for a competitive sim racing team — binding a Next.js Web Platform with a Python Discord Bot via real-time WebSockets.

DomainSim Racing Mgmt
Scale43K+ LOC
StackNext.js, Python, Turso,
Upstash, Discord.py
43K+
Lines of Code
145
API Routes
14
Cron Jobs
3
OAuth Providers
24
Migration Scripts
50+
Active Pilots

Core Architecture

Three OAuth Flows. Two Databases. One Bridge.

Triple OAuth

Discord OAuth for identity. iRacing via custom PKCE S256 (321 lines, hand-written code verifier/challenge). Garage61 OpenID Connect with slug resolution and fallback chain.

3 token lifecycles managed

Dual-Database Layer

Turso (LibSQL) for persistent relational data. Upstash Redis for cache, sessions, rate limiting. Backend-agnostic abstraction — dbGet/dbSet/dbDel works against either engine transparently.

Sub-10ms edge queries

WebSocket Bridge

Python Discord bot on dedicated on-premise server maintains persistent WSS to cloud backend. Authenticated handshake, event-driven broadcasts, bi-directional state mutations.

Real-time sync

System Topology

Three-tier architecture with real-time bidirectional synchronization

Live System Map
All Systems Operationalv2.4.1
Tier 1 — Auth Providers
DiscordOAuth 2.0
iRacingPKCE S256
Garage61OpenID Connect
Tier 2 — Orchestration Layer
Next.js 14Central Orchestrator
LIVE
145
Routes
14
Crons
264
Files
Discord BotPython • On-Premise
WSS
Vercel Cron14 Scheduled Jobs
Tier 3 — Data Layer
TursoLibSQL • Edge
<10ms
Upstash RedisCache • Sessions
95% saved
Backend-agnostic abstraction: dbGet / dbSet / dbDel6 services • 3 auth flows • 2 databases

System Depth

264 TypeScript files. 145 API routes. 24 migration scripts. Every feature hand-built.

14 Cron Jobs

Vercel-scheduled sync pipeline: iRacing stats, Garage61 laps, weekly schedules, subscription audits, cache warming — all auth-protected with admin-visible sync logs.

Granular RBAC

Owner/Admin/Member/Guest roles with 6 admin panels, cup/gallery/league editors, and dynamic Discord-role-to-site-access mapping.

Endurance Race Planner

Multi-timezone stint scheduling with iRating-based matching, Garage61 car ownership verification, spotter slot management, and captain assignment.

Gallery Pipeline

3-tier image processing: Sharp resize → WebP conversion → Base64 Turso storage. Thumbnail + Optimized + Original with photographer attribution.

i18n (TR/EN)

Full bilingual support via next-intl. Every UI string, error message, and notification localized across Turkish and English.

DM Queue System

Web → KV → WSS → Discord Bot → DM. Asynchronous notification pipeline ensuring messages reach pilots regardless of which interface they use.

The Challenge

Coordinating 50+ pilots across time zones for 24-hour endurance races in iRacing. Tracking registrations, verifying iRating limits, collecting Garage61 telemetry, and broadcasting schedule updates — all scattered across disconnected tools and manual spreadsheets.

Three separate OAuth providers with completely different auth flows. An external Discord bot that needed to stay perfectly synchronized with the web state. API rate limits from iRacing that could brick the entire sync pipeline.

The Solution

A centralized orchestration nucleus. The Next.js platform acts as the single source of truth, with Turso handling persistent state and Redis providing a 95% API-call-saving cache layer against rate-limited external services.

The Python bot operates as a stateful node — not a passive notification sink. Users execute management tasks from whichever interface they prefer. Data is instantly verified, cached, and synced globally through the WebSocket bridge.

Next.js 14TypeScriptTursoUpstash RedisNextAuthDiscord.jsTailwind CSSWebSocketOAuth 2.0 / PKCE S256OpenID ConnectVercel Cronnext-intldiscord.pyDocker
Visit Live Platform