Skip to content

morrisonak/Trivia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trivia Nights

A real-time multiplayer trivia game where players compete head-to-head with timed questions, speed-based scoring, and live leaderboards. Built for parties, game nights, and casual fun.

Live App: https://trivia-app.jmorrison.workers.dev

Features

  • Real-time multiplayer — Create or join game rooms with 4-character room codes
  • Timed questions — 15 seconds per question with speed-based scoring
  • Streak bonuses — Earn extra points for consecutive correct answers
  • Big Board display — Connect a TV or monitor as a spectator display for parties
  • Play Again — Seamlessly start a new game with the same group
  • Mobile-friendly — Touch-optimized interface with responsive layouts

How It Works

  1. Host creates a game — Chooses player count and number of questions
  2. Players join — Enter the room code and a display name
  3. Host starts — Game begins when everyone is ready
  4. Answer questions — Timed multiple choice with instant feedback and commentary
  5. See results — Final rankings with scores, accuracy, and streaks

Tech Stack

Getting Started

Prerequisites

  • Node.js 18+
  • Cloudflare account with Wrangler CLI access

Installation

npm install

Database Setup

  1. Create the D1 database (if starting fresh):
npx wrangler d1 create trivia-db
  1. Apply migrations:
npx wrangler d1 execute trivia-db --remote --file=./drizzle/0000_*.sql
  1. Seed the question bank:
# Hit the seed endpoint after starting the dev server
curl -X POST http://localhost:3003/api/seed

Development

npm run dev

The app runs at http://localhost:3003. Dev mode uses --remote to connect to the production D1 database.

Deploy

npm run build && npm run deploy

Architecture

The app uses two complementary Cloudflare storage layers:

  • D1 — Persistent data: questions, game records, player answers, scores
  • Durable Objects — Real-time ephemeral state: WebSocket connections, timers, live game orchestration

During lobby phase, clients poll for state updates. Once the game starts, all communication switches to WebSockets through the GameRoom Durable Object for instant question delivery, timer sync, and result broadcasting.

Scoring

Component Points
Correct answer 100 base
Speed bonus +10 per second remaining
Streak bonus +50 for 3+ correct in a row

Project Structure

src/
├── routes/                     # File-based routing (TanStack Router)
│   ├── game.create.tsx         # Create game form
│   ├── game.join.tsx           # Join by room code
│   ├── game.$roomCode.tsx      # Game lobby
│   ├── game.$roomCode.play.tsx # Live gameplay (WebSocket)
│   ├── game.$roomCode.results.tsx # Final results
│   ├── display.$roomCode.tsx   # Big Board display
│   └── api.games.*.ts          # Game API routes
├── durable-objects/
│   └── GameRoom.ts             # Real-time game orchestration
├── db/
│   └── schema.ts               # 5-table schema (questions, games, players, answers)
└── lib/
    ├── scoring.ts              # Points calculation
    └── room-codes.ts           # Room code generation

Scripts

Command Description
npm run dev Start dev server (port 3003, remote D1)
npm run build Production build
npm run deploy Deploy to Cloudflare Workers
npm run test Run Vitest test suite
npm run db:generate Generate Drizzle migrations
npm run db:studio Open Drizzle Studio GUI

Learn More

About

Real-time multiplayer trivia game with room codes, speed-based scoring, and Big Board display mode. Built with TanStack Start, Cloudflare Workers, D1, and Durable Objects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors