Skip to content

Harmony beauty server powered by FastAPI, ODMantic, MongoDB, Deta, and friends.

License

Notifications You must be signed in to change notification settings

inclusive-web-hub/harmony-beauty-server

 
 

Repository files navigation

Harmony Beauty Server

linting: pylint Code style: black Static typing: mypy License: MIT Codeql

A Fully Async-based backend for Harmony Beauty.

Development Requirements

  • Make (GNU command)
  • Python (>= 3.9)
  • Poetry (1.2)

Project Structure

❯ tree app
.
├── auth          # Package contains different config files for the `auth` app.
│   ├── crud.py       # Module contains different CRUD operations performed on the database.
│   ├── models.py     # Module contains different data models for ODM to interact with database.
│   ├── router.py     # Module contains different routes for this api.
│   └── schemas.py    # Module contains different schemas for this api for validation purposes.
├── cart       # Package contains different config files for the `cart` app.
│   ├── crud.py       # Module contains different CRUD operations performed on the database.
│   ├── models.py     # Module contains different models for ODMs to inteact with database.
│   ├── router.py     # Module contains different routes for this api.
│   └── schemas.py    # Module contains different schemas for this api for validation purposes.
├── users         # Package contains different config files for the `users` app.
│   ├── crud.py       # Module contains different CRUD operations performed on the database.
│   ├── models.py     # Module contains different models for ODMs to inteact with database.
│   ├── router.py     # Module contains different routes for this api.
│   └── schemas.py    # Module contains different schemas for this api for validation purposes.
├── utils         # Package contains different common utility modules for the whole project.
│   ├── crypt.py
│   ├── dependencies.py     # A utility script that yield a session for each request to make the crud call work.
│   ├── engine.py           # A utility script that initializes an ODMantic engine and client and set them as app state variables.
│   ├── jwt.py              # A utility script for JWT.
│   ├── mixins.py           # A utility script that contains common mixins for different models.
├── config.py     # Module contains the main configuration settings for project.
├── __init__.py
├── main.py       # Startup script. Starts uvicorn.
└── py.typed      # mypy related file.

Installation with Make

The best way to configure, install main dependencies, and run the project is by using make. So, ensure you have make installed and configured on your machine. If it is not the case, head over to this thread on StackOverflow to install it on windows, or this thread to install it on Mac OS.

Having make installed and configured on your machine, you can now run make under the root directory of this project to explore different available commands to run:

make

Please use 'make <target>' where <target> is one of:

venv                     Create a virtual environment
install                  Install the package and all required core dependencies
run                      Running the app locally
deploy-deta              Deploy the app on a Deta Micro
clean                    Remove all build, test, coverage and Python artifacts
lint                     Check style with pre-commit
test                     Run tests quickly with pytest
test-all                 Run tests on every Python version with tox
coverage                 Check code coverage quickly with the default Python
build                    Build docker containers services
up                       Spin up the containers
down                     Stop all running containers

1. Create a virtualenv

make venv

2. Activate the virtualenv

source .venv/bin/activate

3. Install dependencies

make install

Note: This command will automatically generate a .env file from .env.example, uninstall the old version of poetry on your machine, then install latest version 1.2.2, and install the required main dependencies.

4. Setup a MongoDB Atlas account

Head over to the official website to create a MongoDB account and a cluster.

5. Set your MongoDB Credentials

Fill in the following environment variables in your .env file accordingly:

# Database
MONGODB_USERNAME=
MONGODB_PASSWORD=
MONGODB_HOST=cluster_name.example.mongodb.net
MONGODB_DATABASE=shop

6. Create a Deta Account

Create a free account on Deta, and create a new project.

7. Set your Deta project key

Set the following environment variable in your .env file according to your project key value:

# Deta
DETA_PROJECT_KEY=

8. Generate a secret key

Generate a secret key using OpenSSL and update its env var in the .env file.

openssl rand -hex 128

afa1639545d53ecf83c9f8acf4704abe1382f9a9dbf76d2fd229d4795a4748712dbfe7cf1f0a812f1c0fad2d47c8343cd1017b22fc3bf43d052307137f6ba68cd2cb69748b561df846873a6257e3569d6307a7e022b82b79cb3d6e0fee00553d80913c1dcf946e2e91e1dfcbba1ed9f34c9250597c1f70f572744e91c68cbe76
# App config:
JWT_SECRET_KEY=afa1639545d53ecf83c9f8acf4704abe1382f9a9dbf76d2fd229d4795a4748712dbfe7cf1f0a812f1c0fad2d47c8343cd1017b22fc3bf43d052307137f6ba68cd2cb69748b561df846873a6257e3569d6307a7e022b82b79cb3d6e0fee00553d80913c1dcf946e2e91e1dfcbba1ed9f34c9250597c1f70f572744e91c68cbe76
DEBUG=info

9. Run The Project Locally

make run

Note: You have to set DEBUG=info to access the docs.

Access Swagger Documentation

http://localhost:8000/docs

Access Redocs Documentation

http://localhost:8000/redocs

Deployments

Deploy locally with Compose v2

First thing first, to run the entire platform, you have to clone the harmony-beauty submodule using the following command:

git submodule update --init --recursive

Once that is done, make sure you have compose v2 installed and configured on your machine, and run the following command to build the predefined docker services(make sure you have a .env file beforehand):

Using Make

make build

or simply running:

docker compose build

Once that is done, you can spin up the containers:

Using Make

make up

or running:

docker compose up

Wait until the client service becomes available:

harmony-beauty-client-1      | Starting the development server...

You can stop the running containers but issuing the following command on a separate terminal session:

make down

Deta Micros (Endpoints not working)

You'll need to create a Deta account to use the Deta version of the APIs.

Deploy on Deta

Heroku

This button will only deploy the server.

Deploy on Heroku

Core Dependencies

The following packages are the main dependencies used to build this project:

License

This project and the accompanying materials are made available under the terms and conditions of the MIT LICENSE.

About

Harmony beauty server powered by FastAPI, ODMantic, MongoDB, Deta, and friends.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 87.5%
  • Makefile 8.9%
  • Dockerfile 2.9%
  • Other 0.7%