Edge System Architecture
How a shared Cloudflare Workers backend (lightmeup-api) and Cloudflare D1 SQL database (lightmeup-db) verify separate Clerk authentication instances for Duat and Common Court, alongside specialized microservices like cc-scores and standalone utilities like Weather Witch.
System Topology Diagram
Interactive SVG RepresentationClient Applications Layer
Cross-Platform Web & Native Frontends
Frontend architectures tailored for maximum responsiveness and specialized domain rendering:
- Duat Play (duatplay.com): React 19 / Expo Web with Three.js / React Three Fiber 3D board rendering, 5 deterministic rules engines, and hieroglyphic deciphering tools.
- Common Court (commoncourt.app): React Native / Expo SDK 57, Leaflet map, Top 24 streetball video pipeline, dynamic elemental day/night themes, and science-based fitness calculators.
- Weather Witch (weatherwitch.app): React 18 / Vite standalone weather web application rendering real-time sky backdrops and multi-layer meteorological maps.
Separate Clerk Authentication
Dedicated App Instances & Edge JWT Verification
Authentication is scoped per application with dedicated Clerk environments to ensure strict security boundaries:
- Duat (Production Key): Dedicated production Clerk application managing verified board game player credentials, milestone progression, and match statistics.
- Common Court (Development Key): Dedicated development Clerk application managing basketball profiles, court bookmarks, and workout streak logs.
- Edge JWT Verification:
lightmeup-apivalidates both distinct JWKS endpoints locally on Cloudflare edge nodes without external auth round-trips. - Weather Witch: Zero authentication required — fully accessible public utility querying open APIs directly.
Cloudflare Workers Edge Layer
lightmeup-api Gateway & cc-scores Ingestion
Serverless V8 isolates distributed globally across Cloudflare edge datacenters for sub-20ms execution:
- lightmeup-api: Shared REST gateway managing badges, user profiles, leaderboards, and real-time multiplayer WebSocket rooms.
- cc-scores Worker: High-throughput sports score ingestion worker streaming real-time clocks, team odds, and betting lines for NBA, NFL, MLB, WNBA, and College Basketball.
- Low Latency WebSockets: Sub-second state synchronization for Duat game lobbies and match moves.
Edge SQL Persistence
Cloudflare D1 (lightmeup-db)
Serverless SQLite database executing queries co-located with Worker compute at the edge:
- Scoped Multi-App Schema: Tables partitioned with
app_idconstraints ensuring clear data boundaries between Duat and Common Court records. - Zero Cold Starts: Edge SQL reads and writes executed in under 15ms globally without connection pooling overhead.
- Relational Integrity: Manages player profiles, unlocked cross-game badges, match histories, pyramid stone placements, and saved court check-ins.
lightmeup-db Core Relational Design
The database schema supports both Duat and Common Court while keeping authentication tokens tied to their respective Clerk application instances:
-- Core user profiles mapping to separate Clerk instances
CREATE TABLE users (
id TEXT PRIMARY KEY, -- UUID
clerk_id TEXT UNIQUE NOT NULL, -- Clerk User ID (scoped per app)
app_id TEXT NOT NULL, -- 'duat' | 'common-court'
username TEXT NOT NULL,
display_name TEXT,
avatar_url TEXT,
created_at INTEGER DEFAULT (unixepoch()),
updated_at INTEGER DEFAULT (unixepoch())
);
-- Shared and app-specific badges
CREATE TABLE badges (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
app_id TEXT NOT NULL, -- Origin app of badge achievement
badge_key TEXT NOT NULL, -- e.g. 'senet_master', 'top24_curator'
tier TEXT NOT NULL, -- 'bronze' | 'silver' | 'gold' | 'obsidian'
unlocked_at INTEGER DEFAULT (unixepoch()),
UNIQUE(user_id, badge_key)
);
-- Duat game match records
CREATE TABLE games_history (
id TEXT PRIMARY KEY,
game_type TEXT NOT NULL, -- 'senet' | 'mehen' | 'hounds_jackals' | 'aseb' | 'tab'
player_a_id TEXT REFERENCES users(id),
player_b_id TEXT REFERENCES users(id),
winner_id TEXT REFERENCES users(id),
moves_count INTEGER NOT NULL,
completed_at INTEGER DEFAULT (unixepoch())
);
-- Common Court saved courts and check-ins
CREATE TABLE cc_saved_courts (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
court_id TEXT NOT NULL, -- Spot identifier (e.g. 'venice_beach')
created_at INTEGER DEFAULT (unixepoch())
); Why Cloudflare Workers + D1 at the Edge?
Zero Cold Starts
V8 isolates spin up in under 5 milliseconds globally, eliminating the latency spikes of traditional containerized and node-based serverless runtimes.
300+ Edge Datacenters
Auth validation, API routing, and WebSocket handshakes terminate at the user's nearest point of presence for consistent sub-30ms round-trips.
Scoped Security
Each application maintains its own Clerk identity environment while sharing verified persistence and edge microservices without cross-contamination.
Cost & Scale Efficiency
Serverless execution scaling to millions of daily requests with minimal base operational overhead and zero idle infrastructure costs.