rosneri/writing
all posts
GamesNov 2026 · 9 min read

The LitRPG: a game where the world remembers your dead

Neriya Rosner
Neriya Rosner
backend-oriented full-stack engineer

I listen to an embarrassing amount of LitRPG: Dungeon Crawler Carl, Welcome to the Multiverse, the genre where the hero levels up with literal stat screens. A while ago I wrote about a small engine for it. This is what that turned into: thelitrpg.com, a grim, hopeful, story-driven roguelike where an AI writes the story around your choices, and the world remembers your dead.

What the game is

You start with almost nothing: no class, no genre, no world name. The AI writes a scene and offers two to four choices, or you type whatever you want to do. Each choice nudges you through a three-dimensional moral space:

The AI reads where you are in that space and writes accordingly. A suspicious, despairing player gets a different story from a trusting, hopeful one, even from the same opening.

Then you die, because it’s a roguelike. Your HP hits zero, you respawn at level 1, and your moral vector is partially absorbed into the world’s. Every death changes the world’s character a little. Play long enough and the world becomes the sum of everyone who died in it.

The story grows in phases

A blank page is a bad place to start a story, so the game unfolds in five phases:

  1. The Awakening: genre-ambiguous exploration. No death, no timers, no quests. The AI is working out what kind of story you want.
  2. The First Steps: the world gets a name and a setting. Simple quests appear, and death is possible but rare.
  3. The Shaping: names, places, relationships, and timed choices.
  4. The Weaving: lore, factions, history, and multi-step quests.
  5. The Chronicle: sagas, which are AI-outlined storylines of three to seven chapters. If you wander off the outline, the AI rewrites the chapters ahead. Death becomes an event in the saga instead of a reset.

The AI signals when the story is ready for the next phase, and fixed thresholds back that up so a story can’t get stuck. The genre and tone it detects early on (“dark fantasy”, “grim”) shape every prompt after that.

Nothing is hardcoded except HP

This is the part I’m proudest of as a LitRPG fan. Stats and bars are generated to fit the story. A dark fantasy might give you strength, arcana, and willpower. A sci-fi run might give you engineering and psi-power. A spaceship story gets a fuel bar, and a horror story gets sanity. A dark ritual can add corruption mid-run. The only fixed number is HP, because HP is how you die.

On top of that, the AI controls a set of mechanics: items with rarity and equip slots, quests that can mutate mid-story, NPCs who remember how many times you’ve met, choice timers, “progression drift” (XP multipliers, stat swaps, and even stat resets as curses), and action mode. Action mode is a combat, chase, or heist sequence where the prose gets shorter, every choice is timed, and free text turns off so you have to commit.

How it’s built

On the surface it’s an Astro SSR app with React islands on Vercel, backed by Supabase Postgres through Prisma. The interesting part is the shape underneath.

One module per mechanic. It’s an Nx monorepo with about 47 libraries, most of them a mod-* per game system: mod-vectors, mod-quests, mod-death, mod-sagas, mod-bars, and so on. Every module has the same five files:

types.ts    — state and trigger types, zero dependencies
logic.ts    — pure functions: apply, validate, transform
schema.ts   — the Zod schema the AI's output is validated against
context.ts  — what this module tells the AI, and what it tells the UI
index.ts    — explicit named exports

That split does most of the work. The AI never mutates game state directly. It returns structured triggers (“start this quest”, “damage this bar”), each module’s Zod schema validates its own triggers, and pure logic.ts functions apply them. When the model makes something up, it fails validation instead of corrupting a save. I wrote about stats as plain data before. This is that idea applied to every system in the game.

Layer boundaries are enforced, not suggested. Nx tags split the code into domain, module, infra, app, and UI layers. A UI library physically can’t import infrastructure, and a module can’t reach into the app. On top of that it has the same guardrails as this site: zero any, 400-line files, 50-line functions, circular-dependency and dependency-cruiser checks.

State machines for the flows that go wrong. The game loop, auth, accounts, and admin are all XState machines. That paid off most on the bug below.

The bug that taught me the most

A turn is slow: several model calls, then persisting everything they produced. On iOS Safari, if you switch apps while the page is turning, Safari kills the fetch. Players came back to a “Loading game” screen, or to a stale moment, or got pushed through onboarding again.

The fix came from one invariant: once the server receives the request, it always finishes the turn. It marks the turn as pending before the slow AI call and clears the mark after persisting. Only the browser’s fetch dies; the turn itself doesn’t. So resuming means re-attaching to the turn’s outcome, never re-rendering the world.

The game machine stays in generating the whole time. If the fetch dies with a transient network error, the client polls a landed endpoint until the turn shows up, then animates the new moment in exactly as if nothing had happened. A cold start renders whatever has landed. A full page reload is the last resort, for when the turn really did die on the server. The player sees one thing from tap to result: the page-turn loader. Writing it as a state machine is what made “the loader never leaves” a property I could test, not just hope for.

Measuring prose, not just shipping it

The hardest question in an AI-written game is whether a change to the prompts makes the story better. “It feels better” doesn’t scale, so the game measures it.

Every turn records each pipeline step’s cost, latency, and tokens. A sample of turns goes to an LLM judge that scores continuity, beat-appropriateness, choice meaningfulness, and prose concreteness. Pipeline variants run as experiments, and the results come with bootstrap 95% confidence intervals. The decision rules are written down: under 30 sessions per variant, keep collecting. If the intervals overlap, it’s a tie. Promote a variant only when it wins clearly and its cost and latency still hold up.

The whole loop is a script, so an agent can run it: create the experiment, play N turns per variant through the API, drain the judge queue, recompute, report. An agent can change a prompt, measure it against a baseline, and show me the numbers before I read a single line of the diff.

Built mostly by agents, held up by checks

The repo has 1,488 commits between February and June 2026 and over 500 test files. More than 180 of those commits came out of Ralphy loops: an issue in Linear becomes a ralph/lit-NNN branch with a proposal, a design, and a task checklist, and a fresh agent works through it one task at a time until a PR opens.

That only works because the repo is so strict. Agents write most of the code, and the module shape, layer boundaries, Zod schemas, and test gates are what keep 1,500 commits feeling like one codebase instead of 1,500 opinions. It’s the same lesson as payments infrastructure, with dragons.

Go die in it

The game is live at thelitrpg.com. Make a few choices, find out what genre you’re in, and die at least once. Your vector stays in the world after you’re gone.

Play it: thelitrpg.com. Built with the same guardrails as everything else here, mostly by Ralphy loops.More writing
Keep readingA LitRPG engine in TypeScript7 minDeterministic guardrails for AI-written code13 minRalphy, as an idea file5 min