Memory5D architecture

BETA / RUNTIME-PROVEN — available GATED. The shared core, native client boundary, and Nakama handler exist and are backed by authenticated two-client Nakama runtime evidence; the native beta route is live in production. The moderated human-learning study gates available promotion.

Shared deterministic core

The implementation begins with JSON-only shared/types.ts, shared/config.ts, and shared/protocol.ts, with SCHEMA_VERSION, RULESET_VERSION, and GENERATOR_VERSION all starting at 1. Every pure leaf lives below shared/core/; it has no DOM, browser, Node, Nakama, Date.now(), Math.random(), or mutable global.

The only reducer signature is:

reduce(state, command, context): { nextState, orderedEvents, rejection? }

Rejections retain the same state reference, produce no events, and never increment the revision. Commands are selection/cancellation, power arm/cancel, draft pick, clock tick, and concede. Purchases, imports, profile management, tutorial navigation, and rematch are outside the reducer.

Events are versioned, sequenced facts such as match start, draft, selection, power application, link resolution, claims, score/streak changes, rotation, reweave, line completion, store purchase, achievement, and terminal result. Replay, tactical AI, UI, simulation, achievements, and statistics all consume this one rule core.

Seeded generation rejects biased or sparse boards, retries deterministically, then uses a balanced deterministic fallback. Reweave changes only unclaimed cell attributes. Fixed golden vectors and simulations compare browser and Nakama-target imports byte-for-byte.

Native Svelte host

The final entrypoint is frontend/src/lib/Memory5DGame.svelte, mounted through the platform native host. Its props mirror NativeGameHost.svelte: hostUpdate, platformSession, platformUser, platformSocket, platformBus, drawerOpen, gameActive, and theme. It uses Svelte 5 runes, callbacks, snippets, $state.raw immutable snapshots, and no legacy stores, raw postMessage, direct socket handler assignment, or on: directives.

The root owns host lifecycle only: it sends typed ready/navigation/dock updates and reflushes them when an inactive pooled mount becomes active. Session orchestration owns local clocks, AI scheduling, IndexedDB, audio, reducer projection, and cleanup. Theme is applied only to the component root with data-theme; the custom constellation layer derives semantic CSS variables from daisyUI tokens.

Online authority

Nakama becomes the single authority only after all local product gates pass. It accepts Memory5D command opcode 20, broadcasts events/snapshots with opcodes 21/22, and terminal results with 23. Client payloads are UTF-8 JSON capped at 4 KiB. Server derives actor identity from the presence, validates membership/schema/match/revision/phase/turn/command, calls the shared reducer, and increments revision once per accepted command. Duplicate command ids replay the original success; every rejection has no state mutation.

A five-tick-per-second match keeps disconnected seats for 300 ticks, continues the authoritative clock, restores a rejoined user’s snapshot, then converts one expiry to forfeit or two to draw. Results are finalized once before external writes and held five seconds for delivery.

Online progression is server-only Nakama storage with read access to the owner and no client write permission. Read-validate-compose-conditional-write retries conflicts at most three times and records idempotent receipts. Local progression never migrates online.

Manifest-declared leaderboards are the source of truth: wins, integer Elo (Ranked Classic only), and best Mastery for every difficulty/ruleset pair. Custom matches write no canonical board. Arcade Power Draft never writes Elo.

Ask Docs

AI assistant to help answer questions about the documentation. Answers are read-only and cite docs/source.

Hi! How can I help you with the documentation today? Answers are read-only and cite docs/source.

Ctrl+Enter to send