# citadel-ai/langcheck architecture

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

- Interactive diagram: https://gitdiagram.com/citadel-ai/langcheck
- Repository: https://github.com/citadel-ai/langcheck

## Overview

This project is an open‐source Python library called LangCheck that provides a suite of evaluation metrics, data augmentation, and visualization tools specifically designed for assessing LLM (large language model) outputs. It’s built in a modular fashion so that users can easily plug in various types of language metrics (reference-free, reference-based, source-based, query-based, text structure, and pairwise comparisons) as well as leverage data augmentations and interactive plots.

##### Main Components
- Core Library (src/langcheck): Represent the core business logic. This includes several submodules:
- Augment Module: Handles text transformations such as rephrasing, gender shifts, keyboard typos, punctuation removal, etc. Note the language-specific subdirectories (e.g., “src/langcheck/augment/en” and “src/langcheck/augment/ja”), which indicate modular support for multiple languages.
- Metrics Module: Contains various evaluation strategies and quality metrics. There are multiple language-specific folders (e.g., “en”, “de”, “ja”, “zh”) and different metric types (e.g., reference-based, reference-free, query-based, source-based, pairwise). Also include the “model_manager” submodule for handling language model configurations and loaders.
- Plotting Module: Provides interactive visualization tools for displaying metric distributions – illustrated by “src/langcheck/plot” (scatter plots, histograms, etc.).
- Utilities: Includes helper functions like logging (“_handle_logs.py”), I/O operations, and progress bars (“src/langcheck/utils”).
- Metrics Scorer and Prompts: Show that there is a component (within “src/langcheck/metrics/prompts”) for templating and dynamically generating evaluation prompts, including jailbreak templates.

- External Interfaces:
- Augmented Data Flow: Display how the augmentation module affects input data prior to metric evaluation.

- CI/CD and Configuration:
- CI/CD Pipelines: Represent GitHub Actions workflows (depicted in the “.github/workflows” folder) that handle formatting, installation, and testing (pytest) to emphasize continuous integration.
- Development Environment: Note the existence of configuration files like “pyproject.toml”, Docker’s devcontainer files, and the VSCode settings, all ensuring a consistent development and deployment environment.

- Testing and Documentation:
- Testing Module: Group the “tests” directory to show unit tests for various components (augmentations, different metric types, model management, etc.). This reinforces the project’s commitment to robust evaluation.
- Documentation: Include a block for documentation (“docs”), which details installation, quickstarts, and tutorials. This is essential for understanding the usage and integration of the system.

##### Relationships and Data Flow
- Follow the flow from metrics results to the Plotting module for visualization.
- That the Testing suite runs alongside these modules and that CI/CD pipelines automatically execute tests and formatting routines.

##### Architectural Patterns and Design Principles
- Modularity: Emphasize the separation into clear submodules (metrics, augmentation, plotting, utils) which follow a clear single-responsibility design.
- Language-specific Extensibility: Note how there’s a pattern of language-specific folders that allow for extensions (e.g., “en”, “ja”, “de”, “zh”), which can be visually grouped.
- Reusability: The project is designed as a Python package, so separate concerns such as data transformation, metric computation, and visualization are independently callable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interface
    ULLM["User/LLM Application"]:::external

    %% Core Library Subgraph
    subgraph "Core Library (src/langcheck)"
        AUG["Augment Module"]:::core
        AUG_EN["Augment (en)"]:::core
        AUG_JA["Augment (ja)"]:::core

        MET["Metrics Module"]:::core
        MET_EN["Metrics (en)"]:::core
        MET_DE["Metrics (de)"]:::core
        MET_JA["Metrics (ja)"]:::core
        MET_ZH["Metrics (zh)"]:::core
        MM["Model Manager"]:::core
        PROMPT["Metrics Scorer and Prompts"]:::core

        PLOT["Plotting Module"]:::core
        UTILS["Utilities"]:::core
    end

    %% Supporting Infrastructure
    CI["CI/CD Pipelines (.github/workflows)"]:::infra
    DEV["Development Environment & Config (.devcontainer,pyproject.toml,.vscode)"]:::infra
    TEST["Testing (tests)"]:::testing
    DOC["Documentation (docs)"]:::doc

    %% Internal Connections in Core Library
    ULLM -->|"input"| AUG
    AUG -->|"augments"| MET
    MET -->|"evaluates"| PLOT
    MET -->|"logs_to"| UTILS
    PLOT -->|"visual_output"| ULLM

    %% Augment Module language-specific nodes
    AUG -->|"submodule"| AUG_EN
    AUG -->|"submodule"| AUG_JA

    %% Metrics Module language-specific nodes
    MET -->|"submodule"| MET_EN
    MET -->|"submodule"| MET_DE
    MET -->|"submodule"| MET_JA
    MET -->|"submodule"| MET_ZH
    MET -->|"managed_by"| MM
    MET -->|"uses"| PROMPT

    %% Supporting Infrastructure Connections
    DEV -->|"configures"| AUG
    TEST ---|"tests"| AUG
    TEST ---|"tests"| MET
    TEST ---|"tests"| PLOT
    CI -->|"automates"| TEST
    ULLM -->|"references"| DOC

    %% Classes
    classDef core fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef external fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef infra fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef testing fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
    classDef doc fill:#d7ccc8,stroke:#5d4037,stroke-width:2px;

    %% Click Events for Core Library Components
    click AUG "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/augment"
    click AUG_EN "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/augment/en"
    click AUG_JA "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/augment/ja"
    click MET "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics"
    click MET_EN "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics/en"
    click MET_DE "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics/de"
    click MET_JA "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics/ja"
    click MET_ZH "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics/zh"
    click MM "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics/model_manager"
    click PROMPT "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/metrics/prompts"
    click PLOT "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/plot"
    click UTILS "https://github.com/citadel-ai/langcheck/tree/main/src/langcheck/utils"

    %% Click Events for Supporting Infrastructure
    click CI "https://github.com/citadel-ai/langcheck/tree/main/.github/workflows"
    click DEV "https://github.com/citadel-ai/langcheck/blob/main/.devcontainer"
    click TEST "https://github.com/citadel-ai/langcheck/tree/main/tests"
    click DOC "https://github.com/citadel-ai/langcheck/tree/main/docs"
```
