# twlab/cig-pipelines architecture

> Architecture diagram of the GitHub repository twlab/cig-pipelines, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/twlab/cig-pipelines
- Repository: https://github.com/twlab/cig-pipelines

## Overview

##### Project type and purpose
- This is an open-source collection of genomics workflows, tools, and tasks written in Workflow Description Language (WDL).
- Its purpose is to bundle end-to-end genomics pipelines (under wdl/pipelines), reusable tasks (wdl/tasks), small combiners (wdl/tools), and shared data structures (wdl/structs), which users execute on a WDL engine (e.g., Cromwell, miniWDL) against local or cloud compute backends.

##### File structure
- Top-level directories:
- scripts: auxiliary shell or Python scripts (e.g., build_imports)
- wdl/pipelines: full-scale workflows wrapping many tasks
- wdl/tasks: low-level task wrappers around CLI tools and scripts
- wdl/tools: mid-level workflows combining a handful of tasks
- wdl/structs: type and runtime definitions shared by pipelines, tools, tasks
- Dockerfiles reside alongside certain WDLs to define containerized execution environments.
- JSON/YAML files next to each WDL show input schemas and expected outputs—helpful for understanding data flows.

##### Key insights from README
- Pipelines call tasks and tools in a layered fashion, using structs to enforce input/output contracts.
- Docker images are stored in a separate repo and referenced in each task/tool WDL.
- The execution engine (external) orchestrates tasks, schedules jobs on HPC or cloud, and collects results.

a. Main components
- WDL Execution Engine (e.g., Cromwell)
- Pipeline definitions (wdl/pipelines)
- Task modules (wdl/tasks)
- Tool workflows (wdl/tools)
- Struct/type definitions (wdl/structs)
- Docker/Container Registry (external)
- Compute Infrastructure (local HPC nodes or cloud batch/VMs)
- Artifact storage (e.g., S3 buckets, shared filesystem)

b. Relationships and interactions
– Pipelines reference tools and tasks by import statements
– Tools group multiple tasks into higher-level workflows
– Tasks declare Docker container URIs for execution
– The engine schedules each task on compute nodes, pulling containers from the registry
– Struct definitions resolve data types and enforce compatibility across imports
– Artifacts (inputs/outputs) are staged on the shared filesystem or object storage

c. Architectural patterns and design principles
– Layered modularity: pipelines → tools → tasks → containerized commands
– Separation of concerns: structs for types, tasks for single commands, tools for mini-workflows, pipelines for full workflows
– Declarative orchestration: WDL engine drives execution graph based on data dependencies
– Reusability: tasks and tools can be swapped or combined without rewriting pipelines

d. Key technologies and frameworks
– WDL specification and workflow imports mechanism
– Docker containers for reproducible environments
– JSON/YAML schemas for CI validation (inputs/outputs)
– External WDL runner (Cromwell, miniWDL, Toil-WDL)
– Execution backends (SLURM, Google Pipelines API, AWS Batch)

##### Essential details
- Layered structure: top-level pipelines calling into mid-level tools and low-level tasks.
- Container pull as part of task execution.
- Data flow clearly: inputs (FASTQ, BAM, references) → tasks → interim files → final outputs (VCF, reports).
- Special patterns (e.g., scatter/gather in WDL for parallelism).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "WDL Artifacts"
        direction TB
        Structs["Struct/Type Definitions"]:::wdl
        Tasks["Task Modules"]:::wdl
        Tools["Tool Workflows"]:::wdl
        Pipelines["Pipeline Definitions"]:::wdl
    end

    ExecutionEngine["WDL Execution Engine"]:::engine
    ContainerRegistry["Container Registry"]:::external
    ComputeInfra["Compute Infrastructure"]:::infra
    Storage["Artifact Storage"]:::external
    Scripts["Auxiliary Scripts"]:::wdl

    %% Relationships
    Pipelines -->|"import"| Tools
    Pipelines -->|"import"| Tasks
    Pipelines -->|"import"| Structs
    Tools -->|"import"| Tasks
    Tools -->|"import"| Structs
    Tasks -->|"import"| Structs
    Tasks -->|"runtime/container pull"| ContainerRegistry
    ExecutionEngine -->|"execute pipelines"| Pipelines
    ExecutionEngine -->|"schedule/execute"| ComputeInfra
    ComputeInfra -->|"read/write artifacts"| Storage
    Storage -->|"provide inputs/collect outputs"| ComputeInfra
    Scripts -->|"generate imports"| Pipelines

    %% Click Events
    click Pipelines "https://github.com/twlab/cig-pipelines/tree/main/wdl/pipelines"
    click Tasks "https://github.com/twlab/cig-pipelines/tree/main/wdl/tasks"
    click Tools "https://github.com/twlab/cig-pipelines/tree/main/wdl/tools"
    click Structs "https://github.com/twlab/cig-pipelines/tree/main/wdl/structs"
    click Scripts "https://github.com/twlab/cig-pipelines/tree/main/scripts/build_imports"
    click ContainerRegistry "https://github.com/twlab/cig-pipelines/blob/main/wdl/pipelines/rna/encode.Dockerfile"
    click Pipelines "https://github.com/twlab/cig-pipelines/blob/main/wdl/pipelines/cactus.inputs.json"
    click Pipelines "https://github.com/twlab/cig-pipelines/blob/main/wdl/pipelines/cactus.outputs.yaml"

    %% Styles
    classDef wdl fill:#cce5ff,stroke:#3399ff,color:#000000
    classDef external fill:#e0ffe0,stroke:#33cc33,color:#000000
    classDef engine fill:#ffe5cc,stroke:#ff9933,color:#000000
    classDef infra fill:#ffe5cc,stroke:#ff9933,color:#000000
```
