Skip to content

Bowell's API service providing endpoints for users, examinations, recording management and running bowel sound analysis using machine learning model for provided by the Division of Artificial Intelligence at the Faculty of Electronics and Information Technology on Warsaw University of Technology.

License

Notifications You must be signed in to change notification settings

BowellSolutions/bowell-backend

Repository files navigation

Bowell Backend

Tools, libraries, frameworks:

This setup has been tested with Python 3.9.

Backend

  • Django + Django Rest Framework : django djangorestframework
  • Django Channels 3 : channels- handling websockets backend
  • djangorestframework-simplejwt - JSON Web Token authentication
  • django-cors-headers - handling cross origin requests
  • coverage - for code coverage reports and running unit tests
  • mypy + djangorestframework-stubs - for better typing experience
  • psycopg2 - needed to use Postgres (in Docker container)
  • channels_redis, redis - connection to Redis database service
  • daphne - production asgi server
  • whitenoise - building static files for production
  • celery - task queue, asynchronous tasks
  • drf-yasg - OpenAPI documentation
  • django-filter - search filters integrated with chosen views

File Structure

Click here to see the documentation of project's file structure.

Development setup:

Environmental variables in .env (random values below)

SECRET_KEY=longrandomlygeneratedsecretkey
DB_NAME=postgresdbname
DB_USER=postgresusername
DB_PASSWORD=postgrespassword
[email protected]
PG_ADMIN_PASSWORD=pgadminpassword

Without Docker

Create a virtual environment

py -3 -m venv venv

venv/Scripts/Activate

python -m pip install --upgrade pip

pip install -r requirements.txt

Run django application

python manage.py runserver

Preparing (if there are any changes to db schema) and running migrations

python manage.py makemigrations

python manage.py migrate

Create superuser

python manage.py createsuperuser

Tests coverage

Run tests using Coverage

coverage run manage.py test

Get report from coverage:

coverage report -m

With Docker

IMPORTANT:

  • Change line endings in shell scripts from CRLF to LF
  • Remove twisted-iocpsupport from requirements.txt if present
  • Remember about env variables

Make sure Docker Engine is running.

While in root directory, build docker images and run them with docker-compose. This might take up to few minutes. Rebuilding image is crucial after installing new packages via pip.

docker-compose up --build

Application should be up and running: backend 127.0.0.1:8000.

If docker images are installed and no additional packages have been installed, just run to start containers:

docker-compose up

Bringing down containers

docker-compose down

To run commands in an active container:

docker exec -it <container_id/container_name> <command>

e.g

docker exec -it backend python manage.py migrate
docker exec -it backend python manage.py shell
docker exec -it backend bash

Production setup

Environmental variables:

DJANGO_SETTINGS_MODULE=core.settings.prod
SECRET_KEY
STATIC_ROOT     # path to dir for storing static files
MEDIA_ROOT      # path to dir for storing recordings
BACKEND_HOST    # e.g example.com
BACKEND_URL     # e.g https://api.example.domain.com
FRONTEND_URL    # e.g https://example.domain.com
COOKIE_DOMAIN   # e.g .domain.com
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST
DB_PORT
REDIS_HOST
REDIS_PORT
REDIS_AUTH_PASSWORD

Build static files (STATIC_ROOT has to exist first for that to succeed)

python manage.py collectstatic --no-input

Making migrations and migrating without user input

python3 manage.py makemigrations --no-input
python3 manage.py migrate --no-input

Running backend

daphne -b 0.0.0.0 -p 8000 core.asgi:application -v2

Deployment to Heroku:

Heroku is used as a backup to our production server and maybe will be used as a staging environment in the future.

Important: Cookie authentication will not work cross-domain and with other Heroku apps because of Heroku

Environmental variables to set in Heroku application:

DJANGO_SETTINGS_MODULE=core.settings.heroku
SECRET_KEY
STATIC_ROOT=staticfiles
MEDIA_ROOT=media
BACKEND_HOST    # e.g <app_name>.herokuapp.com
BACKEND_URL    # e.g https://<app_name>.herokuapp.com
FRONTEND_URL    # e.g https://<app_name>.vercel.app

Used addons: heroku-postgres:hobby-dev, heroku-redis:hobby-dev

To activate worker: heroku ps:scale worker=1:Free -a <app_name>

To run bash: heroku run bash -a <app_name>

About

Bowell's API service providing endpoints for users, examinations, recording management and running bowel sound analysis using machine learning model for provided by the Division of Artificial Intelligence at the Faculty of Electronics and Information Technology on Warsaw University of Technology.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages