Architecture
1. System overview (platform, Phase 3+)
Section titled “1. System overview (platform, Phase 3+)”flowchart LR subgraph Clients P[Player browser] C[Creator: web editor] X[External AI client<br/>Claude, others via MCP] D[Developer: SDK / CLI / local repo] end
subgraph PlatformOrigin["Platform origin (app domain)"] WEB[Web app<br/>React Router SSR] API[API<br/>Hono + OpenAPI] MCPH[MCP server<br/>Streamable HTTP + OAuth] AIA[AI adapter<br/>provider interface, BYOK] AUTH[Auth<br/>Better Auth] end
subgraph PlayOrigin["User-content domain (separate registrable domain)"] PLAY[Sandboxed game iframe<br/>per-game subdomain, strict CSP] end
subgraph Workers["Job workers (isolated containers)"] BUILD[Build + validate<br/>no network] HEAD[Headless runner<br/>Playwright / stub renderer] MOD[Moderation signals<br/>scans, AI review] end
subgraph Data PG[(PostgreSQL<br/>core data, jobs, ledger)] S3[(Object storage<br/>builds, assets, snapshots)] end
CDN[[CDN]] LLM[(AI providers<br/>Anthropic, OpenAI, local)]
P --> CDN --> WEB C --> WEB WEB --> API WEB -. iframe .-> PLAY PLAY <-. typed postMessage bridge .-> WEB CDN --> PLAY X --> MCPH --> API D --> API API --> AUTH API --> AIA --> LLM API --> PG API --> S3 API -- enqueue --> PG PG -- jobs --> BUILD & HEAD & MOD BUILD --> S3 HEAD --> S3 S3 --> CDNKey boundaries:
- Untrusted code only ever runs in the play-origin iframe (players’ browsers) or in isolated worker containers.
- Games never hold user credentials. All platform calls from a game go through the postMessage bridge.
- The MCP server and the built-in assistant share one tool implementation (
agent-tools), backed by the API.
2. Local creator flow with MCP (Phase 2, no platform needed)
Section titled “2. Local creator flow with MCP (Phase 2, no platform needed)”sequenceDiagram participant U as Creator participant AI as AI client (e.g. Claude) participant M as MCP server (stdio) participant FS as Game project on disk participant V as Vite dev server U->>AI: "Add a double-jump power-up" AI->>M: search_docs("double jump"), get_project_tree AI->>M: add_entity / upsert_level (JSON, schema-typed) M->>FS: write validated files AI->>M: validate → schema + tsc results AI->>M: run_headless(seconds=10, inputs=[...]) M-->>AI: logs, errors, assertions, fps stats AI->>M: capture_screenshot FS-->>V: file change → hot reload in the creator's browser3. Framework layering
Section titled “3. Framework layering”flowchart TB GAME[Game code + JSON data<br/>scenes, levels, prefabs] subgraph Framework["@ludrel/* packages"] direction TB GP[gameplay · ui · world] CAM[camera] --- AUD[audio] --- INP[input] PHY[physics-arcade / physics-rapier] R2D[render-2d] --- R3D[render-3d] CORE[core: loop · scenes · ECS · events · assets · save · rng] SCH[schema: Zod → JSON Schema] DEV[devtools: overlay · hot reload · inspector] end LIBS[(PixiJS · Three.js · Rapier<br/>only imported by adapters)] GAME --> GP & CAM & AUD & INP & PHY & R2D & R3D GP --> CORE CAM & AUD & INP & PHY & R2D & R3D --> CORE CORE --> SCH DEV --> CORE R2D & R3D & PHY --> LIBSCore runtime design
Section titled “Core runtime design”- Fixed-timestep loop (default 60 Hz simulation, accumulator, max 5 catch-up steps, render interpolation alpha).
fixedUpdatesystems are deterministic given the seeded RNG and recorded inputs → enables replays, headless tests and (later) rollback/lockstep netcode. - Scenes are a stack (
push,pop,replace) with lifecycle hooks; a scene is a JSON document plus optional registered systems. - Assets: manifest-driven loader with reference counting, cache, progress events, and per-scene bundles.
- Events: typed event bus (
bus.on('player:died', …)), with event types declared in a typed map. - Save/load:
SaveStoreinterface (localStorage/IndexedDB first;PlatformSaveStoreover the bridge later), versioned save payloads with migrations. - Hot reload: Vite HMR for code; data files (levels/scenes) are swapped in place, preserving entity state where IDs match.
- Headless mode: same core with a stub renderer and stub audio; runs in Node for unit tests and in Chromium via Playwright when pixels matter.
4. Data model sketch (Phase 3, monetization-ready)
Section titled “4. Data model sketch (Phase 3, monetization-ready)”erDiagram USER ||--o{ GAME : publishes USER ||--o{ CONTENT_PACK : creates GAME ||--o{ GAME_VERSION : has GAME_VERSION ||--o{ CHANGE : "history (undo)" GAME ||--o| GAME : "forked_from (lineage)" GAME ||--o{ CONTENT_PACK : "extended by" CONTENT_PACK ||--o{ PACK_VERSION : has PACK_VERSION ||--o| MODERATION_ITEM : "reviewed in" GAME ||--o{ RATING : receives GAME ||--o{ PRODUCT : sells CONTENT_PACK ||--o{ PRODUCT : sells PRODUCT ||--o{ REVENUE_SHARE_RULE : "split by" USER ||--o{ ORDER : places ORDER ||--o{ ORDER_ITEM : contains ORDER_ITEM }o--|| PRODUCT : for ORDER_ITEM ||--o{ LEDGER_ENTRY : posts USER ||--o{ ENTITLEMENT : owns USER ||--o{ PAYOUT : receives USER ||--o{ AI_CREDENTIAL : "BYOK (encrypted)" GAME ||--o{ PLAY_EVENT : analytics