# biagent-dev/bia architecture

> Architecture diagram of the GitHub repository biagent-dev/bia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/biagent-dev/bia
- Repository: https://github.com/biagent-dev/bia

## Overview

##### Main Components
- CLI Entry Point: Represented by the file “biagent/entry_point.py” which is responsible for parsing user commands and dispatching tasks.
- Configurations: Include the “biagent/configs” module (e.g., metadata configuration) that provides runtime settings.
- Prompts & Templates: The “biagent/prompts” directory contains Jinja templates (metadata.jinja, mtx_reader.jinja, pipeline_extractor.jinja, etc.) used to generate instructions for LLMs.
- Tools: In “biagent/tools”, you have modules like geo_search.py, count_matrix_reader.py, metadata.py, and pipeline_extractor.py. These implement the core bioinformatics functionalities.
- Data Types & Models: “biagent/types” houses type definitions and Pydantic models which are central to data validation and structured data handling.
- Utilities: “biagent/utils” covers supporting functions such as code execution (code_runner), logging (logger), LLM interaction wrappers (llm_helpers), metadata and pipeline helpers, and other parsing logic.
- Data Resources: The “data” folder (e.g., sc_rna_seq_pipeline.json) may serve as a static resource providing pipeline configurations or sample workflows.
- External Dependencies: Mention the integration with external systems via environment variables (e.g., DASHSCOPE_API_KEY, OPENAI_API_KEY, OPENAI_API_BASE). These are critical for the LLM and API integrations.

##### Relationships and Interactions
- The CLI entry point receives commands and dispatches them to the respective “tools” (e.g., geo_search for sample queries, metadata extraction, count matrix reading, and pipeline extraction).
- Each “tool” component uses its corresponding prompt templates (from the “prompts” folder) to generate queries/instructions that are sent to the LLM services via the utilities (llm_helpers).
- Configuration settings from “configs” are loaded early in the process and are used by tools/utilities to ensure the correct meta settings and behaviors.
- Pydantic models and type aliases (from “types”) are employed throughout the system to ensure data integrity and validate inputs/outputs.
- Utility modules such as logging, output parsing, and helper functions support smooth data flow and error handling.

##### Architectural Patterns and Design Principles
- Modular Design: Notice how the project is split into clear functional modules (entry point, tools, prompts, types, utils) that encourage separation of concerns.
- Template-Driven LLM Communication: Use the prompts (Jinja templates) to dynamically format queries to LLMs.
- CLI-Based Workflow: All activities are initiated from a central command interface, which then channels operations to dedicated tools.
- Dependency Injection/Configuration Management: The configuration module (“configs”) ensures that environment-specific settings are managed systematically.
- Extensibility: The clear separation between prompt definitions and tool implementations allows for future expansion (e.g., adding frontend/backend as indicated in the roadmap).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Modules
    subgraph "Core Modules"
        CLI["CLI Entry Point"]:::core
        CONFIG["Configurations"]:::core
        PROMPTS["Prompts & Templates"]:::core
        subgraph "Tools"
            GT["Geo Search"]:::tool
            METADATA["Metadata Extraction"]:::tool
            CM["Count Matrix Reader"]:::tool
            PIPELINE["Pipeline Extraction"]:::tool
        end
        TYPES["Data Types & Models"]:::data
        UTILS["Utilities"]:::util
    end

    %% Data Resources and External Services
    DATA["Data Resources"]:::data
    subgraph "External Services"
        OPENAI["OpenAI API"]:::external
        DASH["dashscope API"]:::external
    end

    %% Future Enhancements (Planned)
    subgraph "Future Enhancements"
        FE["Frontend & Backend Modules (Planned)"]:::future
    end

    %% Flow Connections
    CLI -->|"dispatch command"| GT
    CLI -->|"dispatch command"| METADATA
    CLI -->|"dispatch command"| CM
    CLI -->|"dispatch command"| PIPELINE

    CONFIG -->|"provides runtime settings"| GT
    CONFIG -->|"provides runtime settings"| METADATA
    CONFIG -->|"provides runtime settings"| CM
    CONFIG -->|"provides runtime settings"| PIPELINE

    GT -->|"uses prompt"| PROMPTS
    METADATA -->|"uses prompt"| PROMPTS
    CM -->|"uses prompt"| PROMPTS
    PIPELINE -->|"uses prompt"| PROMPTS

    GT -->|"validates data"| TYPES
    METADATA -->|"validates data"| TYPES
    CM -->|"validates data"| TYPES
    PIPELINE -->|"validates data"| TYPES

    GT -->|"LLM+logging"| UTILS
    METADATA -->|"LLM+logging"| UTILS
    CM -->|"LLM+logging"| UTILS
    PIPELINE -->|"LLM+logging"| UTILS

    UTILS -->|"external APICall"| OPENAI
    UTILS -->|"external APICall"| DASH

    PIPELINE -->|"reads config"| DATA

    %% Future Enhancements Connection (planned extension)
    CLI ---|"planned extension"| FE

    %% Click Events
    click CLI "https://github.com/biagent-dev/bia/blob/main/biagent/entry_point.py"
    click CONFIG "https://github.com/biagent-dev/bia/blob/main/biagent/configs/metadata.py"
    click PROMPTS "https://github.com/biagent-dev/bia/tree/main/biagent/prompts/"
    click GT "https://github.com/biagent-dev/bia/blob/main/biagent/tools/geo_search.py"
    click METADATA "https://github.com/biagent-dev/bia/blob/main/biagent/tools/metadata.py"
    click CM "https://github.com/biagent-dev/bia/blob/main/biagent/tools/count_matrix_reader.py"
    click PIPELINE "https://github.com/biagent-dev/bia/blob/main/biagent/tools/pipeline_extractor.py"
    click TYPES "https://github.com/biagent-dev/bia/tree/main/biagent/types/"
    click UTILS "https://github.com/biagent-dev/bia/tree/main/biagent/utils/"
    click DATA "https://github.com/biagent-dev/bia/tree/main/data/"

    %% Styles
    classDef core fill:#DDEFFF,stroke:#5577AA,stroke-width:2px;
    classDef tool fill:#FFDDAA,stroke:#CC8844,stroke-width:2px;
    classDef data fill:#DDFFDD,stroke:#559955,stroke-width:2px;
    classDef util fill:#FFEEDD,stroke:#CCBB77,stroke-width:2px;
    classDef external fill:#FFCCCC,stroke:#AA4444,stroke-width:2px;
    classDef future fill:#EEEEEE,stroke:#888888,stroke-dasharray: 5 5,stroke-width:2px;
```
