Table of Contents
This project is a web application built for a computer science course at Babes Bolyai University
- React
- Django
- Postgres
- Nginx
- Cerbot
- Redis
This guide will walk you through the steps to set up a development or production environment.
This project requires npm, Docker, and Docker Compose.
- Docker: Visit Docker's website and follow the instructions to install Docker and docker-compose for your operating system.
- npm: Install npm using nvm from nvm's GitHub page. Make sure to install npm version 7.7.6 or higher.
-
Clone the repo:
git clone https://github.com/UBB-SDI-23/lab-5x-dpie2303
-
Copy the .env.template files from the server and ui_music directories and rename them to .env.
Configure the environment variables for the server, database, and hosting servicesPOSTGRES_USER= # Username for Postgres POSTGRES_PASSWORD= # Password for Postgres POSTGRES_DB= # Database name DOMAIN= # Domain for Let's Encrypt Production only EMAIL= # Email for Let's Encrypt Production only DEBUG= # True or False
Setup base URL's for the frontend application.
REACT_APP_API_BASE_URL=http://localhost:8000 # example for development env REACT_APP_SOCKET_BASE_URL=ws://localhost:8000 # example for development env
-
To set up a development environment, start the server and database in the server directory:
docker-compose -f docker-compose-dev.yml build docker-compose -f docker-compose-dev.yml up -d
Then, in the ui_music directory, execute:
npm install npm start
-
Setting up a production environment
In the server directory execute the fallowing commands to prepare the SSL certificates for the initial run:
docker-compose -f docker-compose-initiate.yml build docker-compose -f docker-compose-initiate.yml up -d docker-compose down
After the certificates for the HTTPS connection are created, start the Docker Compose setup:
docker-compose -f build docker-compose -f up -d
For the deployment and hosting of the frontend application, use Netlify. Refer to their documentation for setup instructions.
Do not forget to setup the enviroment variabiles! -
Finalize the setup:
docker ps # get the server container id docker exec -it <container id> bash python manage.py migrate # migrate the models to the db
To stop your application, in the server directory execute:
docker-compose down
-
Optional!
This aplication contains a setup to populate the database.
Make sure that your do this setup before you do any actions on the apllication.
Adjust the number of entities created by modifying the script in server/music_libraryStart the backend setup using the previous steps. Create the .sql files that contain the artificial data.
docker ps # get the server container id docker exec -it <container id> bash python music_library/generate_sql.py
This may take a while depending on the number of entities and your computer's performance.
To execute the .sql files and populate the db, execute the following:docker ps # get the db container id docker exec -it <container id> bash chmod +x sql_scripts/populate_db.sh ./sql_scripts/populate_db.sh
Your database should be populated now!
- django-debug-toolba: Great for debugging, but can add overhead and expose sensitive data if not disabled in production. Available only wehn DEBUG is set to True.
- djangorestframework_simplejwt: Provides JWT authentication. but it has limited customization options.
- scikit-learn: Implements NearestNeighbors for playlist recommendations, but while it provides accurate recommendations, the prediction part can be slow, especially for large datasets.
- daphne: Starts the server using ASGI but is less widely used and documented than other servers.
- axios: Easy-to-use rest API client, but larger and slower than the native fetch API.
- mui/material: Popular React UI framework, but can be heavy for simple projects and its design might not suit all.
These tools are used to create a proxy server and ensure HTTPS connection.
Redis is used as a communication layer for the Django application, enabling multiple Django threads to communicate with each other using a web socket connection. While Redis is fast and efficient, it requires careful management of data persistence and memory use.
The chron job is runing each 60 days to renew the SSL certificat.
This code is made to work on a VM with 1 GB of RAM and 1 CPU core.
When registering to the app the code to confirm the authenticity of the user is sent to the UI. A steep to send the confirmation code via email needs to be implemented.
There are 3 types of users: admin, moderator, regular. The form of the users generated by pupulation script are, admin_[user index], moderator_[user index], regular_[user index] and the password is Passowrd.123