Skip to content

Acile067/Project_DRS_Social_Media

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Social Media

This project was developed as part of a course at the Faculty of Technical Sciences in Novi Sad, for the subject Distributed Computer Systems.

Social Media is a full-stack application designed for connecting users. It features secure user authentication, post sharing, and admin functionality. This project demonstrates how to build and deploy a Dockerized full-stack application with Flask, Angular, MySQL, and Docker.

Built using

Installation:

To run this project, make sure you have the following installed:

After installing these dependencies, follow the setup instructions to get the project running.

How to run:

Running with Docker

The easiest way to run the application is by using Docker

  1. Clone the project:

    Clone the repository and navigate to the Project_DRS_Social_Media project directory:

    git clone https://github.com/Acile067/Project_DRS_Social_Media.git
    cd Project_DRS_Social_Media/backend
  2. Build docker image (backend):

    docker build -t my-python-app .
  3. Build docker image (frontend):

    cd ..
    cd frontend/DRS_frontend
    docker build -t angular-app .
  4. Create docker network:

    docker network create my_network
  5. Run docker containers:

    docker run --name mysql_db --network my_network -e MYSQL_ROOT_PASSWORD=MySQLPassword1 -e MYSQL_DATABASE=appDB -p 3307:3306 -d mysql:8.0
    docker run --name python_app --network my_network -p 5000:5000 -d my-python-app
    docker run --name angular_app --network my_network -p 4200:4200 -d angular-app
  6. Migrate tables:

    Before migrating the tables, you need to connect to the database and create the appDB database.

    Create a new connection in MySQL Workbench using the following settings:

    • Port: 3307
    • Password: MySQLPassword1

    Create the appDB manually then type

    docker exec -it python_app /bin/bash
    flask --app app.app db init
    flask --app app.app db migrate
    flask --app app.app db upgrade
  7. Add admin in db:

    Fill in a row in the table to create an admin with the following values:

    • isAdmin: yes
    • isNewUser: no
    • RejectedPostCount: 0
    • Email: x@x
    • Fill in the remaining fields as desired (fields must not be null).
Running Locally

Alternatively, you can run the project locally.

  1. Clone the project:

    Clone the repository and navigate to the Project_DRS_Social_Media project directory:

    git clone https://github.com/Acile067/Project_DRS_Social_Media.git
    cd Project_DRS_Social_Media/
  2. Run frontend:

    You must have Angular installed globally to run the ng serve command.

    To install Angular globally, use the following command:

    npm install -g @angular/cli
    cd frontend/DRS_frontend
    npm i
    ng serve

    If ng serve does not work, try running:

    npm run ng serve
  3. Create database:

    Create a local database on port 3306 with the password MySQLPassword1. You can use a different password, but it is important to remember it.

    Create the appDB manually.

  4. Run backend:

    Navigate to the backend folder.

    py -m venv .venv

    or

    python -m venv .venv

    or

    python3 -m venv .venv

    It depends on the version of Python you have.


    cd .venv/bin

    or

    cd .venv/Scripts

    ./activate
    cd ../../

    Replace the following line:

    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root:MySQLPassword1@mysql_db:3306/appDB'

    with this one:

    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root:MySQLPassword1@127.0.0.1/appDB'

    It is important to set the correct password (MySQLPassword1).

    This change can be made in the app.py file.


    pip3 install -r requirements.txt
    cd app
    flask db migrate
    flask db upgrade

    RUN run.py

    cd ..
    py ./run.py
  5. Add admin in db:

    Fill in a row in the table to create an admin with the following values:

    • isAdmin: yes
    • isNewUser: no
    • RejectedPostCount: 0
    • Email: x@x
    • Fill in the remaining fields as desired (fields must not be null).

Common Issues:

Q1: What if I encounter an error during table migration?

A1: Ensure the database appDB is created and the password in app.py matches the MySQL credentials.

Q2: The migrations folder is causing issues

A2: Feel free to delete it, as well as the alembic_version table in the database, and try running the migration again.