Skip to content

Developer & Deployment Guide

github-actions[bot] edited this page Nov 12, 2026 · 2 revisions

Developer & Production Deployment Guide

This guide details the repository structure, local development environment setup, unit testing protocols, database migration strategies, and production deployment procedures for BioLabCalc and its Electronic Lab Notebook (ELN) / Multi-Modal LIMS subsystem.


πŸ“‚ Repository Directory Layout

The codebase follows modern Python packaging standards with clear architectural separation between core biophysical calculators, the ELN subsystem, analytical parsers, and browser assets:

biolabcalc_repository/
β”œβ”€β”€ src/
β”‚   └── biolabcalc/
β”‚       β”œβ”€β”€ __init__.py                 <- Package root and version exports
β”‚       β”œβ”€β”€ cli.py                      <- Click/argparse CLI entrypoint (29 commands)
β”‚       β”œβ”€β”€ easy.py                     <- High-level convenience API for Jupyter / IPython
β”‚       β”œβ”€β”€ molecular_weight.py         <- MW, isotopic distribution, and elemental formula
β”‚       β”œβ”€β”€ protein.py                  <- Extinction coefficients (e280), pI, Net charge
β”‚       β”œβ”€β”€ buffers.py                  <- Recipe generator, dilution (C1V1), pH Henderson-Hasselbalch
β”‚       β”œβ”€β”€ cloning.py                  <- Gibson assembly, Golden Gate Type IIS, restriction digest
β”‚       β”œβ”€β”€ pcr.py                      <- SantaLucia thermodynamics, primer annealing, Q5/Taq
β”‚       β”œβ”€β”€ gels.py                     <- Agarose / SDS-PAGE band simulation & Rf mapping
β”‚       β”œβ”€β”€ western_blot.py             <- Membrane transfer scaling, antibody dilution math
β”‚       β”œβ”€β”€ fluorescence.py             <- Fluorophore excitation/emission spectra & FRET overlap
β”‚       β”œβ”€β”€ ecoli_growth.py             <- Bacterial doubling kinetics, OD600 biomass modeling
β”‚       β”œβ”€β”€ precipitation.py            <- Ethanol/isopropanol/NaOAc desalting stoichiometry
β”‚       └── eln/                        <- Electronic Lab Notebook & LIMS Subsystem
β”‚           β”œβ”€β”€ server.py               <- Dual-engine server launcher (Uvicorn ASGI / HTTP fallback)
β”‚           β”œβ”€β”€ api/                    <- REST routing, WebSockets, and authentication
β”‚           β”‚   β”œβ”€β”€ app.py              <- FastAPI application factory
β”‚           β”‚   β”œβ”€β”€ router.py           <- Unified API route aggregator
β”‚           β”‚   β”œβ”€β”€ websocket_manager.py<- Real-time client state broadcaster
β”‚           β”‚   └── routes/             <- Domain-specific endpoint handlers (sops, inventory, etc.)
β”‚           β”œβ”€β”€ parsers/                <- Analytical instrument file decoders
β”‚           β”‚   β”œβ”€β”€ fplc_parser.py      <- Γ„KTA UNICORN (.res, .csv, .zip) multi-channel reader
β”‚           β”‚   β”œβ”€β”€ nanodrop_parser.py  <- Thermo NanoDrop UV-Vis spectral curve extractor
β”‚           β”‚   β”œβ”€β”€ biorad_parser.py    <- Bio-Rad Image Lab (.scn) & 16-bit TIFF densitometer
β”‚           β”‚   β”œβ”€β”€ abf_parser.py       <- Pure-Python Axon Binary Format (ABF v1/v2, ATF) decoder
β”‚           β”‚   β”œβ”€β”€ doc_parser.py       <- Protocol Markdown and table structure parser
β”‚           β”‚   └── ocr_engine.py       <- HITL OCR engine with biochemical entity disambiguation
β”‚           β”œβ”€β”€ rag/                    <- Local intelligence & retrieval-augmented generation
β”‚           β”‚   β”œβ”€β”€ chunker.py          <- Laboratory entity extractor & semantic chunker
β”‚           β”‚   β”œβ”€β”€ hybrid_search.py    <- BM25 + dense vector Reciprocal Rank Fusion engine
β”‚           β”‚   β”œβ”€β”€ local_llm.py        <- Local inference client (Ollama/GGUF) + offline fallback
β”‚           β”‚   └── synthesizer.py      <- Contextual citation synthesizer with footnotes
β”‚           β”œβ”€β”€ schema/                 <- Relational models, DDL, and database engines
β”‚           β”‚   β”œβ”€β”€ database.py         <- Dual database abstraction (custom SQLite ORM + PostgreSQL)
β”‚           β”‚   β”œβ”€β”€ ddl.sql             <- PostgreSQL 16+ pgvector production DDL (21 tables)
β”‚           β”‚   └── models.py           <- Declarative entity models
β”‚           β”œβ”€β”€ services/               <- Core business logic & GxP governance
β”‚           β”‚   β”œβ”€β”€ audit_service.py    <- SHA-256 cryptographically chained immutable ledger
β”‚           β”‚   β”œβ”€β”€ sop_service.py      <- SOP versioning, PI sign-offs, and execution forks
β”‚           β”‚   β”œβ”€β”€ inventory_service.py<- 6-tier freezer hierarchy, 2D grid, sample lineage
β”‚           β”‚   β”œβ”€β”€ campaign_service.py <- Multi-day experimental campaign management
β”‚           β”‚   └── fplc_service.py     <- Fraction collection and chromatogram integration
β”‚           β”œβ”€β”€ storage/                <- Content-Addressed Storage (CAS)
β”‚           β”‚   β”œβ”€β”€ blob_store.py       <- SHA-256 sharded file storage (local & S3/MinIO)
β”‚           β”‚   └── preview_generator.py<- Web preview downsampling for large analytical files
β”‚           └── web/                    <- Single-Page Application assets
β”‚               β”œβ”€β”€ templates/index.html<- Unified HTML5 laboratory workspace
β”‚               └── static/             <- Canvases, timers, freezer grids, and stylesheets
β”œβ”€β”€ tests/                              <- Test suite
β”œβ”€β”€ pyproject.toml                      <- Build configuration, dependencies, and entrypoints
└── README.md                           <- Repository overview

