Karthikeyan-P / eon-backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EOn-backend

This is a monolithic architecture django project for BITS EOn.

Prerequisites

  • Postgres
  • Redis
  • Celery

Note: Make sure that Postgres and Redis is installed and running on your system. If your don't have these. Please installed them from below link.

Important Features

  • Python 3+
  • Django 2.0+
  • Database Postgres
  • Uses Virtualenv
  • Uses Celery and Redis for sending SMS/Email in background.
  • AWS services - S3, SES, SNS, Elastic Beanstalk

Installation

Note: If you have the zip of this project, then skip the git clone command and extract the project.

$ git clone https://github.com/bits-pgp-fse/eon-backend.git
$ virtualenv <virtual_env_name_of_your_choice>
$ source <virtual_env_name_of_your_choice>/bin/activate
$ cd eon-backend
$ pip install -r requirements.txt

Note: As this project requires celery for background tasks. Make sure it is running in a different terminal.

Running Celery

$ celery worker -A eon_backend.celery:app --loglevel=INFO

Postgres

sudo -u postgres psql

CREATE DATABASE eon;

CREATE USER bits_eon WITH PASSWORD 'password';

ALTER USER bits_eon WITH SUPERUSER;

Environment Variables

#DJANGO
SECRET_KEY=<something_very_secret>
ENCODE_KEY=<encoding_key>
DB_NAME=eon
DB_USERNAME=bits_eon
DB_PASSWORD=password
DB_HOSTNAME=localhost
DB_PORT=5432
PAYMENT_URL="http://localhost:8001/core/payment/"
EVENT_URL="http://localhost:8000/event-details?id="

#JWT
ACCESS_TOKEN_LIFETIME=1(day)
REFRESH_TOKEN_LIFETIME=2(days)

#AWS
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
EMAIL_ID=<application_email_id>
ADMIN_EMAIL=<admin_email_id>
BUCKET_NAME=
AWS_BUCKET_PATH=
BROKER_URL=redis://localhost:6379

Run Server

$ python3 manage.py migrate
$ python3 manage.py runserver

Note: If you are seeing on master branch and running runserver command, then you will receive some warning. You can ignore this warning or run the below command to resolve this warning.

$ python3 manage.py collectstatic

This project has some dependency on values in the database. So for this, load the data from fixtures:

$ python3 manage.py loaddata fixtures/roles.json
$ python3 manage.py loaddata fixtures/event_types.json
$ python3 manage.py loaddata fixtures/questions.json

Create super user to access Django admin:

$ python3 manage.py createsuperuser;

Run Test (with coverage html, if you don't want cover html than remove --cover-html option from command)

$ python3 manage.py test --cover-html

Note: The index.html will be generated in the same repo under cover folder.

Check Pylint Score

Run this command outside of project folder

$ pylint eon-backend --rcfile=eon-backend/.pylintrc

Main Libraries Used

Folder Structure

Main Folder : eon-backend contains complete monolithic django project It further includes:

A basic django app contains following files:
models.py : All the models related to the module
urls.py  : Contains API urls list 
admin.py :  Configuration related to django admin for the module
tests.py : Contains test cases for the module
signals.py : Contains custom signals required pre/post any actions like post_save or pre_save
apps.py : This file registers any sub app with the main app here(eon-backend)
views.py : This file contains all the APIs and required all the logic related to them
serializers.py : Have custom classes used to serialize the data into django object

Comprising of these files this django app contains following modules(sub apps)

authentication: This module contains complete sub app for authentication including 

login
signup
password-reset
change-password

core: This module contains folders:
views_layer: This folder contains separate files for APIs of
Events
Feedback
Invitation
Notification
Subscription
User
Wishlist
tests: This folder contains test cases for all the above mentioned APIs files

Some Additional files in core
	
exceptions.py: Custom exceptions class
filters.py:  Custom filters for free/paid event
presigned_url.py: API to create/fetch presigned url
reports.py: Analysis reports for django admin template generated in this file

Other important folders in the main app includes:

eon_backend: Contains main settings file for the eon_backnd app & also urls for Core / Authentication

static: Contains common css & js files for django-admin template

templates: Contains related to event_analysis dashboard in django admin

About


Languages

Language:Python 89.9%Language:HTML 5.6%Language:JavaScript 3.4%Language:Shell 0.8%Language:CSS 0.3%