- Node.js: JavaScript runtime environment
- Express.js: Web application framework for building APIs
- TBD: Database management system (e.g., MongoDB, PostgreSQL, MySQL)
-
User Management:
POST /api/user
: Register a new user or create a guest user if no credentials are provided.POST /api/login
: Authenticate a user and generate an access token. For guest users, a temporary access token can be generated without requiring any credentials.GET /api/user/:id
: Get user profile by ID. This endpoint can return user details for registered users and generic details for guest users.
-
Trivia Management:
POST /api/trivia
: Create a new trivia gameGET /api/trivia
: Get a list of active trivia gamesGET /api/trivia/:id
: Get trivia game details by IDDELETE /api/trivia/:id
: Delete a trivia game and all associated data by ID
-
Trivia Session Management:
POST /api/trivia/:id/start
: Start a trivia session for the specified trivia game IDPOST /api/trivia/:id/join
: Join an existing trivia session by trivia game IDPOST /api/trivia/:id/join/invite-code
: Join an existing trivia session by trivia game invite codePOST /api/trivia/:id/answer
: Submit an answer for the current question in the trivia sessionGET /api/trivia/:id/question
: Get the current question for the trivia sessionGET /api/trivia/:id/scoreboard
: Get the scoreboard for the trivia sessionPOST /api/trivia/:id/next
: Move to the next question in the trivia sessionPOST /api/trivia/:id/end
: End the trivia session and calculate final scores
Syncora-Backend uses JSON Web Tokens (JWT) for user authentication.
The user schema represents the structure of user data stored in the database. Note that a user can create and host a trivia game, while a guest can only join.
id
: Unique identifier for the usertype
: Whether its a user or guestusername
: User's username or display namepassword
: Encrypted password for authenticationcreatedAt
: Timestamp for when the user account was createdupdatedAt
: Timestamp for when the user account was last updatedavatar
: URL or file path to the user's profile pictureownedTrivias
: Array of UUIDS representing the trivias owned/created by the user For example:
{
id: 'user123',
type: 'user',
username: 'john_doe',
password: 'hashedPassword123',
createdAt: '2023-06-01T10:00:00.000Z',
updatedAt: '2023-06-03T15:30:00.000Z',
avatar: 'path/to/avatar',
ownedTrivias: ['c769a982-8d43-4a36-a2b6-3c8c1e3f6b99', '61e09a25-6c23-48ed-8f41-2ff2fd045dc7', '2e7f3c34-79c2-4939-8e72-b2397dd5a48d']
}
The guest schema represents the structure of guest data temporarily stored. Note that a user can create and host a trivia game, while a guest can only join.
id
: Unique identifier for the guesttype
: Whether its a user or guestusername
: Guest's display name For example:
{
id: 'guest123',
type: 'guest',
username: 'john_doe'
}
The trivia game schema represents the structure of a trivia game stored in the database. This schema defines the format of the trivia game data that is persisted in the database.
id
: Unique identifier for the trivia gametitle
: Title or name of the trivia gamecategory
: Category or theme of the trivia gamequestions
: Array of trivia questions associated with the gameid
: Unique identifier for the questiontimeLimit
: The time limit, in seconds, for how long the question is available to be answeredtext
: Text of the questionoptions
: Array of possible answer optionscorrectAnswer
: Index of the correct answer option For example:
{
id: 'trivia123',
title: 'Movie Trivia',
category: 'Entertainment',
questions: [
{
id: 'question1',
timeLimit: 30,
text: 'Who directed the movie "Inception"?',
options: ['Christopher Nolan', 'Martin Scorsese', 'Steven Spielberg', 'Quentin Tarantino'],
correctAnswer: 0
},
{
id: 'question2',
timeLimit: 30,
text: 'Which actor played the character Iron Man in the Marvel Cinematic Universe?',
options: ['Robert Downey Jr.', 'Chris Evans', 'Chris Hemsworth', 'Mark Ruffalo'],
correctAnswer: 0
},
// Additional question objects...
]
}
The trivia session schema represents the structure of a trivia session that is active and stored locally in memory. This schema defines the format of the trivia session data during the live session when players are connected and playing the game.
id
: Unqiue identifier for the trivia sessionstatus
: The current status of the trivia session (e.g., "pending", "ongoing", "paused", "ended")triviaGame
: Reference to the trivia game being played (using the Trivia Game Schema)currentQuestionIndex
: The index of the current question being presented in the trivia sessionplayers
: Array of connected players with their IDs, names, and scoresid
: Unique identifier for the userusername
: User's username or display namescore
: User's current score for the trivia sessionisConnected
: A boolean flag indicating whether the user is currently connected to the trivia session
isPublic
: A boolean flag indicating whether the trivia game is publicly accessible or requires an invitation code to joininviteCode
: A unique code or token that can be used to join a private trivia gamecreatedAt
: A timestamp when the session was created atstartedAt
: A timestamp when the session was started atendedAt
: A timestamp when the session was ended athost
: The ID of the user who is hosting the trivia sessionhostSocket
: The WebSocket server address for the host user
For example:
{
"id": "session123",
"status": "ongoing",
"triviaGame": {
"id": "trivia456",
"title": "Movie Trivia",
"category": "Entertainment",
"questions": [
{
"id": "question1",
"text": "Who directed the movie \"Inception\"?",
"options": ["Christopher Nolan", "Martin Scorsese", "Steven Spielberg", "Quentin Tarantino"],
"correctAnswer": 0
},
{
"id": "question2",
"text": "Which actor played the character Iron Man in the Marvel Cinematic Universe?",
"options": ["Robert Downey Jr.", "Chris Evans", "Chris Hemsworth", "Mark Ruffalo"],
"correctAnswer": 0
}
]
},
"currentQuestionIndex": 0,
"players": [
{
"id": "user123",
"username": "Player1",
"score": 0,
"isConnected": true
},
{
"id": "user456",
"username": "Guest1",
"score": 0,
"isConnected": true
}
],
"isPublic": true,
"inviteCode": "",
"createdAt": "2023-06-05T10:30:00Z",
"startedAt": "2023-06-05T10:32:00Z",
"endedAt": null,
"host": "user123",
"hostSocket": "ws://localhost:3000"
}