This page walks through the repository as it is at the v2.8.1 tag, folder by folder. Two things surprise people coming from other projects: the starter game that people download is the dist/ folder, and the build output (dist/engine/, dist/types/ and lib/) is committed next to the source.

The top level

Path What it is
src/ The engine, in TypeScript. Everything a game runs comes from here.
debug/ The debug module’s source: debug/index.js and the syntax highlighter it bundles, debug/vendor/prism.js.
dist/ The starter game, which is also where the build writes the browser bundles and the type declarations. See below.
lib/ Build output: the ES module lib/monogatari.module.js and its source map, the npm package’s main entry. Committed.
cypress/ The end-to-end tests: specs in cypress/e2e/, the custom commands in cypress/support/commands.js. See Testing the Engine.
docs/ These docs, published to monogatari.io/v2. See Writing and Publishing the Docs.
.github/ FUNDING.yml and two workflows: lint.yml (lint and type check) and test.yml (build and Cypress).
build.ts The build script. bun build.ts builds everything; flags build one part. See Building and Packaging.
scripts/cypress.ts What bun run test runs: Cypress in Google Chrome, or Chromium where Chrome isn’t installed. See Testing the Engine.
package.json The package @monogatari/core, its version, scripts, exports and dependencies.
bun.lock The lockfile bun install reads.
tsconfig.json TypeScript settings for src/ only ("include": ["src/**/*"]), strict, with noEmit.
eslint.config.mjs ESLint’s flat config: the recommended JavaScript and TypeScript rules on src/ (with no-unused-vars, no-explicit-any and no-this-alias turned off), and the house style from @aegis-framework/eslint-config on every hand-written script. It leaves out the built bundles and declarations (lib/, dist/engine/core/, dist/engine/debug/, dist/types/) and vendored code.
cypress.config.js Cypress’s config: the spec pattern cypress/e2e/**/*.{js,jsx,ts,tsx} and the Cypress Cloud project id.
.editorconfig Two-space indentation, LF line endings, UTF-8, trailing whitespace trimmed.
.nvmrc v25, the Node version for tools that read it.
README.md, CONTRIBUTING.md, LICENSE The front page on GitHub, the short contributor guide, and the MIT license.

node_modules/ appears after bun install; .gitignore keeps it out of Git, along with *.zip, cypress/videos/, cypress/screenshots/ and build.

src/: the engine

src/
├── index.ts            the ES module entry: registers every action, component and translation
├── browser.ts          the browser bundle's entry: sets window.Monogatari and window.monogatari
├── monogatari.ts       the engine object (a class with static members only)
├── index.css           the stylesheet entry: imports the libraries, styles and every component's CSS
├── deeply.d.ts         types for the deeply merge library
├── engine/             parts of the engine object, as functions that take the engine
│   ├── assets.ts           asset lists, audio and image caches, the service worker cache, IndexedDB spaces
│   ├── characters.ts       characters() and character()
│   ├── i18n.ts             interface strings, localize(), _(key) translation, {{variable}} interpolation
│   ├── input.ts            keyboard shortcuts (Mousetrap) and the data-action listeners
│   ├── lifecycle.ts        run(), revert(), next(), previous(), proceed(), rollback() and their checks
│   ├── persistence.ts      saveTo(), loadFromSlot(), resetGame(), setupStorage(), upgrade()
│   └── ui.ts               screens, alerts, auto-play, skip, distraction-free, resizing, screenshots
├── actions/            the 36 actions, one class per file (Dialog.ts, ShowCharacter.ts…)
├── components/         the 27 components, one folder each with index.ts and index.css
├── lib/                the base classes and helpers
│   ├── Action.ts           the base class of every action
│   ├── Component.ts        the base class of every component, on Pandora's Component
│   ├── ShadowComponent.ts  the same with a shadow root (exported for games; no built-in uses it)
│   ├── ScreenComponent.ts  screens: an open state that toggles the active class
│   ├── MenuComponent.ts    menus built from a list of buttons (main-menu, quick-menu)
│   ├── AudioPlayer.ts      Web Audio playback with effects
│   ├── FancyError.ts       the error dialogs
│   ├── FileSystemStorage.ts the FileSystem storage adapter for desktop builds
│   ├── DesktopBridge.ts    finds window.electron or window.electrobun
│   ├── typing-utils.ts     helpers for the type-writer's markers
│   └── types/              the TypeScript types: StateMap, HistoryMap, GameSettings…
├── migrations/         functions that update an old save's data when it's loaded
├── style/              variables.css, monogatari.css, kayros.css, csshake.min.css
├── translations/       the interface in 18 languages, one file per language
└── vendor/random-js/   a vendored copy of the random-js library

