3. Restructuring of Qunicorn Project

  • Status: accepted

3.1. Context and Problem Statement

The Project Structure needed to be restructured in order to have api and logic seperated.

3.2. Decision Drivers

  • Api and logic separation

  • Better readability of project

3.3. Considered Options

  • “Core” Folder with logic

  • Not doing anything

3.4. Decision Outcome

Chosen option: “‘Core’ Folder with logic”

3.5. Description of Changes

A core package was added. Most of the computational logic was moved to it.

3.5.1. Project Restructuring

Below is a description of the different packages and what they include:

3.5.1.1. api package:

  • api_models: DTOs and Schemas for all Objects.

    • These are used for Computation and to define the Schemas for the API Views

  • {object}_api:

    • These include the Definition of the different Views

3.5.1.2. core package:

  • mapper:

    • This Includes Mapper from DTOs to Database Objects, Helper Class

  • {object}manager:

    • Computational Classes for different Object

    • Service Classes, which get called from API

      • All calls from API should be forwarded to these classes.

      • Celery tasks

3.5.1.3. db package:

  • database_services:

    • Services to access the database (add, get, update, remove)

  • models:

    • Definition of various database models

3.5.2. This lead to other various changes:

3.5.2.1. relationship attributes in database:

  • Used to access whole Database Objects, instead of doing another load via ID.

  • Not represented in database itself, only in code.

  • Its “good practice” of accessing and saving whole objects instead of id. (Unless you really know what you are doing.)

3.5.2.2. Job_dtos were extended:

  • JobCoreDto: Internal Job Handling: includes most data and links to other DTOs, furthermore used for internal communication.

  • JobRequestDto: Request received from API

  • JobResponseDto: DTO used to respond via API

3.5.2.3. Flask/poetry methods defined:

  • flask recreate-and-load-db: Drops the current db, creates a new one, and loads example data

  • poetry run invoke check-linting: Checks flake8 and black linting/formatting.