API Contracts
This page contains all of our contacts for the RESTful API and Web Socket service, as well as data flow diagrams.
Flow of data
Flow of Data in the project
This is how data flows through out system from a technological point of view. We have a NextJS frontend, that communicate to AWS Lambda functions via AWS API Gateway. We are utilizing various other AWS services; such as AWS DynamoDB, AWS ElastiCache and AWS Cognito.
Error
Status Code: 4XX | 5XX
Create Game
Flow of Create Game
Request POST /createGame
Response 200 OK
Web Socket
Once a game has been created, the user will need to make a request to the WebSocket server that links the gameID to the user’s connection ID (provided by WebSockets, not part of the request body) and marks this user as the host.
Join Game
Flow of Join Game
Request that the students make to join in on a game.
Request POST /joinGame
Response 200 OK
Web Socket
If the request was successful, the client will need to make the following websocket request:
This will then linked the player ID, socket ID, player role and game ID in the connections database.
Start Game
Flow of Start Game
The game host should make this web socket request in order to get the game started, it will be broadcasted to all players.
Web Socket
This will then go through the connection table, getting all of the connection ID’s for the provided game ID. It will then broadcast a message out to all those clients saying that the game is about to start.
Start of Round
Flow of Start Round
The game will be managed by the host, so that means all actions will be initiated by the host. All starting round messages will be triggered by the host. The host as well as the web socket server should always remain in sync with the data, but the host is final source of data. That means the host will be the timer of the rounds, as well as triggering the respective messages.
There will need to be a timer running on the hosts client that keeps track of how long things are. We could even look at providing toast notifications about how much time is remaining, but that is a QOL for later.
The hosts client will be the initator of all the web sockets in relating to the rounds.
If the current round is greater than 1, it sound process the already existing games from the ElastiCache. It should process all of them and then do one large batch update to the DynamoDB. Have a look at Process Round.
Web Socket
A start round message will be sent to all players in the game. It will include the round number (the round that is starting), when the round is starting and the duration of the round (in seconds).
End of Round
Flow of End of Round
This request will be initated by the game host and broadcast to all players of the game that the round is over and that they should send their data to the server.
Web Socket to Client
Request initated by the game host, indicating that the round has ended. For this, there is X amount of time (represented in seconds), where the player - whatever their role - will do their actions relating to their role. Such as deciding the tax rate, reimbursing roles and handling audits. The player (role B and C) will also have a chance to be audited. That all gets dealt with during this time period.
Web Socket to Server
The client will be notified that the round has ended and needs to send the following data back.
When a player sends their data in, it is simply just written to an ElastiCache instance, where it will be processed later on by the Process Round RESTful route.
Finish Game
When the game is finished, players should be displayed information and statistics. More information to come.
Request
Response
Web Socket
Should broadcast to all connected clients that the game has been finished.
Process Round
Restful API route to process the previous round. Will fetch all player data from the ElasticCache, process it and then batch update the DynamoDB for the current.
Request GET /process/:gameID/:roundNumber
Response 200 OK
Fetch player from Game
Restful API route to fetch a specific player for a game.
Request GET /games/:gameID/:playerID
Response
Errors
Games
Fetches all games
Request GET /games
Response
Fetch a game
Fetch a specific game
Request GET /games/:gameID
Response
Fetch Consent from
Fetches the consent form.
Request GET /consent
Response
Update Consent Form
Updates the consent form.
Request POST /consent
*Response
CSV
Returns the game object as CSV
Request GET /games/:gameID/csv
Response
The game object as CSV with the “Content-Type” as “text/csv”.
XLSX
Getting the data in a way that frontend can generate it into an XLSX.
Request GET /games/:gameID/xlsx
Response
Latest Game
Fetch the latest game and its config.
Request GET /games/latest
Response
Game Configs
Everything relating to the game Configs
Fetch all Configs
Fetch all game Configs
Request GET /games/configs
Response
Fetch specific config
Fetch a specific config
Request GET /games/configs/:id
Response
Add a new config
Create a new config based on the body you pass in.
Request POST /games/configs
Response
Get latest config
Fetches the latest config that was craeted.
Request GET /games/configs/latest
Response
Update player
Update a player in the redis
Request POST /update/player/:gameID
Response