This guide walks you through setting up and running the Flask backend server, connecting to your own MySQL database, and migrating the database.
These instructions were written for Windows in mind. Commands may vary slightly between Windows and Mac.
- Python 3.9+
- MySQL 8.0+
- pip 24.3.1+
First, clone the repository to your local machine:
git clone <repository-url>
cd <repository-directory>
cd backendUse pip to install the required dependencies. It is recommended to create a virtual environment before installing:
# Create and activate a virtual environment
py -m venv venv
source venv/Scripts/activate
# Install dependencies
pip install -r requirements.txtCreate a .env file in the backend directory.
Template for the .env file:
# .env
SECRET_KEY=your_secret_key_here
JWT_SECRET_KEY=your_jwt_secret_key_here
DEV_DATABASE_URI=mysql+pymysql://<username>:<password>@localhost/<database_name>
ROOT_URL=root_url_of_frontend # When testing locally: http://localhost:3000
# If you are attempting to run without sendgrid, please put any placeholder values and you will simply lose resetting password capabilities
SENDGRID_EMAIL=your_sendgrid_email_address
SENDGRID_API_KEY=your_sendgrid_api_keyGenerating a SECRET_KEY key: In any terminal
python
import secrets
secrets.token_hex(12)
quit()
Copy the result (without quotation marks) in place of your_secret_key_here
Generating a JWT_SECRET_KEY In any terminal
python
import secrets
secrets.token_urlsafe(64)
quit()
Copy the result (without quotation marks) in place of your_jwt_secret_key_here
Make sure you have MySQL running and create a database:
# Login to MySQL
mysql -u <your-username> -p
# Create a database for the project
CREATE DATABASE <database_name>;To set up the database structure, you'll need to run the migrations. Flask-Migrate is used for managing database migrations.
# Run the migration commands to initialize the database
cd <repository-directory>/backend # Unless you are currently in the backend directory already
flask db upgrade # Apply migrations scriptsNow, you can start the Flask development server:
cd <repository-directory>/backend # Unless you are currently in the backend directory already
py run.pyThe backend server should now be running at http://127.0.0.1:5000/.
The API documentation is automatically generated and can be accessed at:
http://127.0.0.1:5000/api/v1/docs
-
MySQL client installation: Make sure the MySQL client is installed on your machine. You can install it via your package manager:
- On Ubuntu:
sudo apt-get install mysql-client - On MacOS (using Homebrew):
brew install mysql - On Windows: Download and install MySQL client from here.
- On Ubuntu:
-
Virtual Environment Issues: If you encounter problems with the virtual environment, ensure you have activated it (
source venv/bin/activateorvenv\Scripts\activateon Windows).
- Node.js (version 14 or higher)
- npm (Node package manager)
cd <repository-directory>/frontend
npm install
npm start