# mrmonk12345/ard-database-workbench architecture

> Architecture diagram of the GitHub repository mrmonk12345/ard-database-workbench, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mrmonk12345/ard-database-workbench
- Repository: https://github.com/mrmonk12345/ard-database-workbench

## Overview

#### Purpose and Operating Model

ARD is a filesystem-backed SQLite system for managing amplicon-sequencing projects from experimental metadata through raw reads, pipeline execution, and uploaded analysis results. The database is the source of truth; directories hold staged inputs, reads, generated datasets, and pipeline artifacts. Core schema and a sample database are at `schema.sql`, `example_database.db`, and `database.md`.

#### Database and Metadata Layer

SQLite models projects, treatments, samples, libraries, sequencing outputs, amplicon types, analysis units, datasets, and pipeline-related records. The schema is defined in `schema.sql`; SQL queries produce analysis-specific views and exports in `scripts/sql/get_manifest_data_for_dataset.sql`, `scripts/sql/get_limited_data_for_sample_metadata.sql`, and `scripts/sql/get_amplicon_type_data_for_dataset.sql`. Python DB access/adaptation is concentrated in `scripts/python/db_get_data.py`, `scripts/python/db_get_columns.py`, and `scripts/python/refresh_labels.py`.

#### Interactive Data Management

A Python GUI provides database inspection, project/treatment views, record-entry windows, and TSV export. Its application entry point is `gui/main.py`; main composition and navigation are in `gui/main_window.py` and `gui/general_sections.py`. Domain-specific project and treatment interfaces live in `gui/project_sections.py`, `gui/project_data_window.py`, and `gui/treatment_sections.py`.

#### Incoming Data and Read Organization

New tabular data is staged before database insertion in `input_staging/`; raw FASTQ data is organized by project in `raw_reads_projects/`. Primer demultiplexing is a boundary between raw reads and analysis inputs, implemented by `scripts/python/0_demultiplex_primers_and_gzip.py` with shell launchers at `demultiplex_multiple_primers.sh` and `scripts/shell/demultiplex_multiple_primers.sh`.

#### Dataset Materialization

Database records are transformed into reusable analysis datasets and files. `scripts/python/dataset_base_make_inputs.py` and `scripts/python/dataset_base_write_inputs.py` coordinate extraction/writing; numbered scripts generate gzipped analysis files, manifests, sample metadata, amplicon metadata, and links: `scripts/python/1_dataset_to_analysis_files_simple_gzip.py`, `scripts/python/2_dataset_to_manifest_file.py`, and `scripts/python/5_dataset_symlink_files.py`. Outputs cross into `analysis_files/` and `analysis_datasets/`.

#### Pipeline Handoff and Execution Tracking

Dataset directories are converted into pipeline-run directories by `scripts/python/6_dataset_directory_to_pipeline_run_directory.py` and `scripts/python/create_pipeline_run.py`. Pipeline inputs can also be generated directly from database state via `scripts/python/database_to_pipeline_input.py` and `database_to_pipeline_input.sh`. Runs and their outputs reside under `pipeline_runs/`; the intended external analysis runtime is QIIME workflows, likely executed on the documented ARO HPC environment.

#### Result Ingestion and Traceability

Pipeline outputs return to SQLite through targeted upload scripts: `scripts/python/upload_pipeline_run_results_to_database.py`, `scripts/python/upload_feature_counts_to_database.py`, `scripts/python/upload_taxonomy_to_database.py`, and `scripts/python/upload_asvs_fasta_to_database.py`. `scripts/python/update_pipeline_run_from_snakemake.py` updates run state from Snakemake, forming the control boundary between external workflow execution and database lifecycle tracking. The runtime stack is Python, Bash, SQLite, Conda, QIIME, and Snakemake, with DB Browser for SQLite as an operational inspection tool.

