# aces/loris-mri architecture

> Architecture diagram of the GitHub repository aces/loris-mri, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aces/loris-mri
- Repository: https://github.com/aces/loris-mri

## Overview

1. **What this repository is**
   - This is the imaging-ingestion companion to the main LORIS platform, not the core web app itself.
   - Its job is to move imaging and related acquisition data from raw files into a structured archive and a relational database, then trigger downstream validation, conversion, and insertion steps.

2. **Primary runtime split: legacy Perl + newer Python**
   - The repo is intentionally hybrid.
   - **Perl** still drives much of the historical pipeline and operational tooling: `uploadNeuroDB/`, `DTIPrep/`, `dicom-archive/`, and `tools/`.
   - **Python 3.11** hosts newer pipeline code, database models/queries, BIDS importers, and helper scripts under `python/`.
   - This split is important architecturally because the Python side largely wraps or modernizes behaviors that already exist in the Perl stack.

3. **Core storage boundary: relational database**
   - The main stateful boundary is the LORIS imaging database.
   - Python has a substantial ORM-style layer in `python/lib/db/models` and `python/lib/db/queries`, while Perl uses object-broker modules in `uploadNeuroDB/NeuroDB/objectBroker`.
   - The schema includes imaging uploads, DICOM archive records, MRI protocol/violation tracking, candidate/session/project metadata, physiological files, and notification spool tables.
   - Test SQL in `test/RB_SQL/` mirrors those tables, showing the database is a first-class integration point.

4. **Filesystem and archive boundary**
   - Raw and derived imaging data are managed on disk, typically under `/data/$projectname` and `/opt/$projectname`.
   - The installer configures these paths and permissions, and the pipeline assumes shared filesystem access between LORIS and the imaging worker host.
   - Many scripts operate by reading from archive directories, writing converted outputs, and updating DB records to reflect file locations and processing status.

5. **DICOM archive and study import subsystem**
   - `dicom-archive/` and `python/loris_dicom_importer/` handle DICOM-centric ingestion and summarization.
   - These components extract metadata, summarize studies, tar/archive data, and support updating MRI upload records.
   - The flow is: raw DICOM arrives, metadata is summarized and validated, archive records are created/updated, and the database becomes the source of truth for what was ingested.

6. **Imaging pipeline orchestration**
   - `python/lib/dcm2bids_imaging_pipeline_lib/` contains the newer pipeline framework.
   - It exposes distinct pipeline stages such as:
     - DICOM archive loading
     - DICOM validation
     - NIfTI insertion
     - pushing imaging files to S3
   - The corresponding entrypoint scripts in `python/scripts/` are thin wrappers that launch those stages operationally.
   - This subsystem is where the architecture most clearly separates orchestration from domain logic.

7. **BIDS import and export support**
   - `python/loris_bids_reader/` parses BIDS datasets and their sidecars, scans, participants, and events files.
   - `python/lib/import_bids_dataset/` uses that reader to validate subjects/sessions, copy files, and map BIDS content into LORIS concepts.
   - This is a distinct ingestion path from DICOM: instead of converting raw scanner output first, it accepts an already-BIDS-shaped dataset and maps it into the database and archive.

8. **Electrophysiology and physiological data**
   - The repo is not MRI-only.
   - `python/loris_ephys_chunker/` and `python/lib/physio/` manage electrophysiology chunking and physiological event/file structures.
   - `python/lib/database_lib/physiological_*` and matching DB models/queries show a parallel ingestion model for physio/ephys data with archives, channels, events, parameters, and output types.
   - This is a separate domain boundary, but it reuses the same DB-centric and filesystem-centric architecture.

9. **MNI/MINC and image-processing utilities**
   - The `MNI/` Perl modules and many scripts under `tools/` and `uploadNeuroDB/bin/` depend on the MINC toolkit and DICOM utilities.
   - These utilities support format conversion, concatenation, defacing, header updates, and other image-processing steps used by the insertion pipeline.
   - The README’s installation steps make clear that external toolchains like MINC and dcmtk are required system dependencies, not optional libraries.

10. **DTI/DTIPrep and legacy processing path**
   - `DTIPrep/` contains scripts and modules for diffusion MRI quality control and registration-related processing.
   - This indicates a legacy but still operational branch for DTI-specific preprocessing before or alongside database insertion.
   - It sits beside the broader imaging pipeline rather than inside the newer Python orchestration layer.

