Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

The booking service for extraction and analysis of genetic samples.

Technologies

  • Django
  • React
  • Docker
  • Tailwind CSS

Setup

Refer to README.md

Repository structure

Root

  • pyproject.toml, dependencies of the project
  • pre-commit-config.yml, configuration for precommit
  • aliases.sh, development shortcuts (aliases)
  • entrypoint.sh, docker entrypoint script
  • src, the directory contains all the source code
  • nginx, the directory contains the proxy configurations
  • docs, contains the mdbook pages
  • media, placeholder directory for media files (user uploads)

Source Code

  • capps, wrapper module for core and users django apps
  • capps.users, module that extends the default django auth user module
  • capps.core, module that contains some shared functionalities (base templates, management commands, templatetags)
  • config, module that contains all the configuration logic of the django project (urls.py, settings)
  • frontend, implements the frontend (more on this later)
  • genlab_bestilling, the module that holds all the business logic
  • locale, translations folder
  • fixtures, database seeds folder
  • nina, module that implements models related to our organization management (projects)
  • shared, code that is used in different modules
  • static, static files
  • templates, top level templates folder
  • theme, folder that contains the theme (i.e. Tailwindcss implementation)
  • staff, contains the code that implements the staff section

Frontend

The frontend is implemented using React, the code is bundled with vite and is served as a static file (in production). The code is organized as multi-page: inside frontend/src each folder will be bundled as a different javascript file, which will be loaded on a specific page.

This allows to "enhance" only certain pages, where and if necessary.

During the development, a container that executes vite starts a dev-server. The production image instead builds the frontend modules in a docker stage and keeps the output (without the node_modules folder).

Theme

The theme is implemented as a django-tailwind module.

genlab_bestilling

Most of the files follow the conventions of django (admin, views, urls, apps), more on the others:

  • api, contains the files related to rest-framework, such as views and serializers. Rest APIs are used by the frontend.
  • libs, all the modules contain "isolated" code that should be easy to test and reuse in different contexts
  • filters, filters of django-filter
  • autocomplete, autocomplete of dal2
  • tables, tables of django-tables2
  • tasks, tasks of procrastinate

Technical Notes

Database

Postgres is used as database

GenlabID

The generation of the GenlabID is pretty complex, the requirements are the following:

  • The code should be partitioned by (Year, Species) + a running number
  • The code should be short
  • Each sample can be cloned, leading to a sub-sequence

This is achived using:

  • a postgres function (see genlab_bestilling/migrations/0001) that creates a sequence specific for that partition if not exists (using the species and year as name of the sequence) and retrieves the name of such sequence, and a function that generates the code invoking nextval on the appropriate sequence.
  • only samples that are confirmed will get a GenlabID
  • ids are generated in a queue, by a worker with concurrency 1 to allow the manual rollback of the sequence in case of error

Frontend

Frontend is implemented in React, the frontend scripts are loaded by django templates and communicate with the backend using a REST API.