MAFIA

Building Mafia: the design and dev choices behind mafiagame.io

By Saady Boy · July 6, 2026

I grew up playing Mafia at sleepovers and at family parties where it always ran way later than anyone planned. Someone deals out cards, one person runs the show, everyone closes their eyes, and then the arguing starts. I loved it. What I did not love was needing a deck, a quiet room, and someone willing to explain the rules for the hundredth time.

So I built a version you can open on a phone with friends in about a minute. This post is a walk through how it works and why I made the choices I made. Some of it is game design and some of it is plumbing, but all of it came from trying to keep one thing true: it should feel like the game you already know, just with less friction.

Later on I fell hard for Town of Salem, back when the lobbies were packed and you could always find a game going at any hour. I loved it. A lot of what ended up in here, the extra roles, the wills, the whole trial format, comes from the time I sank into that game. This is my own take on that same itch, trimmed down to something you can start in a room full of friends without a tutorial.

One screen per person

Mafia only works if secrets stay secret. In person, that job falls on the narrator and on everyone's ability to keep a poker face. Online, I could do better than that, so I split the game across two kinds of screens.

There is a host screen, which is meant to live on a laptop or a TV in the middle of the room. It shows the room code and the QR code, keeps the timers, and reads the story out loud so the whole room hears one voice. Then there is your phone, which shows only what your character is allowed to know. Your role, your night action, your will. Nobody has to trust the narrator to keep a straight face, because your phone keeps the secret for you. When it is night, your phone quietly asks the mafia who they want gone while everyone else just sees a sleeping town.

This split ended up shaping almost every other decision. The host is the shared source of truth and the phones are private windows into it.

Joining without accounts

The fastest way to kill a party game is to make people sign up for it. So there is no sign up. You type a name and a six character code and you are in. The code is short and readable on purpose, because someone is going to be shouting it across a living room. If typing is too much effort, the host screen shows a QR code you can point a camera at and skip straight to the name step.

No email, no password, no download, nothing to verify. The whole game runs in a browser tab. That was a hard rule from the start, and sticking to it made the game feel a lot more like passing out cards than like logging into software.

The stack, and why it is boring on purpose

There is nothing exotic here. A single Node server runs Express and Socket.io and holds all the game logic in memory. The front end is React, built with Vite. One server process serves the built front end and runs every live game at the same time.

Every game lives in a plain map in memory. No database anywhere. That keeps things fast and simple, and it comes with one honest tradeoff: when I ship an update the server restarts, and any game in progress gets wiped. For a party game where a round lasts twenty minutes, that is a price I am happy to pay. I deploy during quiet hours and move on. A database would have bought me durability I do not need and a lot of maintenance I do not want.

Roles, and how much to show

The game supports up to fifteen players, and the number of mafia scales with the size of the group so it never feels lopsided. Alongside the classic mafia and townsfolk, there are a few roles that change how people play.

A rule I kept coming back to was how much to reveal. When someone dies, the game shows their role. That single choice does a lot of work. It turns every death into new information and gives the town something real to argue about, instead of just guessing in the dark all game.

The will system

Inspired by Town of Salem, which shaped a lot of what is in this game. While you are alive you can write a will, and when you die it gets read out to everyone. On the surface it is a way to pass on what you learned before the mafia got to you. In practice it is a bluffing tool. You can write a will designed to be found, point fingers from beyond the grave, or leave a trail that makes you look innocent. Some of the best moments in testing came from a dead player's will completely flipping the room.

Voting, trials, and timers

Days follow a rhythm. First there is discussion, on a timer so nobody can stall forever. Then voting opens. If someone collects enough votes, they do not just die on the spot. They stand trial. The accused gets a moment to defend themselves, and then the town votes guilty or innocent while a second timer runs.

The part I care about most is what happens after the verdict: everyone gets to see who voted guilty and who voted innocent. That reveal is where a lot of the paranoia lives. The three people who were suspiciously quick to condemn an innocent townsperson have some explaining to do tomorrow. Timers everywhere keep the whole thing moving so the game has a pulse instead of dragging.

The narrator

The host screen talks. It uses the browser's built in speech synthesis, so there are no voice files to record or ship, and it only runs on the host so the room hears one narrator instead of fifteen slightly out of sync ones. The tone is pure Jackbox: dramatic, a little smug, and happy to make fun of you for dying.

The trick to keeping it from getting old was writing a big pile of lines for each moment and picking randomly. Night one does not read the same way twice. I also gave the narrator a few emotional presets by nudging the pitch and speaking rate, so an ominous line at midnight sounds different from a cheery one at dawn when somehow everybody survived.

Surviving a dropped phone

Phones fall asleep, tabs get backgrounded, someone walks into another room and loses signal. If the game fell apart every time that happened, it would be unplayable. So reconnecting is the default. The connection retries on its own, and if you get fully knocked out, you just rejoin with the same name and drop right back into your seat with your role intact. It is a small thing that quietly saved a lot of games.

What is next

There is a running list. More roles to widen the strategy, maybe a way to keep stats between games, and steady polish on the writing so the narrator keeps surprising people. And more of these posts, since apparently I enjoy writing them.

If you made it this far, the least you can do is round up some friends and go get accused of a murder you did not commit.

Play a game