# clinical-genomics/cg architecture

> Architecture diagram of the GitHub repository clinical-genomics/cg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/clinical-genomics/cg
- Repository: https://github.com/clinical-genomics/cg

## Overview

##### Main Components Identification

The system should be divided into these major components:

a. Core Services Layer:
- Database Service (using SQLAlchemy, evident from alembic migrations)
- REST API Service (for web portal integration)
- CLI Service (for command-line operations)

b. Integration Services Layer:
- Illumina Sequencing Service
- PacBio Sequencing Service
- File Management Services
- Analysis Pipeline Services
- Quality Control Services
- Delivery Services

c. External Systems Integration:
- Scout (variant visualization)
- Housekeeper (file management)
- Trailblazer (analysis tracking)
- LIMS Integration
- Web Portal Integration

##### Relationships and Data Flow

- CLI/API → Core Services → Integration Services
- Integration Services ↔ External Systems
- All components ↔ Database Service

##### Detailed Component Breakdown

For each major component, include subcomponents:

a. File Management:
- Compression Service
- Backup Service
- Archive Service
- Transfer Service

b. Analysis Workflows:
- MIP Pipeline
- BALSAMIC Pipeline
- RareDiseases Pipeline
- RNA Fusion Pipeline
- Microsalt Pipeline

c. Quality Control:
- Sequencing QC
- Analysis QC
- Delivery QC

##### Specific Implementation Details

- The modular structure (evident from the /cg/apps/ directory)
- The workflow management system (visible in /cg/meta/workflow/)
- The multi-database architecture (shown in store/models.py)
- The extensive API integration capabilities (seen in /cg/apps/ structure)

##### Storage Layer

Remember to include version control integration points and deployment paths, as indicated by the presence of GitHub workflows in the repository.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#333
    classDef integration fill:#90EE90,stroke:#333
    classDef external fill:#FFB366,stroke:#333
    classDef storage fill:#E6E6E6,stroke:#333
    classDef api fill:#FFE6CC,stroke:#333
    classDef critical fill:#FF9999,stroke:#333

    %% User Interface Layer
    subgraph UI
        CLI["CLI Service"]
        API["REST API Service"]
        WEB["Web Portal"]
    end

    %% Core Services Layer
    subgraph Core
        DB[(Database Service)]
        FS["File Management"]
        ORD["Order Management"]
    end

    %% Integration Services Layer
    subgraph Integration
        ILL["Illumina Sequencing"]
        PAC["PacBio Sequencing"]
        ANA["Analysis Service"]
        QC["Quality Control"]
        DEL["Delivery Service"]
    end

    %% Analysis Workflows
    subgraph Workflows
        MIP["MIP Pipeline"]
        BAL["BALSAMIC Pipeline"]
        RARE["RareDiseases Pipeline"]
        RNA["RNA Fusion Pipeline"]
        MIC["Microsalt Pipeline"]
    end

    %% File Management Services
    subgraph FileServices
        COMP["Compression Service"]
        BACK["Backup Service"]
        ARCH["Archive Service"]
        TRANS["Transfer Service"]
    end

    %% External Systems
    subgraph External
        SCOUT{{Scout}}
        HK{{Housekeeper}}
        TRAIL{{Trailblazer}}
        LIMS{{LIMS}}
    end

    %% Relationships
    CLI --> DB
    API --> DB
    WEB --> API
    
    DB --> FS
    DB --> ORD
    
    FS --> FileServices
    ORD --> Integration
    
    Integration --> Workflows
    Workflows --> QC
    QC --> DEL
    
    Integration --> External
    DEL --> External
    
    %% Click Events
    click CLI "https://github.com/clinical-genomics/cg/tree/master/cg/cli/"
    click API "https://github.com/clinical-genomics/cg/tree/master/cg/server/"
    click DB "https://github.com/clinical-genomics/cg/tree/master/cg/store/"
    click ILL "https://github.com/clinical-genomics/cg/tree/master/cg/services/illumina/"
    click PAC "https://github.com/clinical-genomics/cg/tree/master/cg/services/run_devices/pacbio/"
    click FS "https://github.com/clinical-genomics/cg/tree/master/cg/services/deliver_files/"
    click ANA "https://github.com/clinical-genomics/cg/tree/master/cg/services/analysis_service/"
    click QC "https://github.com/clinical-genomics/cg/tree/master/cg/services/sequencing_qc_service/"
    click DEL "https://github.com/clinical-genomics/cg/tree/master/cg/services/delivery_message/"
    click SCOUT "https://github.com/clinical-genomics/cg/tree/master/cg/apps/scout/"
    click HK "https://github.com/clinical-genomics/cg/tree/master/cg/apps/housekeeper/"
    click LIMS "https://github.com/clinical-genomics/cg/tree/master/cg/apps/lims/"
    click COMP "https://github.com/clinical-genomics/cg/tree/master/cg/apps/crunchy/"
    click ORD "https://github.com/clinical-genomics/cg/tree/master/cg/services/orders/"
    click Workflows "https://github.com/clinical-genomics/cg/tree/master/cg/meta/workflow/"

    %% Legend
    subgraph Legend
        L1[Service]:::core
        L2[Integration Service]:::integration
        L3{{External System}}:::external
        L4[(Database)]:::storage
    end

    %% Style Applications
    CLI:::core
    API:::core
    DB:::storage
    ILL:::integration
    PAC:::integration
    ANA:::integration
    QC:::integration
    DEL:::integration
    SCOUT:::external
    HK:::external
    TRAIL:::external
    LIMS:::external
```
