Skip to content

A Flask Authentication Boilerplate: Blueprints + React + Typescript + MongoDB

Notifications You must be signed in to change notification settings

jack20951948/Flask-Mongo-Authenticate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Flask Authentication Boilerplate.

  • Development:

    • React + Typescript + MongoDB
  • Production:

    • React + Typescript + MongoDB + Docker

Overview

spawned from Luke Peters work here

APP Versions

App Name Version
Ubuntu 20.04.6 LTS
Docker 24.0.7
Python 3.12.1
Node 20.11.0
Npm 10.2.4
Nvm 0.35.3
Nginx 1.24.0
MongoDB 7.0.5
Mongosh 2.1.1

Structure

├── api
  ├── main
    ├── auth
      └── token authentication methods
    ├── config
      └── the ./setup script populates a new config.cfg file for Flask,
          using the ##FIELDS## provided in config.cfg.sample
    ├── tools
      └── utilities for date/time, expression matching, the like
    └── user
      └── models.py defines the User() class
      └── routes.py implements User() methods api/routes as a blueprint
          (registered at /user/)
├── public
  └── all hot reloading and whatnot is done from react-scripts at index.html
└── src
  └── insert client-side source here, hack away  xD
      the thinking is one deal with compiling & serving production code elsewhere

Development Setup

This project works on Ubuntu 20.04.6 LTS. For Windows users, please run this project on WSL. You may use this command wsl --install -d Ubuntu-20.04 on your PowerShell to install the Ubuntu 20.04.6 LTS

  • clone the project
    • git clone https://github.com/jack20951948/Flask-Mongo-Authenticate.git
  • move to project directory
    • cd Flask-Mongo-Authenticate
  • install Python 3.12.1, this step depends on OS you may find any resoucre on the internet achieve this
  • create python virtual environment
    • python3.12 -m venv .venv
  • get into the virtual environment
    • source ./.venv/bin/activate
  • install the dependencies
    • pip3 install -r ./api/requirements.txt
  • add packages to PATH
    • export PATH="$HOME/.local/bin:$PATH"
  • install pre-commit
    • pre-commit install
  • install nvm 0.35.3
    • curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
  • reopen your terminal
  • install node 20.11.0 via nvm
    • nvm install 20.11.0
  • take 20.11.0 as node version
    • nvm use 20.11.0
  • install frontend dependencies
    • cd frontend
    • npm install
  • give permission for setup / run script
    • cd ..
    • sudo chmod +x setup run
  • modify end of line sequence style for both run and setup script
    • select LF
  • install MongoDB 7.0.5 and Mongosh 2.1.1
    • note that at the Install the MongoDB packages stage, you may select the version specificly to MongoDB 7.0.5 and Mongosh 2.1.1
    • note that at the ulimit Considerations stage, you may assign open files value to 64000
    • ref here
  • run setup script, it only needs to run once while getting started
    • ./setup
  • run run script to start developing
    • ./run
  • confirm frontend is working
  • confirm backend is working
  • confirm mongoDB is working

Docker setup for production on Ubuntu

  1. Set up Docker's apt repository.

    # Add Docker's official GPG key:
    sudo apt-get update
    sudo apt-get install ca-certificates curl gnupg
    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    
    # Add the repository to Apt sources:
    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
  2. Install the Docker version 24.0.7

    sudo apt-get install docker-ce=5:24.0.7-1~ubuntu.20.04~focal docker-ce-cli=5:24.0.7-1~ubuntu.20.04~focal containerd.io docker-buildx-plugin docker-compose-plugin docker-compose
  3. Add user to the Docker group(run docker command without the sudo prefix)

    sudo usermod -aG docker ${USER}

Common Docker command

  • run docker containers in background

    # execute this command at the same directory as docker-compose.yml
    docker-compose up -d --scale backend=3
  • remove docker images / containers / networks / volume from this project

    # execute this command at the same directory as docker-compose.yml
    docker-compose down --rmi all -v
  • remove docker containers / networks

    # execute this command at the same directory as docker-compose.yml
    docker-compose down
  • list every image on your device

    docker images
  • remove the docker image, it can remove multiple images at once by adding more <image-id>

    docker image remove <image-id>
  • remove the specific docker container, it can remove multiple images at once by adding more <docker-container-id>

    docker container remove <docker-container-id>
  • list the running docker container

    docker ps
  • list the running / exited docker container

    docker ps -a

Common MongoDB command

  • enter db in terminal:

    mongosh
  • switch db (ex: new-app)

    use new-app
  • switch find documents from collection (ex: users collection)

    db.users.find()
  • empty collection (ex: users collection)

    db.users.deleteMany({})

About

A Flask Authentication Boilerplate: Blueprints + React + Typescript + MongoDB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 60.3%
  • Python 25.9%
  • Shell 8.2%
  • HTML 3.5%
  • Dockerfile 1.6%
  • CSS 0.5%