A few things to know before you open these files:

  • src/monogatari.ts is one class whose members are all static. The engine object a game calls monogatari is the class itself, not an instance. Most methods are thin wrappers: proceed() calls proceed() from src/engine/lifecycle.ts with the engine as its first argument. Reading the Code maps the file.
  • Actions are files named after their class (ShowCharacter.ts), and their id is what monogatari.action() looks up ('Show::Character'). Components are folders named after their tag (text-box/).
  • The order of _actions in src/index.ts matters. The engine asks each action in that order whether it takes a statement, and Dialog takes any string, so it is last.
  • src/style/kayros.css is a local copy of the Kayros CSS framework. The comment above its import in src/index.css says it was repurposed and kept to avoid breaking changes. Its utility classes (.left, .right, .center…) share names with classes the engine puts on sprites, which caused the bug in stage 3 of the learning path.
  • Every component’s index.css is imported by src/index.css, which is how its rules reach monogatari.css. A new component’s stylesheet needs its own @import line there: nothing else warns when one is missing (credits-screen lacked it until 2.9.0).

dist/: the starter game and the bundles

dist/ is what people download: the release zip is this folder, flat (see Releasing a 2.8.x Patch). Most of it is the game’s own files, edited by hand. Three folders inside it are written by the build.

dist/
├── index.html          loads the debug module, the engine, then js/options.js, storage.js, script.js, main.js
├── js/                 the game: options.js (settings), storage.js, script.js (the story), main.js (init)
├── style/main.css      the game's own styles
├── assets/             the game's media folders, each kept in Git by an empty .gitignore; icons/ has the app icons
├── engine/
│   ├── core/           BUILD OUTPUT: monogatari.js, monogatari.css and the source map
│   ├── debug/          BUILD OUTPUT: debug.js and its source map
│   ├── electron/       the Electron host: index.js, preload.js, notarize.js, entitlements.mac.plist
│   ├── electrobun/     the Electrobun host: index.ts (main process), view.ts (webview bridge)
│   ├── desktop/        storage.js: the files both hosts keep for the FileSystem storage adapter
│   └── LICENSE
├── types/              BUILD OUTPUT: the .d.ts declarations of src/
├── service-worker.js   caches the game for offline play when served
├── manifest.json       the web app manifest
├── package.json        the game's own package: Electron, electron-builder and Electrobun scripts
├── bun.lock            that package's lockfile
├── electrobun.config.ts
├── serve.ts            a small development server (Bun)
├── build-web.ts        copies the game to build/web without the debug module
├── jsconfig.json, jsconfig.node.json
└── favicon.ico

The Starter Game and Desktop Hosts explains each part and what has been run.

Build output, and why it’s committed

Folder Made by Used by
dist/engine/core/ buildBrowser() and buildCSS() in build.ts dist/index.html, the Cypress specs, the release zip, the package’s ./browser export
dist/engine/debug/ buildDebug() dist/index.html
dist/types/ buildTypes() (tsc --emitDeclarationOnly) the package’s types
lib/ buildModule() the package’s main, module and . export

All four are committed. The starter game must run as downloaded, the Cypress specs load dist/index.html, and the zip is made from the folder, so a change to src/ goes in together with the rebuilt files. Until December 2025 a GitHub workflow rebuilt dist/engine/core and committed it as “Update engine core”; commit 5b16c02e (“Don’t commit core”) stopped that, and since then the person making the change commits the rebuilt files. The build is reproducible: on a commit whose bundles are current, bun run build leaves git status clean. Building and Packaging has the details.

Tests

cypress/e2e/actions/ holds one spec per action or group of actions (dialog.spec.js, show_character.spec.js, stop.spec.js…), and cypress/e2e/components/ the component specs (save-screen.spec.js, text-box-scroll.spec.js…). cypress/e2e/main_menu_after_load.spec.js checks the main menu after a load. There is no unit-test suite. Testing the Engine lists every spec and the commands they share.

The docs folder

docs/ holds these pages as Markdown, one folder per section, docs/styles/docs.css for the shared page components, and docs/FORMAT.md, which has no title and is never published. Writing and Publishing the Docs has the rules.