Skip to content

GrassKhoPper/database_hw

Repository files navigation

Database Management Systems course project

Project theme : Online service for digital distribution of computer games and programs

Project Description

GameHub is an educational project demonstrating the work of a distributed system using PostgreSQL, microservice architecture and Docker. The project includes:

  • Game Store (store-service): allows users to view games, add them to the cart, and make purchases.
  • Banking service: processes transactions and manages the balance of users.
  • Database: stores data about users, games, studios, tags, purchases, and media content.

Stack : Docker, Python, PostgreSQL, HTML, CSS, Javascript.

Generate test data

Requierements for generator:

  • python3
  • python-pillow

To generate random test data use(modify before running constants in deGenerator.py file):

python3 tools/deGenerator.py

This utility will generate a set of initializing data for the store's database and put it in a set of initializing csv files.

Variable parameters

Below is a list of variable generator parameters:

USERS_COUNT  = 100       # amount of users generated by the rule "user_name:password" username<id>:username<id>, where <id> from 1 to USERS_COUNT
STUDIO_COUNT = 10        # amount of studios with names studio<id>, where <id> from 1 to STUDIO_COUNT
TAGS_COUNT = 20          # amount of tags with names tag<id>, where <id> from 1 to TAGS_COUNT
GAMES_COUNT = 100        # amount of games with names game<id> from random studio from above, where <id> from 1 to GAMES_COUNT
MAX_SCREENSHOT_COUNT = 8 # amount of max-screenshot for one game. A number up to MAX_SCREENSHOT_COUNT is selected for each game.
GAME_TAGS_COUNT = 1000   # amount of associations of random tags created earlier with random games created earlier.
PURCHASES_COUNT = 1000   # amount of created purchases. With chance 50% create purchases with ts = NULL ( game in cart, not in library ) for random users.

Environment set

You need to set environment variables into .env file like this

STORE_DB_NAME=store-db
STORE_DB_PSWD=store-pswd
STORE_DB_USER=store-user

BANK_DB_NAME=bank-db
BANK_DB_PSWD=bank-store
BANK_DB_USER=bank-user

DB_PORT=51488

About bank-service api ( for more information, see the wiki page )

How to get user balance ( example )

curl --insecure -X GET -H 'Content-Type: application/json' -u "seregga:seregga" "https://127.0.0.1:5001/api/balance"

How to add account in our great bank ( example )

curl --insecure -X POST -H 'Content-Type: application/json' -d '{"uuid" : "test", "password" : "test"}' "https://127.0.0.1:5001/api/add-account"

How to delete bank account ( example )

curl --insecure -X POST -H 'Content-Type: application/json' -u "test:test" "https://127.0.0.1:5001/api/delete-account"

How to transfer money from one account to another ( example )

curl --insecure -X POST -H 'Content-Type: application/json' -u "test:test" -d '{"uuid_to" : "seregga", "amount" : 500 }' "https://127.0.0.1:5001/api/transfer"

Return codes for bank api service

  • 401 : authorization failed
  • 402 : wrong requested data
  • 404 : wrong request

About store-service API (for more information, see the wiki page)

Possible ways to launch a project

Running services in docker on a local machine.

Requirements list for docker running:

  • docker
  • docker-compose
  • openssl ( create certificates for your services )
  • curl ( interaction with bank service )

How to run service in docker:

# create test data (optional)
python tools/deGenerator.py 

# store.crt and store.key files for store service
cd store-service/
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout store.key -out store.crt
cd ..

# bank.crt and bank.key files for bank service
cd bank-service/
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout bank.key -out bank.crt
cd ..

# run containers in daemon mode
docker compose up --build -d

# stop services
docker compose down

# clear database volume
docker compose down --volumes

Running services on local machine (for example, in systemd-nspawn)

Running systemd-nspawn container (and creation)

sudo debootstrap noble ./ubuntu-sandbox
sudo mount --bind ./ubuntu-sandbox ./ubuntu-sandbox
sudo chroot ./ubuntu-sandbox

passwd # set password for root in container
exit

sudo systemd-nspawn -b -D ./ubuntu-sandbox

After that you need to change /etc/resolve.conf for nameserver 8.8.8.8 and /etc/apt/source.list for :

deb http://archive.ubuntu.com/ubuntu/ noble main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ noble-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ noble-backports main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ noble-proposed main restricted universe multiverse

Install dependencies

# install utils for os 
apt install -y python3 libssl-dev nginx python3-pip python3-venv postgresql
python3 -m venv /opt/venv
export PATH="/opt/venv/bin:$PATH"

# install python requirements.txt
CFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" UWSGI_PROFILE_OVERRIDE=ssl=true pip3 install --no-cache-dir -r store-service/requirements.txt
pip install --no-cache-dir -r bank-service/requirements.txt

Run services (it is important at this stage to already have initialized environment variables (as in the dotenv file!!!) :

# run bank service
cd bank-service
python app.py

#run store service
cd store-service
uwsgi --ini uwsgi.ini

Special utilities for testing this project.

These utilities are stored in the tools directory.

  • deGenerator.py : generator of test data for store-service with some variables parameters;
  • DOSer.py : checking for resistance to basic DOS;
  • tester.py : running a specific sql query to a specific database from python-psycopg3.

Our team:

  • Gubanov Peter (@gubanovpm)
  • Khrol Ivan (@ent1r)
  • Potapova Anna (@ann37)