# athina-ai/athina-evals architecture

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

- Interactive diagram: https://gitdiagram.com/athina-ai/athina-evals
- Repository: https://github.com/athina-ai/athina-evals

## Overview

##### Main Components
- API/CLI Interface: Represented by the athina/cli module. This component exposes command‐line commands to interact with the SDK.
- Evaluation Engine: Multiple “evals” submodules (athina/evals) contain dedicated evaluators for different evaluation types (conversation, function, grounded, ragas, guardrails, safety, LLM, etc.). These modules form the core that defines how AI outputs are measured.
- Data & Dataset Management: The athina/datasets module holds sample datasets and loaders, which along with athina/loaders are used to ingest and structure input data.
- Interaction with External Services: The athina/interfaces directory shows adapters for external systems – for example, for accessing OpenAI’s API (athina/interfaces/openai), custom model configs, and result output. Similarly, the athina/llms module abstracts interactions with various LLM services using specific implementations (e.g., openai_service, litellm_service).
- Helper Utilities: The athina/helpers package consolidates common utilities like logging, configuration management, JSON handling, and loader support.
- Service and Runner: Components under athina/runner and athina/services run the entire evaluation workflow, orchestrating the flow from data ingestion to evaluation execution.
- Error and Exception Handling: Modules like athina/errors and athina/guard ensure that exceptions and guardrails are in place during execution.
- Experiment Steps: Components under athina/steps represent distinct steps (e.g., conditional flows, code execution, retrieval methods) in an evaluation pipeline.
- Continuous Integration and Deployment: The existence of .github/workflows, pre-commit hooks, and the pyproject.toml configuration indicate automated tests, linting, and publishing pipelines, which are depicted as external support processes.

##### Relationships and Interactions
- The CLI layer interacts with the Evaluation Engine, initiating processes that run various evaluators.
- Data flows from the Data/Dataset Management component through different Loaders to become inputs for Evaluators.
- The Interfaces and LLMS modules serve as adapters, bridging calls from the evaluation routines to external AI service APIs (such as OpenAI) or customized evaluation logic.
- Helper modules provide cross-cutting services (like logging and configuration) to all major components.
- The Service and Runner layer orchestrate the overall evaluation process by invoking Steps in a defined sequence.
- Error handling and guard services ensure that any exceptions or out-of-bound evaluation results are caught and managed appropriately.
- Integration with external systems (especially Athina IDE) is hinted by the README, positioning the SDK as part of a larger ecosystem.

##### Architectural Patterns and Principles
- Modular/Layered Design: Each major aspect (CLI, datasets, evaluations, interfaces, steps) is separated into its own module, promoting high cohesion and loose coupling.
- Plugin/Extension Mechanisms: With preset evals and support for custom evals, the architecture encourages extensibility.
- Pipeline/Orchestration: The steps and runner components imply a pipeline-based approach where input data goes through multiple evaluation steps.
- Error Management and Guardrails: Dedicated guard modules show a design emphasis on safety and controlled execution.

##### Relevant Technologies and Frameworks
- Primary Language: The entire codebase is in Python.
- CI/CD Tools: GitHub Actions for linting, testing, and publishing.
- Package Management: pyproject.toml and pre-commit configurations ensure code quality and standardized builds.
- External API Integrations: OpenAI and potentially other LLM services are integrated via dedicated interfaces.

- To illustrate sequence flows (e.g., dataset → loader → evaluator).
- To indicate dependency relationships (e.g., evaluation modules depending on helper utilities).
- A separate style for the internal pipeline (steps, runner, services).
- Additional processes (like CI/CD), possibly at the periphery of the main architecture, to show supporting workflows.

- That every module in the athina package is represented at least as a major functional block if not in full detail.
- External interactions like the integration with the Athina IDE (as depicted in the README images) which serves as the platform for running and visualizing experiments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    subgraph "Core Modules"
        cli["CLI Interface"]:::cli
        runner["Runner Orchestrator"]:::runner
        api_service["API Service"]:::runner
    end

    %% Data & Dataset Management
    subgraph "Data & Dataset Management"
        dataset["Dataset Module"]:::data
        loaders["Data Loaders"]:::data
    end

    %% Evaluation Engine
    subgraph "Evaluation Engine"
        conv["Conversation Evals"]:::evaluation
        func["Function Evals"]:::evaluation
        grounded["Grounded Evals"]:::evaluation
        guardrails["Guardrails Evals"]:::evaluation
        llm["LLM Evals"]:::evaluation
        ragas["Ragas Evals"]:::evaluation
        safety["Safety Evals"]:::evaluation
    end

    %% External Services
    subgraph "External Services"
        openai["OpenAI Interface"]:::external
        llmSrv["LLM Service Adapters"]:::external
    end

    %% Helper Utilities
    subgraph "Helper Utilities"
        logging["Logging Helper"]:::helper
        config["Config Helper"]:::helper
    end

    %% Error and Exception Handling
    subgraph "Error Handling"
        exception["Exception Handler"]:::error
        guard["Guard System"]:::error
    end

    %% Experiment Pipeline
    subgraph "Experiment Pipeline"
        steps["Experiment Steps"]:::steps
        ide["Athina IDE Integration"]:::external
    end

    %% CI/CD Processes
    ci["CI/CD Pipeline"]:::ci

    %% Connections
    cli -->|"triggers"| runner
    cli -->|"invokes"| api_service

    dataset -->|"provides data"| loaders
    loaders -->|"feeds data"| conv
    dataset -->|"supplies"| conv

    runner -->|"orchestrates"| conv
    runner -->|"orchestrates"| func
    runner -->|"orchestrates"| grounded
    runner -->|"orchestrates"| guardrails
    runner -->|"orchestrates"| llm
    runner -->|"orchestrates"| ragas
    runner -->|"orchestrates"| safety

    %% Evaluation Engine uses External Services
    conv -->|"calls"| openai
    conv -->|"calls"| llmSrv
    func -->|"calls"| openai
    func -->|"calls"| llmSrv
    grounded -->|"calls"| openai
    grounded -->|"calls"| llmSrv
    guardrails -->|"calls"| openai
    guardrails -->|"calls"| llmSrv
    llm -->|"calls"| openai
    llm -->|"calls"| llmSrv
    ragas -->|"calls"| openai
    ragas -->|"calls"| llmSrv
    safety -->|"calls"| openai
    safety -->|"calls"| llmSrv

    %% Runner flows into Experiment Steps and external integration
    runner -->|"executes"| steps
    steps -->|"reports to"| ide

    %% Error handling integration with Evaluation Engine modules
    conv -->|"monitored by"| exception
    func -->|"monitored by"| exception
    grounded -->|"monitored by"| exception
    guardrails -->|"monitored by"| guard
    llm -->|"monitored by"| guard
    ragas -->|"monitored by"| guard
    safety -->|"monitored by"| guard

    %% CI/CD integration
    ci -->|"validates"| cli
    ci -->|"validates"| runner

    %% Helper Utilities support
    logging ---|"supports"| cli
    logging ---|"supports"| runner
    config ---|"supports"| conv
    config ---|"supports"| steps
    config ---|"supports"| api_service

    %% Styles
    classDef cli fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef runner fill:#fad7a0,stroke:#d35400,stroke-width:2px;
    classDef data fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef evaluation fill:#aed6f1,stroke:#2e86c1,stroke-width:2px;
    classDef external fill:#f5cba7,stroke:#a04000,stroke-width:2px;
    classDef helper fill:#d6eaf8,stroke:#2471a3,stroke-width:2px;
    classDef error fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef steps fill:#abebc6,stroke:#229954,stroke-width:2px;
    classDef ci fill:#e8daef,stroke:#8e44ad,stroke-width:2px;

    %% Click Events
    click cli "https://github.com/athina-ai/athina-evals/blob/main/athina/cli/cli.py"
    click conv "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/conversation"
    click func "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/function"
    click grounded "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/grounded"
    click guardrails "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/guardrails"
    click llm "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/llm"
    click ragas "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/ragas"
    click safety "https://github.com/athina-ai/athina-evals/tree/main/athina/evals/safety"
    click dataset "https://github.com/athina-ai/athina-evals/blob/main/athina/datasets/dataset.py"
    click loaders "https://github.com/athina-ai/athina-evals/blob/main/athina/loaders/base_loader.py"
    click openai "https://github.com/athina-ai/athina-evals/blob/main/athina/interfaces/openai.py"
    click llmSrv "https://github.com/athina-ai/athina-evals/blob/main/athina/llms/openai_service.py"
    click logging "https://github.com/athina-ai/athina-evals/blob/main/athina/helpers/athina_logging_helper.py"
    click config "https://github.com/athina-ai/athina-evals/blob/main/athina/helpers/config.py"
    click runner "https://github.com/athina-ai/athina-evals/blob/main/athina/runner/run.py"
    click api_service "https://github.com/athina-ai/athina-evals/blob/main/athina/services/athina_api_service.py"
    click exception "https://github.com/athina-ai/athina-evals/blob/main/athina/errors/exceptions.py"
    click guard "https://github.com/athina-ai/athina-evals/blob/main/athina/guard/guard.py"
    click steps "https://github.com/athina-ai/athina-evals/tree/main/athina/steps"
```
