Setting up Project Backend

We’ll start this project with a clean slate and walk through each step to set up the development environment. The following are some of the project requirements that must be met:

  1. Python 3.9.0 or higher should be installed.
  2. Node.js server (npm) should be installed.

This is already available on the Educative platform.

Initial setup

We’ll start by creating the main bookapp/ project folder. Then, we’ll jump right into the bookapp/ folder and initialize a Git repository from a command prompt using the following commands.

Create a directory:

mkdir bookapp

Change into the directory:

cd bookapp

Initialize git:

git init

The gitignore file

To make sure we don’t commit any generated files to the repository, we’ll create a .gitignore file in the bookapp/ folder:

.idea/

*.pyc
*.bak
*.log

database/
venv/
__target__/
dist/
.cache/
node_modules/
__pycache__/

It is generally preferred to not commit IDE settings to the project’s git repository, so we add the PyCharm .idea/ folder to the .gitignore file.

Similarly, we keep the Python virtual environments out of the code repository as well. If the virtual environment needs to be recreated, a requirements.txt file can be used to automatically install any needed Python library dependencies. This is also similar to the JavaScript libraries, so we ignore anything in the node_modules/ folder. We can install the JavaScript libraries with npm and the package.json file. We also don’t want to commit the database either, so we add that folder to the ignore list.

Setting up a virtual environment

Next, go ahead and create the two application folders: server/ and client/. We then set the bookapp/server/ folder as the current folder, and then we set up the virtual environment for the back-end server using Python 3.9.0 or higher.

We need to use python3 or python3.9 (or py -3.9 on Windows) instead of just python depending on what version(s) of Python we have installed:

python3 -m venv venv

Then, we activate the virtual environment using the appropriate command for the operating system:

source venv/bin/activate

And since we know we are going to be using Flask, let’s go ahead and install that now, as well as the Flask-Login plug-in:


Installing Flask

And since we are going to use Flask, let’s go ahead and install Flask and Flask-Login plug-in:

pip install Flask 

Installing Flask-Login

pip install Flask-Login

Then, we exit the virtual environment:

deactivate

Now, we change the working folder to bookapp/client/ and do as follows:

python3 -m venv venv
source venv/bin/activate

Installing Transcrypt

We need to use Transcrypt in the web application, so we’ll be installing that into the virtual environment too:

pip install transcrypt

Enabling versioning

We want to create the src/ source code folder for bookapp/client/. Finally, to allow npm version to work properly with our folder structure, add an empty .git/ folder to bookapp/client/.

At this point, the project folder structure should now look like this:

bookapp/
├── .git/
├── client/
│   ├── .git/
│   ├── src/
│   └── venv/
└── server/
    └── venv/

We will take care of the JavaScript side of things later in the course.

Note: We’ve already created a .gitignore file. We can also try the other commands explained above in the following terminal.

Get hands-on with 1200+ tech skills courses.