Skip to content

This is a simple game I created to learn more about web development, with a focus on API development and NoSQL database design

Notifications You must be signed in to change notification settings

foongsq/money-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Money Game

Purpose of this game

The purpose of this simple game is to allow me to get familiar with api development and NoSQL database design.

How the game works

Upon signing in to the game, users can press a button labelled Work to earn coins. Users can then use the coins they have earned to buy things from a store. Upon buying an item from the store, the item will be added into the user's inventory, where they can choose to sell the item for coins.

The original motivation behind this game was crypto/NFT related. However, I wanted to keep the game as simple as possible so that I can focus on learning backend programming.

Infrastructure

Technological Stack:

tech stack

Frontend

Frontend mock ups

Note: This app was only designed to be used on mobile, not on desktop.

frontend mockup normal users frontend mockup admin frontend mockup authentication

Page Interactions

This diagram shows the 3 pages of our application and what are the possible routes users can take to navigate around our application.

page interactions

State management

To improve user experience and performance of our application, we have to manage the flow of data and manage the state of our application well. We should aim to reduce the number of unnecessary API calls made. This diagram shows the data needed in each page.

state management

API Calls

To ensure that we are making only the most necessary, I have drawn out this diagram to plan which API calls to make upon each user interaction.

api calls

I have noticed that most of the API calls are quite straight forward, and the only place I think we could optimize is by:

  • Don't call update money endpoint upon each click of Work button. (either accumulate a certain number of clicks or a certain amount of time before calling API)
  • Isolate the re-rendering of components to only the sections with changes
  • Cache store items (the benefit of this is if someone signs in as a normal user, then sign in as admin, it will be faster for them as they dont have to fetch the store items again. But I think the benefits of this outweighs the cost of implementation and it doesn't make a lot of sense to do this optimization.)

CSS Classes Documentation

I decided to document the layout of my CSS classes because I used to always spend a lot of time figuring out the layout of my css classes again and again. I think that documenting it like that can help me save a lot of time when styling my components.

dashboard css admin css authentication css

Vue Project setup

Install dependencies: npm install

Compiles and hot-reloads for development: npm run serve

Compiles and minifies for production: npm run build

Lints and fixes files: npm run lint

Customize configuration: See Configuration Reference.

Backend

Database Schema:

  • Authentication: unique username and password to signin
  • Money
  • Inventory: itemid, picture, quantity, sell price
  • Store: itemid, picture, buy price

database schema

Abstract backend API used by normal users

  • /user: POST method that takes unique username, password, and creates a user in the database, returns userId
  • /session: POST method that takes username, password, returns userId
  • /session: GET method that uses cookie info to fetch user info
  • /session: DELETE method to sign out, to delete jwt cookie
  • /money: POST/UPDATE method that takes userId, and updated money
  • /inventory: GET method that gets all items in inventory
  • /store: GET method that gets all items in store
  • /inventoryItem: POST/UPDATE method -> buy; decrement money; if item in inventory, increment quantity by 1; else, add item;
  • /inventoryItem: POST/UPDATE method -> sell; decrement quantity; increment money

Abstract backend API used by admin

  • /user: POST method that username, password, returns userId of admin
  • /store: GET method that gets all items in store
  • /storeItem: POST method that uploads new item to store (picture, name, price, auto snag id)
  • /storeItem : DELETE method that deletes an item from store

Backend features

  • hashed passwords
  • enforce unique usernames
  • jwt authentication

Backend Infrastructure:

backend infrastructure

API Project setup

All sequences of commands are assumed to be run from the root directory.

Activating python virtual environment:

cd api/Scripts
activate

Install dependencies:

cd api
pip install -r requirements.txt

Run server:

cd api/routes
python app.py

References

Additional Libraries/Packages used

Information sources

About

This is a simple game I created to learn more about web development, with a focus on API development and NoSQL database design

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published