Git Product home page Git Product logo

kenttrann2302 / studyhub-backend Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 5.99 MB

This repo is for StudyHub (a full-stack web app that helps student to find the study group that fits their needs!) server development. This involves of all streaming APIs that help building and maintaining the application's server!

Python 99.17% HTML 0.42% Mako 0.19% Dockerfile 0.23%
flask aws-lambda aws-dynamodb aws-ses postgresql-database sqlalchemy-orm docker python server

studyhub-backend's Introduction

StudyHub-Backend

Table of Contents

Overview

StudyHub is an online tool that facilitates the development of efficient and productive study groups. It strives to bring together students who have similar study preferences, courses, and locations in order to improve collaborative learning experiences.

Built With

Architecture

  • Below is the snippet of the UML Diagram of our server:
Screenshot 2023-05-16 at 10 09 30 PM

Features

  • User Registration and Authentication: StudyHub provides a user-friendly registration process and secure authentication mechanism, allowing users to create accounts and access the platform securely:
Screenshot 2023-05-15 at 10 58 04 PM
  • User Profiles and Preferences: Users can create personalized profiles, including study preferences, courses, and availability schedules. This information is used to match users with compatible study groups:
Screenshot 2023-05-15 at 11 03 18 PM
  • Study Group Matching Algorithm: StudyHub employs a neural network-based matching algorithm that analyzes user preferences and behavior to suggest the most suitable study groups. This algorithm ensures optimal group formations based on compatibility factors.

  • Google OAuth 2.0 Integration: StudyHub integrates with Google OAuth 2.0 for seamless user authentication, enabling users to sign in using their Google accounts:

Screenshot 2023-05-15 at 11 04 29 PM
  • Email Verification: To ensure the authenticity of user accounts, StudyHub incorporates email verification functionality. Users receive email notifications to verify their email addresses during the registration process, this is done by using AWS SES and Twilio SendGrid:
Screenshot 2023-05-15 at 11 07 29 PM Screenshot 2023-05-15 at 11 07 06 PM
  • API Security: StudyHub implements API security best practices, including JWT tokens and bcrypt hashing, to protect sensitive user data and ensure secure communication between the client and server.

  • Docker Containerization: The application is containerized using Docker, providing an isolated and portable environment for seamless deployment and scalability:

Screenshot 2023-05-15 at 11 09 38 PM
  • AWS and GCP Integrations: StudyHub integrates with AWS services such as DynamoDB, Lambda, and SES for email delivery, along with GCP Geolocation API for address verification:
Screenshot 2023-05-15 at 11 12 53 PM
  • Unit Testing: The codebase includes comprehensive unit tests for the REST APIs, ensuring functionality, reliability, and maintainability.

For development purpose:

Note: If you're using Windows, please clone this repo in WSL and run the docker commands in there.

To clone and run this application you'll need:

Then on your terminal, run the following from the root of this repository:

# Build the images and containers then run the containers
docker compose up -d --build

In order to test the APIs of each endpoint at http://0.0.0.0:8080/, use Postman collections.

To stop the containers and to start the containers after the initial build:

# For stopping and removing the containers created above
# Use the -v flag to remove the associated volumes
docker compose down

# For creating and starting the container
# after the initial build
docker compose up -d

Good-to-Know Commands

Run command in a container

To run shell command in any of the two containers:

docker compose exec <service-name> <command> <list-of-args>

# Example: Running SQL commands in the container
PGPASSWORD=<password> psql -U <username> <database>

# Example: Make backend migrations with Flask Migrations
docker compose exec backend flask db init
docker compose exec backend flask db migrate -m <migration-message>
docker compose exec backend flask db upgrade

We recommend creating alias(es) to shorten the above commands

Common Issues

Database is not up to date after running migration scripts

# By running this command, the database will be up to date with the latest migration
docker compose exec backend flask db stamp head

Import "{framework/library-name}" could not be resolved error from Pylance

If you're using VSCode and see this error. This mean the framework/library was not installed globally or installed in the virtual environment you're using. We highly recommend setting up a new virtual environment. So remove your existing environment in the root of this repository. Then run the following commands