11. **Operational entrypoints and batch jobs**
   - The repository includes many executable scripts for batch operations: uploads, validation, cleanup, header updates, tarchive management, defacing, and conversions.
   - These are designed for cron, manual ops, or pipeline automation on shared infrastructure.
   - In architecture terms, they are the “edges” that connect raw data arrival, scheduled maintenance, and DB/filehousekeeping.

12. **Infrastructure and deployment model**
   - Deployment is VM/fileserver oriented, not container-first.
   - The install scripts in `install/` configure directories, environment variables, CPAN dependencies, Python virtual environments, and database connectivity.
   - The repo assumes integration with the main LORIS environment, the MySQL database, local filesystem permissions, and sometimes S3 for file distribution.

13. **Validation and test boundaries**
   - GitHub Actions workflows and the Python test suite cover integration and ORM/SQL synchronization.
   - Docker-based test assets under `test/` suggest the database layer and scripts are validated in isolation from the full production environment.
   - This reinforces that the architecture’s critical contract is consistency between file processing and database state.

14. **How to draw the main architecture**
   - A good diagram would show multiple ingestion sources on the left: DICOM studies, BIDS datasets, NIfTI/MINC files, and physio/ephys data.
   - In the center, show pipeline workers in Perl and Python performing validation, conversion, chunking, and archiving.
   - On the right, show the shared LORIS imaging database plus filesystem archive storage, with optional S3 as an external distribution target.
   - Around that, place the MINC/DCMTK/DTIPrep toolchain as external processing dependencies and the main LORIS platform as the consuming system for metadata and upload status.

