It is vital to see how data is going to be structured in Mini Kahoot before designing the backend API. This determines what data the backend should expect and what data it should send back in responses.
For this project, I've decided to use MongoDB as the chosen databases.
Why I've chosen MongoDB:
Mini Kahoot consists of three collections:
Each document in this collection represents a single question with the fields below.
{ question: string, options: string[], answer: number, tags: string[], vector: number[] }
Explanation:
question
The text of the question itself.options
Array for the answer options.answer
Stores the index of the correct answer in options
tags
Array of the question tags. Tags are used to specify the topics a question is about.vector
Vector embedding of the question text. This is for when descriptions need to be matched to relevant
questions.The Games collection represents active game sessions.
{ gameId: number, questions: Question[] players: Player[], round: number, roundStart: number, answeredInRound: number, state: string (ENUM) }
Explanation:
gameId
ID of the game. This is the code players will enter to join this game.questions
List of questions the game has. I decided to embed full question documents instead of question IDs to
remove extra database calls to fetch the question in live games.players
List of players connected to the game. This is also embedded as players are always tied to a game and
won't be referenced outside one.round
The round/question the game is currently on.answeredInRound
Number of people who have submitted an answer in the current round. This will be used to determine
if game rounds can end early or not.state
Enum for the current state of the game.
Seen in the Games collection, a document in the players collection represents a player in an active game.
{ name: string, score: number, token: number, isHost: boolean }
Explanation:
name
The player’s display name.
score
The player’s current score within the game.
token
A unique numeric token used by the server identify the player in the game session.
isHost
Boolean flag indicating if this player is the host of the game.
That's all the data modelling needed for Mini Kahoot!
The next post will cover API design, using these database models to determine how data is received and responded with.