Skip to content

Documentation Backend

Anubhav Gupta edited this page Feb 14, 2022 · 2 revisions

Backend

These docs are for the backend folder i.e. the Django Project.
If you are looking for some other docs, then please refer here.

The backend folder is a Django Project called "backend"

The project structure for the Django App (backend) is shown below:

.
β”œβ”€β”€ backend                       # Django Project called "backend"  
β”‚  β”œβ”€ __init__.py                  
β”‚  β”œβ”€ asgi.py
β”‚  β”œβ”€ settings.py
β”‚  β”œβ”€ urls.py
|  └─ wsgi.py
|
β”œβ”€β”€ eatit                         # Django app called "eatit"  
β”‚  β”œβ”€ api                         # A separate folder of API to deal with the API requests 
β”‚  β”‚  β”œβ”€ __init__.py
β”‚  β”‚  β”œβ”€ serializers.py           # Functions to serialize python data
β”‚  β”‚  β”œβ”€ urls.py                  # API endpoints
β”‚  β”‚  └─ views.py                 # View functions for the corresponding URL's
β”‚  β”œβ”€ migrations
β”‚  β”‚  └─ ...
β”‚  β”œβ”€ __init__.py
β”‚  β”œβ”€ admin.py
β”‚  β”œβ”€ apps.py
β”‚  β”œβ”€ models.py                   # Models for the "eatit" app
β”‚  β”œβ”€ tests.py                    # Tests for the "eatit" app
|  └─ views.py
|
β”œβ”€β”€ restaurants                   # Django app called "restaurants"
β”‚  β”œβ”€ api                         # A separate folder of API to deal with the API requests
β”‚  β”‚  β”œβ”€ __init__.py
β”‚  β”‚  β”œβ”€ serializers.py           # Functions to serialize python data
β”‚  β”‚  β”œβ”€ urls.py                  # API endpoints
β”‚  β”‚  └─ views.py                 # View functions for the corresponding URL's
β”‚  β”œβ”€ migrations
β”‚  β”‚  └─ ...
β”‚  β”œβ”€ __init__.py
β”‚  β”œβ”€ admin.py
β”‚  β”œβ”€ apps.py
β”‚  β”œβ”€ models.py                   # Models for the "restaurants" app
β”‚  β”œβ”€ tests.py                    # Tests for the "restaurants" app
|  └─ views.py   
| 
β”œβ”€β”€ example.env                   # env file without credentials
β”œβ”€β”€ manage.py                     # Standard Django project's file
β”œβ”€β”€ Procfile                      # For Heroku deployment
└── requirements.txt              # Contains all the dependencies

This Django Project has 2 apps, namely eatit and restaurants.
The eatit app is responsible for the end users, the one's who browse through the food items, and purchase them.
The restaurants app is responsible for the restaurant owners, the one's who partner with us, and list their food items on our platforms, and receive payments on selling them.

1. eatit

You will notice that there is a new folder called api in addition to the standard Django's App files.
This folder is responsible for all the API endpoints.

urls.py - This file defines all the API endpoints for the "eatit" app
views.py - This file specifies the view functions for the corresponding URL routes
serializers.py - This file contains classes to serialize the current data in Python objects into JSON objects

Overall Working

DRF is used in the backend while User authentication is done using JWT. Various API endpoints are defined in the url.py file, whereas the corresponding view functions are available in the views.py file. View functions perform the required backend operations and then return the data to the frontend in a JSON format. The data conversion, from Python objects to JSON objects, is done using serializers available in serializers.py file

2. restaurants

You will notice that there is a new folder called api in addition to the standard Django's App files.
This folder is responsible for all the API endpoints.

urls.py - This file defines all the API endpoints for the "restaurants" app
views.py - This file specifies the view functions for the corresponding URL routes
serializers.py - This file contains classes to serialize the current data in Python objects into JSON objects

Overall Working

DRF is used in the backend while User authentication is done using JWT. Various API endpoints are defined in the url.py file, whereas the corresponding view functions are available in the views.py file. View functions perform the required backend operations and then return the data to the frontend in a JSON format. The data conversion, from Python objects to JSON objects, is done using serializers available in serializers.py file

Clone this wiki locally