ic-y29y: GH#6: ADR: SpacetimeDB as World Runtime
Snapshot: 2026-03-30T08:40:31Z
| Field | Value |
|---|---|
| Status | open |
| Assignee | (unassigned) |
| Priority | 2 |
| Labels | atlas |
| Created by | github-bridge |
| Created | 2026-03-28T18:50:05Z |
| Updated | 2026-03-28T18:50:05Z |
Description
GitHub issue: b4arena/spellkave#6 URL: https://github.com/b4arena/spellkave/issues/6
Context
Spellkave needs a runtime for its persistent world simulation — where world state lives, how game logic executes, and how clients (human players, AI agents, observers) connect and receive updates.
After evaluating traditional stacks (game server + PostgreSQL), SpacetimeDB emerged as a strong candidate. This ADR should evaluate and document the decision.
What Atlas Should Deliver
An ADR documenting:
- Decision: Use SpacetimeDB as the combined database + application server for Spellkave's world simulation
- Rationale: Why this over a traditional game server + DB stack
- Pattern: The BitCraft architecture pattern — entire server as a single SpacetimeDB WASM module (Rust)
- AI Agent Integration: The two-phase ThinkRequest/ThinkResult pattern for LLM-backed agent reasoning:
- Fast path: simple agent behavior as scheduled reducers (move, trade, patrol) — runs inside SpacetimeDB
- Slow path: LLM reasoning offloaded to an external service that subscribes to
ThinkRequesttable and writes results back via reducer - The LLM service is "just another client" — world never blocks on LLM responses
- Client model: All clients (text CLI, web UI, AI agents, observers) connect via SpacetimeDB SDK — no separate REST/gRPC layer. The API contract IS the set of public tables + reducers.
- Accepted risks and mitigations:
- Single-writer lock → keep reducers fast, offload heavy compute
- RAM ceiling → design data lifecycle (archive old events) from day one
- API instability → pin SpacetimeDB version (BitCraft pins 1.12.0)
- Vendor risk (BSL license, small team) → self-host, patterns portable to any backend
- No horizontal scaling → single-node fine for Phase 0-2, world partitioning at app level if needed later
Key Reference Material
SpacetimeDB
- What is SpacetimeDB? — "Your database is your server"
- Key Architecture — in-memory + WAL, WASM modules, WebSocket clients
- Scheduled Reducers — how tick loops work
- Procedures (beta) — outbound HTTP for LLM calls
- Subscriptions — real-time push to clients
- Self-hosting — Docker or standalone binary
- Technical review (strn.cat) — honest assessment of durability, single-writer, maturity
BitCraft (primary architecture reference)
- BitCraftPublic repo — entire MMORPG server as one SpacetimeDB module
- "Databases are the endgame for data-oriented design" — must-read: ECS is a subset of relational
- "SpacetimeDB and BitCraft" — architecture overview
- GDC 2025 talk — "Database-Oriented Design: Why We Built Our MMORPG Inside a Database"
- Developer Voices podcast — deep technical interview
Other SpacetimeDB game projects
- spacetime-mud — text MUD with Rust server + TS frontend + Python AI agent (closest to Spellkave's model)
- spacetimedb-minecraft — Minecraft server on SpacetimeDB
Dependencies
None — this is the foundational decision. Issues #4, #5, #6, #7 depend on this.
Acceptance Criteria
- ADR follows standard format (context, decision, consequences)
- Explicitly addresses the BitCraft pattern and how Spellkave adapts it
- Documents the ThinkRequest/ThinkResult pattern for AI agent LLM integration
- Lists accepted risks with mitigations
- Committed to
spellkaverepo under an appropriate path