# microsoft/lida architecture

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

- Interactive diagram: https://gitdiagram.com/microsoft/lida
- Repository: https://github.com/microsoft/lida

## Overview

##### Project Type & Purpose
- LIDA is a Python library that automatically generates data visualizations and infographics by leveraging large language models (LLMs).
- It is designed as a modular, extensible tool that supports multiple visualization tasks (generation, editing, explanation, evaluation, repair, and recommendation) and also provides a bundled web API and UI.
- The README emphasizes two primary use cases: direct Python API usage (i.e., in your own app or via a CLI) and an optional web interface (with a Docker-supported deployment).

##### Main Components Identification
- Core Library:
- The "lida" package is the heart of the project.
- Within it, the "components" folder contains several modules (executor, goal, infographer, manager, persona, scaffold, summarizer) that encapsulate distinct functionalities.
- The "datamodel.py" and "utils.py" files support infrastructure and helper functions.
- The "version.py" adds version management to the library.
- Visualization Subsystem:
- The "components/viz" folder further splits visualization functionalities into dedicated modules: viz editor, evaluator, explainer, generator, recommender, and repairer.
- CLI Interface:
- The "lida/cli.py" file acts as the entry point for command-line operations.
- Web API and UI:
- The "lida/web" directory contains a separate subpackage with "app.py" (likely the web server logic) and UI assets (HTML files, JavaScript bundles, CSS, and associated resources).
- Configuration and Deployment:
- Files such as "docker-compose.yml", "dockerfile", and standard python files (pyproject.toml, requirements.txt) aid in deployment and environment configuration.
- Supporting Resources:
- Notebooks (for tutorials/demos), docs, tests, and even Docker and Git-related files help with documentation, testing, and deployment.

##### Relationships & Interactions
- The central orchestrator is the Manager (implemented in components/manager.py) that leverages the specialized components (e.g., summarizer, goal generation, viz generation/editing/explanation) based on inputs (data, goals, instructions).
- The CLI tool (cli.py) and the web API (web/app.py) are front ends that expose functionalities of the core library.
- External Dependencies:
- The project relies on external language model providers (OpenAI, HuggingFace, etc.) via the "llmx" library.
- Docker and docker-compose provide a containerization strategy for the web UI and API.

