# bihealth/digestiflow-cli architecture

> Architecture diagram of the GitHub repository bihealth/digestiflow-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bihealth/digestiflow-cli
- Repository: https://github.com/bihealth/digestiflow-cli

## Overview

##### Main Components
- CLI Interface: The entry point (src/main.rs) that parses command-line arguments and flags (like --ingest, --analyze-adapters, etc.). It coordinates further actions.
- Configuration Loader: A component that reads the user’s global configuration file (typically ~/.digestiflowrc.toml), which contains parameters like thread count, API URL, token, and ingest options.
- Ingestion Module: Under src/ingest, this set of components (api.rs, bcl_data.rs, bcl_meta.rs, mod.rs) is responsible for:
– Reading flow cell directories.
– Parsing meta information from files such as RunParameters.xml and RunInfo.xml.
– Preparing data for the REST API.
- Adapter Analysis Module: Also part of the ingestion process, which—when enabled—computes histograms of index reads. This module triggers additional API queries and processing, depending on the --analyze-adapters flag.
- REST API Client: The part of the system that interacts with the Digestiflow Web’s REST API. This is used for querying existing flow cell records, updating them, or creating new flow cell entries.
- External Digestiflow Web System: Though outside of the project itself, represent the target external API endpoint that this client communicates with.

##### Relationships and Interaction
- The CLI Interface (main entry point) accepts user input and flags then passes this along to the Configuration Loader.
- With configuration settings (like API token, URL, and thread settings) in hand, the CLI then initiates the Ingestion Module.
- The Ingestion Module processes the input directories, reads in meta-information from the Illumina-generated files, and decides how to act (update an existing flow cell vs. creating a new one).
- If adapter analysis is necessary, the Adapter Analysis Module is invoked to compute and verify the histogram information.
- Data flows from the Ingestion Module to the REST API Client, which makes HTTP calls to the Digestiflow Web system. The external system’s response might also influence further processing (e.g., whether or not to update an entry).
- Thread handling (as hinted by the configuration) suggests that these operations may be multi-threaded to enhance performance.

##### Architectural Patterns and Principles
- Modular Design: Different modules (CLI, Configuration, Ingest, Analysis, API Client) are clearly separated into distinct directories/files.
- Separation of Concerns: Each module handles a specific aspect of the workflow—from reading configurations to processing sequencing meta-data and communicating with the REST API.
- Configurability: Through the TOML configuration file, the system is flexible and supports parameters such as thread count and API credentials.
- Network Communication: The integration with Digestiflow Web via REST API emphasizes a client-server pattern.

##### Relevant Technologies
- Rust Language: The entire project is written in Rust (using Cargo.toml for package management).
- REST API: Communication with Digestiflow Web is implemented via HTTP calls (implied by the existence of files like api.rs).
- Continuous Integration: The presence of a .travis.yml file indicates integration with Travis CI for automated testing/builds.
- YAML and TOML: CLI configurations are defined in "cli.yaml" and the global configuration in a TOML file.

##### Additional Elements to Consider
- Indicators for configuration parameters (API URL, token, threads) that propagate throughout the system.
- Modular structure of the codebase by showing how the “ingest” functionality is encapsulated within its own module.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Components Subgraph
    subgraph "CLI Components"
        CLI_Main["CLI Interface: parses command-line arguments"]:::internal
        CLI_Config["CLI Configuration: cli.yaml"]:::internal
    end
    CLI_Config -->|"configures"| CLI_Main

    %% Internal Components
    CLI_Main -->|"reads_config"| Config["Configuration Loader: loads ~/.digestiflowrc.toml"]:::internal
    Config -->|"provides_settings"| Ingest["Ingestion Module: reads sequencing meta-data (multi-threaded)"]:::internal
    Ingest -->|"if_flag_enabled"| Adapter["Adapter Analysis: computes index histograms"]:::auxiliary
    Ingest -->|"prepares_API_calls"| APIClient["REST API Client: interacts with Digestiflow API"]:::internal

    %% External Component
    APIClient -->|"HTTP_request"| External["Digestiflow Web API"]:::external
    External -->|"API_response"| APIClient

    %% Click Events
    click CLI_Main "https://github.com/bihealth/digestiflow-cli/blob/master/src/main.rs"
    click CLI_Config "https://github.com/bihealth/digestiflow-cli/blob/master/src/cli.yaml"
    click Config "https://github.com/bihealth/digestiflow-cli/blob/master/src/settings.rs"
    click Ingest "https://github.com/bihealth/digestiflow-cli/tree/master/src/ingest"
    click APIClient "https://github.com/bihealth/digestiflow-cli/blob/master/src/ingest/api.rs"

    %% Styles
    classDef internal fill:#bbf,stroke:#333,stroke-width:2px;
    classDef external fill:#fbb,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#bfb,stroke:#333,stroke-width:2px;
```
