Integrates Backend | Python Web Service | Fluid Attacks

Introduction

Maintainability Rating

Introduction

Integrates’ backend is an HTTP web service written in Python, served with Hypercorn, and built with Starlette.

Principles

  1. Functional: The codebase favors functions over classes and avoids direct mutations.
  2. No need to reinvent the wheel: Leveraging third-party packages when available.

Getting started

To view changes reflected as you edit the code, you can:
  1. cd integrates and run direnv allow to source the environment into your shell.
  2. Run integrates-local.
As explained in the introduction section, this command launches a replica of the platform using the test data defined in common/schemas/database-design.json. Inside the schemas/tables directory, you find all the data launched by default. This is useful as it allows you to modify anything you wish to test, for example:

{
   enrolled:              true
   is_concurrent_session: false
   is_registered:         true
   role:                  "admin"
   last_name:             "Manager"
   last_login_date:       "2020-12-31T16:50:17+00:00"
   ...
   legal_remember:    true
   registration_date: "2018-02-28T16:54:12+00:00"
   sk:                "USER#__adminEmail__"
   pk_2:              "USER#all"
   pk:                "USER#__adminEmail__"
   first_name:        "Integrates"
   email:             "__adminEmail__"
   sk_2:              "USER#__adminEmail__"
},

This portion of the code that is in the stakeholder_state.cue file defines your local user; with this, you can modify the role, registration status, and all metadata information. Remember, after doing any modifications to the local database, you need to run the following:
integrates-schema-export
And update your local environment so your changes can be reflected.

More on this can be found in the database design section.

Linting

The back uses Prospector and Mypy to enforce compliance with a defined coding style.
To lint and format your code, run:
integrates-back-lint

Testing

Refer to the testing section.

Web server

The back-end is served by Hypercorn, a program with two sides:
  1. 🌐 On one side, it speaks the HTTP protocol, receiving requests and sending responses.
  2. 🐍 On the other it speaks Python (ASGI), passing request data to Python code for processing.
This lower level is challenging to build an application directly on top of, which is where Starlette comes in handy.

Starlette abstracts request handling and provides utilities for building web applications, such as declaring routes, middlewares, and managing sessions and cookies.

Modules

You can find them in the back/integrates directory.

api

This module implements a GraphQL API. You can find more details about it in the API article.

db_model

Declares the structure of each entity used in the application and interacts with database-specific modules to read from and write to a data store.

It provides functions to perform CRUD operations for each entity, taking care of batching and caching using dataloaders. Designed to be agnostic for easy swapping of the underlying data store.

This module is also responsible for controlling concurrent writes, using strategies like optimistic locking.

More about the Integrates backend

  1. API
  2. Logging
  3. Multitasking
  4. Testing - Introduction
  5. Testing - Unit tests
Idea
Tip
Have an idea to simplify our architecture or noticed docs that could use some love? Don't hesitate to open an issue or submit improvements.