##### Architectural Patterns & Design Principles
- Modular Design – Each functionality (like summarizing data or editing visualizations) is encapsulated in its own module, promoting separation of concerns.
- Service-Oriented/Layered Architecture – The application is divided into layers: core business logic (components), presentation (web UI/CLI), and infrastructure/configuration (deployment scripts, Docker).
- Extensibility – The use of a Manager that aggregates functionalities allows for plugging in additional components or alternative LLM configurations easily.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% LIDA Core Library
    subgraph "LIDA Core Library"
        Manager["Manager"]:::core
        Summarizer["Data Summarization Module"]:::core
        GoalGen["Goal Generation Module"]:::core
        Infographics["Infographics Module"]:::core
        Executor["Executor Module"]:::core
        Persona["Persona Module"]:::core
        Scaffold["Scaffold Module"]:::core
        DataUtil["Utility & Data Model"]:::core
        Version["Version Management"]:::core

        %% Visualization Subsystem as a nested subgraph
        subgraph "Visualization Subsystem"
            VizEditor["Visualization Editor"]:::viz
            VizEvaluator["Visualization Evaluator"]:::viz
            VizExplainer["Visualization Explainer"]:::viz
            VizGenerator["Visualization Generator"]:::viz
            VizRecommender["Visualization Recommender"]:::viz
            VizRepairer["Visualization Repairer"]:::viz
        end
    end

    %% Presentation Layer: CLI and Web Interface
    subgraph "Presentation Layer"
        CLI["CLI Interface"]:::cli
        WebAPI["Web API Server"]:::web
        WebUI["Web UI and Assets"]:::web
    end

    %% Deployment and External Services
    subgraph "Deployment & External"
        Docker["Docker Deployment Environment"]:::deploy
        LLM["LLM Providers"]:::external
        Config["Deployment & Configuration Files"]:::deploy
    end

    %% Relationships: Presentation Layer drives Manager
    CLI -->|"invokes"| Manager
    WebAPI -->|"invokes"| Manager

    %% Manager orchestrates Core Modules
    Manager -->|"calls"| Summarizer
    Manager -->|"calls"| GoalGen
    Manager -->|"calls"| Infographics
    Manager -->|"calls"| Executor
    Manager -->|"calls"| Persona
    Manager -->|"calls"| Scaffold
    Manager -->|"utilizes"| DataUtil
    Manager -->|"checks"| Version

    %% Manager directs Visualization Operations
    Manager -->|"triggers"| VizEditor
    Manager -->|"triggers"| VizEvaluator
    Manager -->|"triggers"| VizExplainer
    Manager -->|"triggers"| VizGenerator
    Manager -->|"triggers"| VizRecommender
    Manager -->|"triggers"| VizRepairer

    %% External Interaction with LLM Providers
    Manager ---|"integrates_with"| LLM

    %% Deployment Flow
    WebAPI ---|"containerized_by"| Docker
    WebUI ---|"served_by"| Docker
    Config ---|"configures"| Manager
    Config ---|"configures"| WebAPI

    %% Click Events for LIDA Core Library
    click Manager "https://github.com/microsoft/lida/blob/main/lida/components/manager.py"
    click Summarizer "https://github.com/microsoft/lida/blob/main/lida/components/summarizer.py"
    click GoalGen "https://github.com/microsoft/lida/blob/main/lida/components/goal.py"
    click Infographics "https://github.com/microsoft/lida/blob/main/lida/components/infographer.py"
    click Executor "https://github.com/microsoft/lida/blob/main/lida/components/executor.py"
    click Persona "https://github.com/microsoft/lida/blob/main/lida/components/persona.py"
    click Scaffold "https://github.com/microsoft/lida/blob/main/lida/components/scaffold.py"
    click DataUtil "https://github.com/microsoft/lida/blob/main/lida/datamodel.py"
    click Version "https://github.com/microsoft/lida/blob/main/lida/version.py"

    %% Click Events for Visualization Subsystem
    click VizEditor "https://github.com/microsoft/lida/blob/main/lida/components/viz/vizeditor.py"
    click VizEvaluator "https://github.com/microsoft/lida/blob/main/lida/components/viz/vizevaluator.py"
    click VizExplainer "https://github.com/microsoft/lida/blob/main/lida/components/viz/vizexplainer.py"
    click VizGenerator "https://github.com/microsoft/lida/blob/main/lida/components/viz/vizgenerator.py"
    click VizRecommender "https://github.com/microsoft/lida/blob/main/lida/components/viz/vizrecommender.py"
    click VizRepairer "https://github.com/microsoft/lida/blob/main/lida/components/viz/vizrepairer.py"

    %% Click Events for Presentation Layer
    click CLI "https://github.com/microsoft/lida/blob/main/lida/cli.py"
    click WebAPI "https://github.com/microsoft/lida/blob/main/lida/web/app.py"
    click WebUI "https://github.com/microsoft/lida/tree/main/lida/web/ui/"

    %% Click Events for Deployment & Configuration
    click Config "https://github.com/microsoft/lida/blob/main/docker-compose.yml"
    click Config "https://github.com/microsoft/lida/tree/main/dockerfile"
    click Config "https://github.com/microsoft/lida/blob/main/pyproject.toml"
    click Config "https://github.com/microsoft/lida/blob/main/requirements.txt"

    %% Styles
    classDef core fill:#C5E1A5,stroke:#33691E,stroke-width:2px;
    classDef viz fill:#FFF59D,stroke:#F9A825,stroke-width:2px;
    classDef cli fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef web fill:#FFCCBC,stroke:#BF360C,stroke-width:2px;
    classDef external fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef deploy fill:#B2DFDB,stroke:#004D40,stroke-width:2px;
```