Main entry points: [`schema.sql`](https://github.com/mrmonk12345/ard-database-workbench/blob/main/schema.sql) (ARD schema), [`scripts/python/1_dataset_to_analysis_files_simple_gzip.py`](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/1_dataset_to_analysis_files_simple_gzip.py) (Dataset file generators), [`scripts/python/dataset_base_make_inputs.py`](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/dataset_base_make_inputs.py) (Dataset input builder), [`gui/main.py`](https://github.com/mrmonk12345/ard-database-workbench/blob/main/gui/main.py) (Management GUI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_db["SQLite metadata"]
  node_schema[("ARD schema<br/>SQLite schema<br/>[schema.sql]")]
  node_sql_queries["Analysis SQL queries<br/>SQL exports"]
  node_db_access["DB access adapters<br/>Python data access<br/>[db_get_data.py]"]
  node_label_refresh["Label refresh<br/>Python maintenance<br/>[refresh_labels.py]"]
end

subgraph group_manage["Data management"]
  node_gui["Management GUI<br/>Python GUI<br/>[main.py]"]
  node_gui_project_views["Project and treatment views<br/>GUI domain views"]
  node_staging["Tabular staging<br/>filesystem staging"]
  node_raw_reads[("Project raw reads<br/>FASTQ storage")]
end

subgraph group_materialize["Dataset preparation"]
  node_demultiplex["Primer demultiplexing<br/>Python/Bash boundary"]
  node_dataset_builder["Dataset input builder<br/>Python orchestration"]
  node_dataset_exports["Dataset file generators<br/>Python export scripts"]
  node_analysis_files["Analysis files<br/>generated inputs"]
  node_analysis_datasets["Dataset directories<br/>generated datasets"]
end

subgraph group_pipeline["Pipeline lifecycle"]
  node_run_creator["Pipeline run creator<br/>Python handoff"]
  node_pipeline_runs["Pipeline runs<br/>workflow artifacts"]
  node_qiime_snakemake{{"QIIME and Snakemake<br/>external workflow runtime"}}
  node_run_state_update["Run state updater<br/>Python lifecycle sync"]
  node_result_upload["Result uploaders<br/>Python ingestion"]
end

node_schema -->|"defines queryable records"| node_sql_queries
node_schema -->|"read and adapt"| node_db_access
node_label_refresh -->|"maintains labels"| node_schema
node_staging -->|"inserted as metadata"| node_schema
node_gui -->|"uses"| node_db_access
node_gui -->|"composes"| node_gui_project_views
node_gui_project_views -->|"inspect and edit"| node_schema
node_raw_reads -->|"FASTQ input"| node_demultiplex
node_schema -->|"dataset records"| node_dataset_builder
node_sql_queries -->|"manifest and metadata"| node_dataset_builder
node_demultiplex -->|"organized reads"| node_dataset_exports
node_dataset_builder -->|"dataset inputs"| node_dataset_exports
node_dataset_exports -->|"writes"| node_analysis_files
node_dataset_exports -->|"materializes"| node_analysis_datasets
node_analysis_datasets -->|"source directories"| node_run_creator
node_run_creator -->|"creates"| node_pipeline_runs
node_pipeline_runs -->|"workflow execution"| node_qiime_snakemake
node_qiime_snakemake -->|"Snakemake status"| node_run_state_update
node_run_state_update -->|"updates run lifecycle"| node_schema
node_qiime_snakemake -->|"analysis outputs"| node_result_upload
node_result_upload -->|"ingests results"| node_schema

click node_schema "https://github.com/mrmonk12345/ard-database-workbench/blob/main/schema.sql"
click node_sql_queries "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/sql/get_manifest_data_for_dataset.sql"
click node_db_access "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/db_get_data.py"
click node_label_refresh "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/refresh_labels.py"
click node_gui "https://github.com/mrmonk12345/ard-database-workbench/blob/main/gui/main.py"
click node_gui_project_views "https://github.com/mrmonk12345/ard-database-workbench/blob/main/gui/project_sections.py"
click node_demultiplex "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/0_demultiplex_primers_and_gzip.py"
click node_dataset_builder "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/dataset_base_make_inputs.py"
click node_dataset_exports "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/1_dataset_to_analysis_files_simple_gzip.py"
click node_run_creator "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/6_dataset_directory_to_pipeline_run_directory.py"
click node_run_state_update "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/update_pipeline_run_from_snakemake.py"
click node_result_upload "https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/upload_pipeline_run_results_to_database.py"

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_schema,node_sql_queries,node_db_access,node_label_refresh toneBlue
class node_gui,node_gui_project_views,node_staging,node_raw_reads toneAmber
class node_demultiplex,node_dataset_builder,node_dataset_exports,node_analysis_files,node_analysis_datasets toneMint
class node_run_creator,node_pipeline_runs,node_qiime_snakemake,node_run_state_update,node_result_upload toneRose
```

## Components

### SQLite metadata

System of record and query layer.

- [ARD schema](https://github.com/mrmonk12345/ard-database-workbench/blob/main/schema.sql): SQLite schema · Models experimental, dataset, and pipeline records. · `schema.sql`
- [Analysis SQL queries](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/sql/get_manifest_data_for_dataset.sql): SQL exports · Produces dataset manifests and metadata extracts. · `scripts/sql/get_manifest_data_for_dataset.sql`
- [DB access adapters](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/db_get_data.py): Python data access · `scripts/python/db_get_data.py`
- [Label refresh](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/refresh_labels.py): Python maintenance · `scripts/python/refresh_labels.py`

### Data management

- [Management GUI](https://github.com/mrmonk12345/ard-database-workbench/blob/main/gui/main.py): Python GUI · Inspection, record entry, navigation, and TSV export. · `gui/main.py`
- [Project and treatment views](https://github.com/mrmonk12345/ard-database-workbench/blob/main/gui/project_sections.py): GUI domain views · `gui/project_sections.py`
- **Tabular staging**: filesystem staging · Incoming tabular data before database insertion.
- **Project raw reads**: FASTQ storage

### Dataset preparation

- [Primer demultiplexing](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/0_demultiplex_primers_and_gzip.py): Python/Bash boundary · Separates raw reads into analysis-ready inputs. · `scripts/python/0_demultiplex_primers_and_gzip.py`
- [Dataset input builder](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/dataset_base_make_inputs.py): Python orchestration · Extracts database records and writes reusable dataset inputs. · `scripts/python/dataset_base_make_inputs.py`
- [Dataset file generators](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/1_dataset_to_analysis_files_simple_gzip.py): Python export scripts · Generates compressed files, manifests, metadata, and links. · `scripts/python/1_dataset_to_analysis_files_simple_gzip.py`
- **Analysis files**: generated inputs
- **Dataset directories**: generated datasets

### Pipeline lifecycle

- [Pipeline run creator](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/6_dataset_directory_to_pipeline_run_directory.py): Python handoff · Converts dataset directories into pipeline-run directories. · `scripts/python/6_dataset_directory_to_pipeline_run_directory.py`
- **Pipeline runs**: workflow artifacts · Run inputs and outputs tracked against database lifecycle records.
- **QIIME and Snakemake**: external workflow runtime · Executes analysis workflows and reports run state.
- [Run state updater](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/update_pipeline_run_from_snakemake.py): Python lifecycle sync · `scripts/python/update_pipeline_run_from_snakemake.py`
- [Result uploaders](https://github.com/mrmonk12345/ard-database-workbench/blob/main/scripts/python/upload_pipeline_run_results_to_database.py): Python ingestion · Loads feature counts, taxonomy, and ASV FASTA into SQLite. · `scripts/python/upload_pipeline_run_results_to_database.py`

## Connections

- ARD schema → Analysis SQL queries: defines queryable records
- ARD schema → DB access adapters: read and adapt
- Label refresh → ARD schema: maintains labels
- Tabular staging → ARD schema: inserted as metadata
- Management GUI → DB access adapters: uses
- Management GUI → Project and treatment views: composes
- Project and treatment views → ARD schema: inspect and edit
- Project raw reads → Primer demultiplexing: FASTQ input
- ARD schema → Dataset input builder: dataset records
- Analysis SQL queries → Dataset input builder: manifest and metadata
- Primer demultiplexing → Dataset file generators: organized reads
- Dataset input builder → Dataset file generators: dataset inputs
- Dataset file generators → Analysis files: writes
- Dataset file generators → Dataset directories: materializes
- Dataset directories → Pipeline run creator: source directories
- Pipeline run creator → Pipeline runs: creates
- Pipeline runs → QIIME and Snakemake: workflow execution
- QIIME and Snakemake → Run state updater: Snakemake status
- Run state updater → ARD schema: updates run lifecycle
- QIIME and Snakemake → Result uploaders: analysis outputs
- Result uploaders → ARD schema: ingests results