# Ensure you are in the root of this repository
python3 -m venv env # Our gitignore assumes the virtual environment name is env
source env/bin/activate
pip install -r backend/requirements.txt

Then select the interpreter in env/bin/. The issue should disappears.

Note: We assumed you're using MacOS or Linux. For Windows, please find the corresponding command for setting up Python virtual environment.

studyhub-backend's People

Contributors

j-ngo828 avatar kenttrann2302 avatar sumo01665 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

j-ngo828

studyhub-backend's Issues

Streamline development environment

What's the purpose of this issue?

Right now, we need to run two instances of Flask to handle registration flow, and CRUD operations for UserProfile. This is fine if we're building microservices, but there's no reason for them to be microservices when they are this small. To ensure a smoother development process, we will need to unify the two separate apps into one instance of Flask. We will also need to have a way to ensure the database is initialized right when we run the command to start the application.

Code Complete Criteria

  • I can start the development environment with just one command
    • It should initializes the database
    • It should allows me to go through the login flow and perform CRUD operations for UserProfile without having to run another command to start another instance of Flask
    • It should automatically restart the server whenever there's a code change (similar to how nodemon restarts Node.js server whenever a code change)

Related issues

This issue is blocked by #18. We need that issue to be completed first before we start on this issue

Registration Database

Need to finish the registration form and database with authentication for users to create an account at ScholarSavings

Dockerize development environment

What's the purpose of this issue?

We have 6 developers contributing to StudyHub at the moment, with 6 different machines with variety of dependencies installed, different OS, ... To ensure we do not run into any problems related to setting up development environment, we need to containerize our backend to avoid "but this works and runs on my machine". See this article: https://devopswithdocker.com/part-2/section-4

Containerization of development environment also allows us to mirror production as much as possible to avoid unexpected issue showing up when deploying, despite everything working well during development. We will use Docker for containerization, everyone would needs to install Docker desktop on their machine.

Side Note

You must use the requirements.old.txt file, bad name I know but the current requirements.txt has too much unused libraries in there that will make the Docker image heavier than needed. If requirements.old.txt does not contain all requirements needed, then I shall pray to GPT the Revered God

You must always run Flask related command in the container, you can use Docker Desktop for this, or use docker compose (how to do this can be easily found by Google)

Instructions can be found in the useful resources below

Code Complete

  • I can start the development environment with just one command, something like: docker compose up -d --build -f docker-compose.dev.yaml
    • The Flask server as well as development database should be setup

Checklist

  • Create Docker image for Flask server
  • Create docker-compose.dev.yaml file in the root of the repository to manages the 2 containers (Flask server and dev db)
  • Non-blocking: Add debugger for debugging the containerized Flask server

Related Issues

  • #17 can be done later

Useful resources

https://www.freecodecamp.org/news/how-to-dockerize-a-flask-app/

https://medium.com/@lassebenninga/how-to-debug-flask-running-in-docker-compose-in-vs-code-ef37f0f516ee

Restructure files and directories

What's the purpose of this issue?

Our backend directory structure is a bit disorganized right now. We want to have a proper structure so that adding new features and/or changing existing one can be done smoothly. We also want to have a convention so developers familiar with other technologies such as Django and Express can quickly navigate through the codebase and know where to put new code.

Ideally we'd utilize the Blueprint structure here: https://github.com/app-generator/tutorial-flask/blob/main/flask-project-structure.md, but the other structure in there works as well.

Lastly, we need to have proper structure for this issue: #17. It'd be much easier to setup configuration and necessary initialization with properly structured files and directories

Code Complete

  • Codebase structure is organized
  • Existing functionalities must not break! Ensure imports are updated correctly

Configure migration script for db running in the docker container

The problem I'm facing right now is when I delete a specific user from the Users table, the information of the other relational tables were still kept and hence, it violates the constraints of non-null user id. Therefore, I made some changes in the SQLAlchemy model to set all the others tables to ondelete='CASCADE' so it will also be deleted when the user id is deleted. However, I need some help on running migration script in the dockerize environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.