Main entry points: [`python/lib/dcm2bids_imaging_pipeline_lib`](https://github.com/aces/loris-mri/tree/main/python/lib/dcm2bids_imaging_pipeline_lib) (Pipeline lib), [`uploadNeuroDB`](https://github.com/aces/loris-mri/tree/main/uploadNeuroDB) (UploadNeuroDB), [`dicom-archive`](https://github.com/aces/loris-mri/tree/main/dicom-archive) (DICOM archive), [`tools`](https://github.com/aces/loris-mri/tree/main/tools) (Ops tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_perl["Perl stack"]
  node_upload_neurodb["UploadNeuroDB<br/>Perl pipeline"]
  node_object_broker["Object broker<br/>Perl DB layer"]
  node_dicom_archive["DICOM archive<br/>Perl ingest"]
  node_legacy_tools["Ops tools<br/>Perl ops"]
  node_dtiprep["DTIPrep<br/>Perl DTI QC"]
  node_mni["MNI utils<br/>Perl imaging utils"]
end

subgraph group_python["Python stack"]
  node_py_pipeline["Pipeline lib<br/>Python orchestration"]
  node_py_scripts["Entrypoints<br/>Python CLI"]
  node_py_db_models["DB models<br/>Python ORM"]
  node_py_db_queries["DB queries<br/>Python query layer"]
  node_py_dicom_importer["DICOM importer<br/>Python import"]
  node_py_bids_reader["BIDS reader<br/>Python parser"]
  node_py_bids_import["BIDS import<br/>Python import"]
  node_py_ephys["Ephys chunker<br/>Python ephys"]
  node_py_physio["Physio libs<br/>Python physio"]
end

subgraph group_storage["State boundaries"]
  node_db[("LORIS DB<br/>MySQL state")]
  node_archive_fs["Archive FS<br/>Filesystem archive"]
  node_s3["S3 bucket<br/>Object storage"]
end

subgraph group_deps["External tools"]
  node_loris_platform["LORIS platform<br/>Consumer app"]
  node_toolchain["MINC/DCMTK<br/>System deps"]
end

node_dicom_archive -->|"update archive"| node_db
node_upload_neurodb -->|"insert/update"| node_db
node_object_broker -->|"ORM access"| node_db
node_py_db_models -->|"map schema"| node_db
node_py_db_queries -->|"query state"| node_db
node_py_dicom_importer -->|"import studies"| node_db
node_py_bids_import -->|"map BIDS"| node_db
node_py_ephys -->|"track chunks"| node_db
node_py_physio -->|"physio records"| node_db
node_py_scripts -->|"launch"| node_py_pipeline
node_py_pipeline -->|"read/write"| node_archive_fs
node_upload_neurodb -->|"process files"| node_archive_fs
node_dicom_archive -->|"tar/summarize"| node_archive_fs
node_py_bids_reader -->|"parse inputs"| node_py_bids_import
node_py_dicom_importer -->|"feeds validation"| node_py_pipeline
node_legacy_tools -->|"shell out"| node_toolchain
node_mni -->|"wrap tools"| node_toolchain
node_dtiprep -->|"QC pipeline"| node_toolchain
node_py_pipeline -->|"push files"| node_s3
node_db -->|"share state"| node_loris_platform
node_legacy_tools -->|"ops maintenance"| node_db
node_py_scripts -->|"batch jobs"| node_db

click node_upload_neurodb "https://github.com/aces/loris-mri/tree/main/uploadNeuroDB"
click node_object_broker "https://github.com/aces/loris-mri/tree/main/uploadNeuroDB/NeuroDB/objectBroker"
click node_dicom_archive "https://github.com/aces/loris-mri/tree/main/dicom-archive"
click node_legacy_tools "https://github.com/aces/loris-mri/tree/main/tools"
click node_dtiprep "https://github.com/aces/loris-mri/tree/main/DTIPrep"
click node_mni "https://github.com/aces/loris-mri/tree/main/MNI"
click node_py_pipeline "https://github.com/aces/loris-mri/tree/main/python/lib/dcm2bids_imaging_pipeline_lib"
click node_py_scripts "https://github.com/aces/loris-mri/tree/main/python/scripts"
click node_py_db_models "https://github.com/aces/loris-mri/tree/main/python/lib/db/models"
click node_py_db_queries "https://github.com/aces/loris-mri/tree/main/python/lib/db/queries"
click node_py_dicom_importer "https://github.com/aces/loris-mri/tree/main/python/loris_dicom_importer"
click node_py_bids_reader "https://github.com/aces/loris-mri/tree/main/python/loris_bids_reader"
click node_py_bids_import "https://github.com/aces/loris-mri/tree/main/python/lib/import_bids_dataset"
click node_py_ephys "https://github.com/aces/loris-mri/tree/main/python/loris_ephys_chunker"
click node_py_physio "https://github.com/aces/loris-mri/tree/main/python/lib/physio"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_upload_neurodb,node_object_broker,node_dicom_archive,node_legacy_tools,node_dtiprep,node_mni toneBlue
class node_py_pipeline,node_py_scripts,node_py_db_models,node_py_db_queries,node_py_dicom_importer,node_py_bids_reader,node_py_bids_import,node_py_ephys,node_py_physio toneAmber
class node_db,node_archive_fs,node_s3 toneMint
class node_loris_platform,node_toolchain toneRose
```

## Components

### Perl stack

Legacy ingestion, archive handling, and operational scripts.

- [UploadNeuroDB](https://github.com/aces/loris-mri/tree/main/uploadNeuroDB): Perl pipeline · Core legacy MRI ingestion and insertion runtime. · `uploadNeuroDB`
- [Object broker](https://github.com/aces/loris-mri/tree/main/uploadNeuroDB/NeuroDB/objectBroker): Perl DB layer · Perl-side database access and record mappers for imaging entities. · `uploadNeuroDB/NeuroDB/objectBroker`
- [DICOM archive](https://github.com/aces/loris-mri/tree/main/dicom-archive): Perl ingest · Summarizes, tars, and updates DICOM study archive records. · `dicom-archive`
- [Ops tools](https://github.com/aces/loris-mri/tree/main/tools): Perl ops · Batch scripts for uploads, cleanup, conversion, and maintenance. · `tools`
- [DTIPrep](https://github.com/aces/loris-mri/tree/main/DTIPrep): Perl DTI QC · Legacy diffusion MRI preprocessing and quality-control path. · `DTIPrep`
- [MNI utils](https://github.com/aces/loris-mri/tree/main/MNI): Perl imaging utils · Shared MINC-oriented utilities and helpers used by image processing scripts. · `MNI`

### Python stack

Modern pipeline code, readers, importers, and ORM/query layers.

- [Pipeline lib](https://github.com/aces/loris-mri/tree/main/python/lib/dcm2bids_imaging_pipeline_lib): Python orchestration · Modern DICOM archive, validation, insertion, and S3 pipeline framework. · `python/lib/dcm2bids_imaging_pipeline_lib`
- [Entrypoints](https://github.com/aces/loris-mri/tree/main/python/scripts): Python CLI · Thin operational scripts that launch pipeline stages and batch jobs. · `python/scripts`
- [DB models](https://github.com/aces/loris-mri/tree/main/python/lib/db/models): Python ORM · Python model layer for MRI, candidate, session, physio, and archive records. · `python/lib/db/models`
- [DB queries](https://github.com/aces/loris-mri/tree/main/python/lib/db/queries): Python query layer · Query helpers that read and update imaging and physio state. · `python/lib/db/queries`
- [DICOM importer](https://github.com/aces/loris-mri/tree/main/python/loris_dicom_importer): Python import · Study summarization and database import for raw DICOM datasets. · `python/loris_dicom_importer`
- [BIDS reader](https://github.com/aces/loris-mri/tree/main/python/loris_bids_reader): Python parser · Parses BIDS datasets, sidecars, scans, participants, and events. · `python/loris_bids_reader`
- [BIDS import](https://github.com/aces/loris-mri/tree/main/python/lib/import_bids_dataset): Python import · Validates and maps BIDS datasets into LORIS imaging concepts. · `python/lib/import_bids_dataset`
- [Ephys chunker](https://github.com/aces/loris-mri/tree/main/python/loris_ephys_chunker): Python ephys · Chunks electrophysiology data for ingestion and archival. · `python/loris_ephys_chunker`
- [Physio libs](https://github.com/aces/loris-mri/tree/main/python/lib/physio): Python physio · Physiological file, event, parameter, and chunking support. · `python/lib/physio`

### State boundaries

Shared database and filesystem/archive targets.

- **LORIS DB**: MySQL state · Shared imaging database for uploads, archive records, protocol checks, physio, and notifications.
- **Archive FS**: Filesystem archive · Shared project directories for raw, derived, and inserted imaging data.
- **S3 bucket**: Object storage · Optional external distribution target for imaging files.

### External tools

System toolchains and downstream platforms used by the pipelines.

- **LORIS platform**: Consumer app · Main platform that consumes imaging metadata, upload status, and validated records.
- **MINC/DCMTK**: System deps · External conversion, archive, and header-editing toolchains required by ingestion scripts.

## Connections

- DICOM archive → LORIS DB: update archive · Creates and updates DICOM archive and MRI upload records.
- UploadNeuroDB → LORIS DB: insert/update · Writes imaging, candidate, protocol, and notification state.
- Object broker → LORIS DB: ORM access · Perl database access layer for imaging entities.
- DB models → LORIS DB: map schema · Python ORM models mirror the imaging database tables.
- DB queries → LORIS DB: query state · Python query layer reads and mutates persistent imaging state.
- DICOM importer → LORIS DB: import studies · Summarizes DICOM studies and records import results.
- BIDS import → LORIS DB: map BIDS · Validates BIDS content and stores mapped subjects, sessions, and files.
- Ephys chunker → LORIS DB: track chunks · Persists electrophysiology and associated archive metadata.
- Physio libs → LORIS DB: physio records · Handles physiological files, events, parameters, and archive objects.
- Entrypoints → Pipeline lib: launch · Operational wrappers invoke pipeline stages.
- Pipeline lib → Archive FS: read/write · Loads archive data, validates inputs, inserts outputs, and stages files.
- UploadNeuroDB → Archive FS: process files · Legacy insertion scripts read and write shared imaging directories.
- DICOM archive → Archive FS: tar/summarize · Builds study archives and stores file-location metadata.
- BIDS reader → BIDS import: parse inputs · Provides structured BIDS metadata to the importer.
- DICOM importer → Pipeline lib: feeds validation · DICOM study summaries feed the newer pipeline flow.
- Ops tools → MINC/DCMTK: shell out · Batch utilities depend on MINC and DICOM command-line tools.
- MNI utils → MINC/DCMTK: wrap tools · Perl utilities provide MINC-oriented helper functions.
- DTIPrep → MINC/DCMTK: QC pipeline · DTI preprocessing depends on external imaging utilities.
- Pipeline lib → S3 bucket: push files · Optional stage publishes imaging files to object storage.
- LORIS DB → LORIS platform: share state · Downstream platform consumes validated imaging metadata and status.
- Ops tools → LORIS DB: ops maintenance · Batch scripts manage uploads, cleanup, and record reconciliation.
- Entrypoints → LORIS DB: batch jobs · Entry scripts perform ingestion and maintenance jobs against the database.
