I wanted a quiz show that runs inside a TikTok LIVE stream. Viewers type their answers in the chat, the fastest correct answers score the most, and gifts can change what happens next. The whole thing is in Indonesian, with categories like football, Indonesian and world history, science, maths and a "guess the animal" round with sound clips. Later I added an English mode with its own questions.
It's a side project, so I could build it the way I wanted. Here's how it's put together.
Two parts: a game server and an overlay
The backend is NestJS with SQLite through Drizzle. It connects to the live stream with a TikTok LIVE connector library, which emits chat messages and gifts as events, and it owns the game: the current round, the question, the timer, the scores.
The frontend is a Next.js page sized for a portrait stream, 1080×1920, that I add to the broadcast as an overlay. It shows the question, the countdown, the leaderboard and the animations, and it gets updates from the game server in real time. There's also an admin side for managing categories and questions.
The game's rules live on the server; the overlay's job is to show what the server says.
Answers are typed, not picked
There's no multiple choice. Viewers type the answer in the chat, and the server compares it without caring about upper or lower case, so nobody can win by guessing A, B, C or D.
The order of correct answers matters. The first three get the most points, everyone after gets a smaller fixed amount:
const POINTS = [100, 75, 50];
const LATE = 25;
function pointsFor(place: number) {
return POINTS[place] ?? LATE;
}
function onChat(round: Round, viewer: string, text: string) {
if (round.closed || round.answered.has(viewer)) return;
if (normalize(text) !== normalize(round.answer)) return;
round.answered.add(viewer);
addScore(viewer, pointsFor(round.answered.size - 1));
}
Gifts follow a rule table
Gifts are where a live game earns its keep, but I didn't want every gift to do the same thing. Each gift has a row in a rule table that says what it does: boost a vote (for example, which category comes next) or buy a cosmetic effect for the viewer's character. Cosmetics have a minimum price, so they don't feel cheap, and they last for a set number of rounds.
type GiftRule = { gift: string; effect: "vote" | "cosmetic"; weight: number; minCoins?: number };
function onGift(rules: GiftRule[], viewer: string, gift: string, coins: number) {
const rule = rules.find((r) => r.gift === gift);
if (!rule) return;
if (rule.effect === "vote") return boostVote(viewer, rule.weight);
if (coins >= (rule.minCoins ?? 0)) grantCosmetic(viewer, gift);
}
Gift votes are counted with a short delay before the result is locked, so gifts sent right at the end of a vote still count.
The show around the questions
Most of the work after the game was playable went into making it feel like a show: a podium for the top three, a leaderboard that keeps the top three fixed while the rest scroll, pop-up animations when a gift lands, transitions between rounds, a waiting screen, and a per-round toggle for a random category. Round winners appear on stage as 3D characters with the viewer's profile picture as the face.
What I'd keep
If I started again, I'd keep the same split: the server decides, the overlay shows. Scoring, gift rules, timers and rounds all live in one place, and the overlay stays a screen.