πŸ› οΈ Development Setup & Testing

1. Development Installation

Clone the repository and install in editable mode with development dependencies:

# Clone the repository
git clone https://github.com/your-org/biolabcalc.git
cd biolabcalc

# Create and activate an isolated Python virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate

# Install package in editable mode with development and ELN extras
pip install -e ".[dev,eln]"

2. Running the Test Suite

The repository maintains exhaustive test coverage across all calculators, parsers, and ELN services using Python's standard unittest framework:

# Execute entire test suite
python -m unittest discover tests

# Run ELN test suites
python -m unittest tests/test_eln_services_and_api.py
python -m unittest tests/test_eln_parsers.py
python -m unittest tests/test_eln_rag.py
python -m unittest tests/test_eln_schema.py
python -m unittest tests/test_eln_integration.py

πŸ—„οΈ Database Migration: SQLite to PostgreSQL 16+

While the zero-dependency SQLite engine is optimal for local evaluation, high-throughput multi-user enterprise deployments should run on PostgreSQL 16+ with the pgvector extension.

Connecting to PostgreSQL requires SQLAlchemy and psycopg2-binary, installed via pip install "biolabcalc[eln]". When using file-based SQLite, WAL mode (PRAGMA journal_mode = WAL;) and a 30-second busy timeout are automatically enabled to ensure reliable concurrency, while in-memory SQLite connections are guarded by thread synchronization locks.

Step 1: Provision PostgreSQL & Enable Extensions

CREATE DATABASE eln_production;
\c eln_production;

-- Enable required extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "vector";
CREATE EXTENSION IF NOT EXISTS "pg_trgm";
CREATE EXTENSION IF NOT EXISTS "btree_gin";

Step 2: Execute Production DDL

Apply the complete 21-table production schema located at src/biolabcalc/eln/schema/ddl.sql:

psql -U postgres -d eln_production -f src/biolabcalc/eln/schema/ddl.sql

Step 3: Configure Database Connection

Launch the ELN server targeting the PostgreSQL database:

biolabcalc eln --db "postgresql://eln_user:secret_password@localhost:5432/eln_production" --port 8080

Or export the standard environment variable:

