Book Image

A Blueprint for Production-Ready Web Applications

By : Dr. Philip Jones
Book Image

A Blueprint for Production-Ready Web Applications

By: Dr. Philip Jones

Overview of this book

A Blueprint for Production-Ready Web Applications will help you expand upon your coding knowledge and teach you how to create a complete web application. Unlike other guides that focus solely on a singular technology or process, this book shows you how to combine different technologies and processes as needed to meet industry standards. You’ll begin by learning how to set up your development environment, and use Quart and React to create the backend and frontend, respectively. This book then helps you get to grips with managing and validating accounts, structuring relational tables, and creating forms to manage data. As you progress through the chapters, you’ll gain a comprehensive understanding of web application development by creating a to-do app, which can be used as a base for your future projects. Finally, you’ll find out how to deploy and monitor your application, along with discovering advanced concepts such as managing database migrations and adding multifactor authentication. By the end of this web development book, you’ll be able to apply the lessons and industry best practices that you’ve learned to both your personal and work projects, allowing you to further develop your coding portfolio.
Table of Contents (13 chapters)
1
Part 1 Setting Up Our System
3
Part 2 Building a To-Do App
8
Part 3 Releasing a Production-Ready App

Connecting to the database

We have chosen to store the data the app needs in a PostgreSQL database, which we will need to connect to. To do this, I like to use the Quart extension called Quart-DB, which is a great wrapper around fast lower-level PostgreSQL drivers. It is installed by running the following command in the backend directory:

pdm add quart-db

We can activate QuartDB by adding the following code to backend/src/backend/run.py:

from quart_db import QuartDB
quart_db = QuartDB(app)

We also need to configure which database QuartDB should connect to. This is achieved by adding a TOZO_QUART_DB_DATABASE_URL environment variable, the value of which is constructed as follows, with the highlighted parts being configurable:

postgresql://username:password@0.0.0.0:5432/db_name

We’ll use tozo for the username, password, and database name in development as they are very obvious and easy to remember. To do this, add the following to backend/development.env:

...