On this page
Trivia night works best when everyone answers on their own phone and the scores appear on one screen for the dramatic reveal. This brief covers a host who writes ten questions, a short join code that friends type in, timed rounds and a live leaderboard. It needs a shared backend, so the plan is to connect your own Supabase for rooms, answers and realtime updates. Android comes first in the build order, iPhone uses the same Supabase project, and the iPhone app needs a Mac with Xcode to build. The proof is one real game with three phones in the same room.
Screens
- Host setup: Write questions, four options each, and mark the correct one
- Lobby: Show the join code and players as they arrive
- Question: Display the prompt, options and a countdown on every player phone
- Leaderboard: Reveal scores after each question with movement up or down
- Join: Enter a code and a nickname, nothing more
Data model
| Table | Key fields | Purpose |
|---|---|---|
| games | id (uuid), host_id (uuid), join_code (text unique), status (text), current_question (int) | One trivia session and where it currently is |
| questions | id (uuid), game_id (uuid), position (int), prompt (text), options (jsonb), correct_index (int) | The host's question set in play order |
| players | id (uuid), game_id (uuid), user_id (uuid), nickname (text), joined_at (timestamptz) | Everyone who joined this game with the code |
| answers | id (uuid), player_id (uuid), question_id (uuid), choice (int), answered_at (timestamptz), points (int) | One locked answer per player per question |
Use anonymous sign-in on your own Supabase so a nickname maps to a real session without a password. Row-level security must hide correct_index from players until the host reveals the question, otherwise a curious friend can read answers from the network. Insert answers through a database function that checks the question is open, rejects a second answer from the same player and calculates points on the server from the deadline, never from a timer value the phone reports.
Native features
The live feel comes from Supabase realtime channels: the host changes the game status and every phone moves to the next question together. Phones should still recover if one drops off Wi-Fi for a moment, by reloading the current question from the database instead of trusting missed messages.
| Feature | Android (Kotlin) | iPhone (SwiftUI) | Notes |
|---|---|---|---|
| Live game state | supabase-kt Realtime channel collected into a StateFlow | supabase-swift Realtime channel driving an @Observable model | Treat realtime as a hint and always refetch the current question after reconnecting. |
| Inviting friends | Share sheet with the join code and a deep link | ShareLink with the code | The code alone must be enough; links are a convenience. |
| Answer feedback | Short vibration on lock-in | UINotificationFeedbackGenerator on reveal | Do not reveal correctness until the host does. |
Android notes (Kotlin and Jetpack Compose)
Model the player screen as a sealed state: Joining, Lobby, Question, Locked, Reveal and Finished. A ViewModel subscribes to the game row and switches state from the server status, so tapping fast or rotating the phone cannot push a player ahead of the room.
- Render answer options as large Material 3 buttons that disable after one tap, and show the remaining seconds computed from the server deadline minus the current time.
- Keep the nickname and last game ID in DataStore so a player who swipes the app away can rejoin the same game with their score intact.
- With three real phones on one network, have one player turn on airplane mode during question four and back off during question five. They should land on question five with an honest missed answer, not a crash or a duplicate player.
iPhone notes (Swift and SwiftUI)
Drive navigation from the game status rather than from button taps: a NavigationStack path derived from status keeps every iPhone in step with the host. Use a large monospaced timer so the countdown is readable across a table.
- Subscribe to the realtime channel in a task tied to the view lifecycle and resubscribe when scenePhase returns to active.
- Animate leaderboard rows with matched geometry so position changes are visible, but keep text sizes compatible with Dynamic Type.
- On a physical iPhone, join a game started on an Android host, answer every question, lock the phone during one round and confirm the app catches up when unlocked without awarding late points.
Copy-paste prompt
Build a trivia night app for my friends: I type 10 questions, everyone joins on their phone with a code, and there's a live leaderboard after every question. Make it a native Android app connected to my own Supabase project. Screens: Host setup, Lobby, Question, Leaderboard and Join. Use anonymous sign-in with a nickname. Store games, questions, players and answers, and protect them with row-level security so players cannot read correct answers before the reveal. Accept one answer per player per question through a server function that checks the deadline and calculates points on the server. Use realtime updates so every phone moves to the next question together, and refetch the current question after any reconnect. Show lobby, waiting, locked-in and finished states, plus clear errors for a wrong code, a full game and a lost connection. For acceptance, run a game with three phones, drop one off Wi-Fi mid-round, and confirm scores match the answers stored in the database.
Opens Apirex with this prompt in the box. Pick the Android · Kotlin tab before you send.
Acceptance test
- As host, write three questions and start a game; confirm a short join code appears in the Lobby.
- Join from two other phones with nicknames and check both appear in the host Lobby within a couple of seconds.
- Answer the first question on each phone, one correctly, and confirm the leaderboard reveal shows the right points.
- Tap an answer twice quickly on one phone and verify only one answer row exists for that player and question.
- Disconnect a player during a question, reconnect after it closes and confirm they see the current question with no late points.
Check the security rule directly: from a player session, query the questions table during an open round and confirm correct_index is not returned. Then end the game and confirm the final leaderboard is computed from stored answers, so refreshing the host screen gives the same order every time.
Frequently asked questions
Do friends need an account?
No password is needed. Anonymous sign-in on your own Supabase gives each phone a session tied to its nickname, which is enough to keep one answer per player.
Can the questions be generated for me?
This version uses questions you write. Adding generated questions is possible later, but the host should still review them for accuracy before a game.
What happens if the host loses connection?
The game state lives in the database, so the host can reopen the app and continue from the current question. Players stay on their screen until the status changes.
Build this blueprint
The blueprint prompt, ready for your platform. Edit anything before you send it.
Opens Apirex with this prompt. Pick the Android · Kotlin tab before you send. The Free plan includes 5 Rex Credits a day.