-
Notifications
You must be signed in to change notification settings - Fork 0
Project Structure
This is the overview of the entire project.
.
├── app
│ ├── db.py
│ ├── __init__.py
│ ├── routes.py
│ └── templates
│ └── reset-password.html
├── config.py
├── docs
│ ├── deleteframes.yml
│ ├── getframes.yml
│ ├── login.yml
│ ├── postframes.yml
│ ├── register.yml
│ ├── sendresetmail.yml
│ ├── updateframes.yml
│ └── updatepassword.yml
├── requirements.txt
├── sample.env
├── server.py
└── utils.py
It is always a good practice to keep place similar modules in one package and different modules in different packages. This makes a project (program) easy to manage and conceptually clear. Inside our app
package we have
app/__init__.py :
It does most of the initialization of the flask app including the mail service and swagger. One thing to note here is that the routes module is imported at the bottom and not at the top of the script as it is always done. The bottom import is a workaround to circular imports, a common problem with Flask applications.
app/routes.py :
It sets all of the API endpoints and their methods. Also for the swagger documentation, @swag_from
decorator is used. The module used for the documentation is Flasgger.
app/db.py :
It contains all the functions that perform operations with the database. For this, we used Pyrebase it is a simple Python wrapper of the Firebase API.
app/templates :
It contains all the templates necessary for rendering.
It contains all the configuration required as an object. That way we can access it from anywhere, by just importing the class.
It has all the necessary documentation needed for the Swagger dashboard. All the files here are .yml
files.
It consists of all the main packages used. It is always advised to use a virtual environment while working with python projects. To create the virtual environment, run the following commands:
$ python3 -m venv venv
You will see a venv directory created. Now to activate this virtual environment run:
$ source venv/bin/activate
N.B here onwards you will have to use
pip
orpython
don't usepip3
orpython3
.
Now to install all the required packages just run
$ pip install -r requirements.txt
Else if you want to manually install a package run
$ pip install <package-name>
Let's say you have already installed a couple of packages you can update the requirements.txt
by:
$ pip freeze > requirements.txt
Also to get a list of all the python packages you are using you can run pip freeze
or pip list
This file contains all the utility functions that are used, and are not specific to the app. Like encoding JWT, creating reset tokens, and sending mail.
As the name suggests this is the sample of a .env
file. Since we are using python-dotenv
the env files will get automatically loaded when we run the flask run
command. But when the app is running through the gunicorn service the path has to be specified.