This repository is my delivery of the home exam in the subject PG6300 Web Development and API Design. "Curriculum" and code inspiration can be found in Andrea Arcuri's (lecturer) repository found here.
General: The application is an online multiplayer quiz game. After the users has logged in they can either create a new quiz in the quiz page or start playing in the game page. When the players are ready to play, they will enter a game lobby.
Game lobby: The person who joins first will become the host of the lobby, and will have the authority to start the game once another player has joined. Everyone in the lobby will get a list of the current players in the lobby.
Game: After the game has begun, a quiz in the database is chosen at random and the lobby is removed (allowing parallel matches). For each question, the players will be presented with a timer, a question and four answers to pick from. The players get 3 points if the answer is correct, and 0-2 points depending on the time it took to answer. If the player fails to answer the question within 10 seconds, the question is skipped and no points is given. The game will progress like this until there are no more questions in the quiz. When the quiz is done the results are presented, with the winner on top.
Represent the frontend and is structured like so:
- client: Holds logic applying to all pages.
- home: Landing page. Either register/login page, or navigation.
- game: Game page. Play game.
- quiz: Quiz page. Create quizzes.
Represent the backend and is structured like so:
- server: Holds logic applying to all sub-components.
- api: Entry points to backend.
- game: Game logic.
- ws: Websockets. Real-time updates.
The application is written with the MERN-stack in JavaScript and is built with webpack/babel.
Libraries/tools:
- Passport: Authentication.
- Socket.io: Real-time communication
- Eslint + prettier: Used to ensure consistent code style and conventions.
- MongoDB: Data storage
The frontend is a Single-Page-Application using React + React-Router.
The backend is a single NodeJS instance serving both the frontend and backend. The backend uses a MongoDB docker container as database.
Libraries:
- Express: Web Framework. Used for client communication.
- bcrypt: Password encryption
- Mongoose: Object Data Modeling for MongoDB
- Node/Npm
- Docker installed and running
- Docker-compose
- Modern web browser (application has been tested and developed in chrome/firefox)
npm install
npm run build
npm run db
npm start
When done: npm run stop
or docker-compose down
(shut down DB).
Note:
- On start, placeholder data is created for convenience. Therefore, restarting the application without resetting the db/container will result in duplicates.
npm run db
is setting up a docker container in the background. If pulling the image takes too long, then it might happen concurrently with the application starting. To remedy this, there is a retry-policy in place. You should therefore look for:Connected to MongoDB
. The application may not work until you see this message.
Application can be reached at: https://pg6300-web-exam.herokuapp.com/. Note: mLab is used as a Database-as-a-Service instead of using a docker container.
Time limitations and exam scope makes this project not 100% done. Below is what further development would have involved:
- Improve the feedback to the user. Currently window.alert() is used for notifying users, which is a bad practice. The feedback from the backend to frontend is also lacking. Where there are details happening that should be reflected to the client such as users leaving midgame etc.
- The pages are pretty barren. The "plan" would be to include more stuff to do/see on each page and improve the design.
- The game section should allow the players to create their own lobbies with it's own ID similar to "Kahoot!" and the ability to choose between quizzes. In order to achieve this I would have used socket.io rooms.
- The quiz section is not done and is lacking some functionality. Currently you can only create a quiz with a single question (or use the API), which is not ideal. The quiz section should also allow you to do all CRUD-operations.
- The way the backend is designed is not robust enough. I'm sure there are ways to ensure that the backend crashes or is stuck if you put some effort in it, and I don't think there would be a way for it to recover without a reboot.
- The codebase could use some structural and semantic changes. The way it is structured now has some code smell and could use some improvements.
- A leaderboard/highscore system for quizzes and individual players.