export DATABASE_URL="postgresql://eln_user:secret_password@localhost:5432/eln_production"
biolabcalc eln

🐳 Production Deployment Architectures

Option A: Docker & Docker Compose (Recommended)

Create a docker-compose.yml to provision PostgreSQL with pgvector alongside the BioLabCalc ELN application container:

version: '3.8'

services:
  db:
    image: pgvector/pgvector:pg16
    restart: always
    environment:
      POSTGRES_DB: eln_production
      POSTGRES_USER: eln_admin
      POSTGRES_PASSWORD: secure_biolab_password
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./src/biolabcalc/eln/schema/ddl.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"

  eln:
    build: .
    restart: always
    depends_on:
      - db
    environment:
      DATABASE_URL: postgresql://eln_admin:secure_biolab_password@db:5432/eln_production
      BIOLABCALC_STORAGE_DIR: /data/storage
      BIOLABCALC_AUDIT_LOG: /data/storage/audit_ledger.jsonl
    volumes:
      - eln_data:/data/storage
    ports:
      - "8080:8080"
    command: ["biolabcalc", "eln", "--host", "0.0.0.0", "--port", "8080", "--no-browser"]

volumes:
  pgdata:
  eln_data:

Launch the cluster:

docker-compose up -d

Option B: Linux Systemd Service

For standard bare-metal or virtual server deployments running on Ubuntu / Debian / RHEL:

Create /etc/systemd/system/biolabcalc-eln.service:

[Unit]
Description=BioLabCalc Electronic Lab Notebook & LIMS Service
After=network.target postgresql.service

[Service]
Type=simple
User=biolab
Group=biolab
WorkingDirectory=/opt/biolabcalc
Environment="PATH=/opt/biolabcalc/venv/bin:/usr/bin"
Environment="DATABASE_URL=postgresql://eln_user:secret@localhost:5432/eln_production"
Environment="BIOLABCALC_STORAGE_DIR=/var/lib/biolabcalc/data"
ExecStart=/opt/biolabcalc/venv/bin/biolabcalc eln --host 127.0.0.1 --port 8080 --no-browser
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now biolabcalc-eln.service

Option C: Production Nginx Reverse Proxy Configuration

Deploy Nginx in front of BioLabCalc to manage SSL/TLS termination, request buffering, client upload limits, and WebSocket upgrade protocols:

server {
    listen 80;
    server_name eln.lab.institution.edu;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name eln.lab.institution.edu;

    ssl_certificate /etc/letsencrypt/live/eln.lab.institution.edu/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/eln.lab.institution.edu/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    # Allow large instrument file uploads (FPLC runs, gel micrographs up to 500 MB)
    client_max_body_size 500M;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket support for real-time timer sync and live updates
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400s;
        proxy_send_timeout 86400s;
    }
}

⚑ Performance Tuning & Storage Maintenance

1. SQLite Concurrency (WAL Mode)

When running the embedded SQLite engine in multi-threaded laboratory setups, enable Write-Ahead Logging (WAL) mode to permit concurrent readers during writes:

PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA cache_size = -64000; -- 64 MB memory cache
PRAGMA foreign_keys = ON;

2. CAS Blob Store Deduplication & Pruning

Content-Addressed Storage automatically deduplicates uploads based on SHA-256 hash digests. To remove unreferenced "orphan" blobs (e.g. from deleted temporary drafts):

from biolabcalc.eln.storage.blob_store import BlobStore

store = BlobStore(base_dir="/var/lib/biolabcalc/data/blobs")
# Enumerate all physical blobs
all_blobs = store.list_blobs()
print(f"Total stored blobs: {len(all_blobs)}")

3. Disaster Recovery & Backup Strategy

  • Database Backup: Standard automated PostgreSQL dumps:
    pg_dump -U eln_admin -Fc eln_production > /backup/eln_$(date +%Y%m%d_%H%M%S).dump
  • CAS Blob Synchronization: Because blobs are immutable and named by SHA-256 hashes, they can be synchronized incrementally to cold storage (e.g. AWS S3 Glacier or NAS) using rsync or S3 sync:
    rsync -av --ignore-existing /var/lib/biolabcalc/data/blobs/ /mnt/backup_nas/blobs/

πŸ”— Related Documentation

Clone this wiki locally