# EnigMafia: the Discord mafia game engine

> The town sleeps. The engine doesn't.

EnigMafia runs 60-player, multi-week mafia games on Discord, in the spirit of Town of Salem. Roles are data, every night resolves deterministically in Rust, and the gods (the human moderators) keep the one thing a machine should never touch: the story.

It is free, open-source software under the MIT license. Everything on this site runs the real engine in your browser through WebAssembly.

## How it works

Hand-resolving dozens of interacting roles across fourteen priority tiers in a spreadsheet is slow and error-prone. EnigMafia turns the role bible into a typed ruleset and resolves it the way a careful god would, with a receipt for every step.

- **Roles are content.** Forty composable effect blocks, triggers, variants and a small condition language. A Consort is a role-block plus a lookout. No role is ever named in engine code.
- **Two passes, one truth.** Pass A settles who actually ends up where: jail, alerts, control, transport, role-blocks, traps. Pass B walks the tiers. Seeded dice make every night replay bit for bit.
- **Menus that can't lie.** The Discord `/act` command builds its menus from the engine's legal options, so nobody is offered a dead target, a spent charge or the wrong moon.
- **No silent guesses.** Thirty-two contradictions in the bible are written down, decided provisionally, and pinned by a scenario that fails if anyone changes the behaviour.
- **Balance before launch.** Simulate hundreds of games in your browser before a new role reaches a player.
- **Gods keep the pen.** Resolve, read the factual draft, add the story, publish. Every override lands in the audit log.

## Architecture

One Rust core, three hosts. The same engine compiles into the Cloudflare Worker that talks to Discord, into this site, and into the command line gods use to test rulesets. Each game lives in its own Durable Object with SQLite state, alarms for the phase clock, and an audit log.

## Pages

- [Codex](https://mafiosa.pages.dev/codex): every role, generated from the ruleset.
- [Arena](https://mafiosa.pages.dev/arena): deal a town and watch a night resolve.
- [Ruleset Lab](https://mafiosa.pages.dev/lab): write a role and prove it with scenarios.
- [God console](https://mafiosa.pages.dev/console): run a live game after signing in with Discord.
- [About](https://mafiosa.pages.dev/about), [Contact](https://mafiosa.pages.dev/contact) and [Privacy](https://mafiosa.pages.dev/privacy).
- [Source code on GitHub](https://github.com/KarthikSubramanian07/Enigmafia).
- [llms.txt](https://mafiosa.pages.dev/llms.txt): a guide for AI agents.

## For agents

Read [llms.txt](https://mafiosa.pages.dev/llms.txt) for when to use EnigMafia and how to reach it. Every page on this site is also available as Markdown: send `Accept: text/markdown`, or add `.md` to the path, for example [index.md](https://mafiosa.pages.dev/index.md).
