Skip to content

Latest commit

 

History

History
111 lines (89 loc) · 3.38 KB

File metadata and controls

111 lines (89 loc) · 3.38 KB

Backend Habit Building App

Table of Contents

Overview

This project is a backend application built using FastAPI, PyMongo, and Docker. It demonstrates building RESTful APIs that interact with a MongoDB database and includes a serverless deployment option using AWS Lambda and API Gateway.

Tools Used

Backend

  • FastAPI for building RESTful APIs
  • PyMongo for interacting with MongoDB
  • Docker for containerized deployment
  • JSON Web Tokens for User Authentication
  • Hosted on AWS
    • ECR to host containerized images
    • Lambda Functions to respond to requests
    • API Gateway to manage server-client communications

Front End

  • React
  • Next.js
  • ShadCN (component library)
    • Skeleton Loaders
    • Motion Elements
    • Fallback functionality

Requirements

  • Python 3.11

Setup

1. Clone the repository

git clone https://github.com/unsupervised-machine/habit_backend
cd habit_backend

2. Create a virtual environment & install dependencies

python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt

3. Configure environment variables

Create a .env file with the following: (For illustrative purposes I will expose the secrets below.)

MONGO_URI=[REDACTED - REQUEST FROM AUTHOR]
DATABASE_NAME=habit_db
SECRET_KEY=[REDACTED - REQUEST FROM AUTHOR]
ALGORITHM=[REDACTED - REQUEST FROM AUTHOR]
ACCESS_TOKEN_EXPIRE_MINUTES=30

4. Run Locally

uvicorn main:app --reload --port 8000

You can also visit the live website here: https://habit-frontend-five.vercel.app

This will start both the FastAPI Uvicorn service running on http://127.0.0.1:8000

Backend API Endpoints

FastAPI Docs

Serverless Deployment

  • This projects database is currently being hosted on MongoDB Atlas server, whether you hit the API from the API Gateway routes or from the locally hosted routes the database will reflect the changes.
  • The project was containerized using docker, the container image was stored in a ECR repo, a Lambda instance is spun up on calls from an API Gateway.

Cloud Architecture

  • A diagram describing my API architecture can be found here: diagrams/Cloud Diagram.drawio.svg Cloud Architecture

MongoDB

  • The database is hosted on the cloud using MongoDB Atlas.
  • All CRUD operations with the database are done through the official MongoDB driver pymongo.

Front End

  • The Front end was built using Next.js, React,

Demo

Demo Video

License

None

Contact Me

If you have any questions, suggestions, or issues, feel free to reach out!