# ylanv/datalive architecture

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

- Interactive diagram: https://gitdiagram.com/ylanv/datalive
- Repository: https://github.com/ylanv/datalive

## Overview

##### Project type and purpose
- DataLive.ai is a full-stack, desktop-hosted AI assistant for interactive, multimodal data exploration and visualization.
- It combines a Streamlit frontend with a Python backend that (a) profiles and cleans data locally, (b) generates Python code via OpenAI’s GPT-4o, (c) executes that code in a sandbox, (d) renders visualizations, and (e) interprets plots via a HuggingFace Video-LLaMA2B endpoint.

##### File structure
- Top level:
- main.py (entrypoint)
- pages/… (Streamlit pages: cover.py, data_import.py, data_info.py, main_page.py)
- src/… (modules & tests)
- pyproject.toml, .python-version, .gitignore, uv.lock
- src/model/ contains UI helper functions (ui_utils.py)
- src/openai_caller.py handles prompts and GPT-4o interactions
- src/utils/ contains data-processing modules (analyse.py, cleaning_data.py, data_info_function.py)
- src/tests/ houses unit tests for core functionality
- No persistent database—data lives in memory, loaded from user CSVs.

##### Key insights from README
- Frontend: Streamlit pages for uploading data, viewing statistics, issuing natural‐language queries, and displaying plots.
- Backend layers:
a. Data profiling & cleaning (pandas, NumPy, Scikit-learn)
b. Code generation (OpenAI GPT-4o)
c. Plot analysis (Video-LLaMA2B on HuggingFace)
d. Local code execution sandbox (Seaborn, Matplotlib)
- Private/local execution emphasis: metadata extraction, local sandbox, no external data upload.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        main["main.py"]:::frontend
        cover["cover.py"]:::frontend
        data_import["data_import.py"]:::frontend
        data_info_page["data_info.py"]:::frontend
        main_page["main_page.py"]:::frontend
    end

    subgraph "Service Layer"
        subgraph "Data Profiling & Cleaning Service"
            analyse["analyse.py"]:::service
            cleaning["cleaning_data.py"]:::service
            data_info_func["data_info_function.py"]:::service
        end
        ui_utils["ui_utils.py"]:::service
        code_gen["OpenAI Code Generation Service"]:::service
        sandbox["Local Sandbox Executor"]:::service
        plot_interp["Plot Interpretation Service"]:::service
    end

    subgraph "Data Store"
        dataframe["In-Memory DataFrame & Metadata Store"]:::data
    end

    subgraph "External APIs"
        openai_api["OpenAI GPT-4o API"]:::external
        hf_api["HuggingFace Video-LLaMA2B"]:::external
    end

    subgraph "Testing Layer"
        test_code["test_generated_code.py"]:::test
        test_openai["test_openai.py"]:::test
        test_plot["test_plot.py"]:::test
    end

    %% Data flow
    main -->|upload CSV| dataframe
    main -->|request profiling| analyse
    analyse -->|stats| main
    main -->|choose cleaning| cleaning
    cleaning -->|cleaned data| main
    main -->|request info| data_info_func
    data_info_func -->|info| main

    main -->|use helpers| ui_utils

    main -->|NL query| code_gen
    code_gen -->|HTTP JSON| openai_api
    openai_api -->|code response| code_gen
    code_gen -->|generated code| sandbox
    sandbox -->|plot objects & logs| main

    main -->|display plot| main_page

    main -->|interpret plot| plot_interp
    plot_interp -->|analysis request| hf_api
    hf_api -->|textual insights| plot_interp
    plot_interp -->|insights| main

    %% Testing connections
    test_code --- analyse
    test_code --- cleaning
    test_openai --- code_gen
    test_plot --- sandbox

    %% Click Events
    click main "https://github.com/ylanv/datalive/blob/main/main.py"
    click cover "https://github.com/ylanv/datalive/blob/main/pages/cover.py"
    click data_import "https://github.com/ylanv/datalive/blob/main/pages/data_import.py"
    click data_info_page "https://github.com/ylanv/datalive/blob/main/pages/data_info.py"
    click main_page "https://github.com/ylanv/datalive/blob/main/pages/main_page.py"
    click analyse "https://github.com/ylanv/datalive/blob/main/src/utils/analyse.py"
    click cleaning "https://github.com/ylanv/datalive/blob/main/src/utils/cleaning_data.py"
    click data_info_func "https://github.com/ylanv/datalive/blob/main/src/utils/data_info_function.py"
    click code_gen "https://github.com/ylanv/datalive/blob/main/src/openai_caller.py"
    click ui_utils "https://github.com/ylanv/datalive/blob/main/src/model/ui_utils.py"
    click test_code "https://github.com/ylanv/datalive/blob/main/src/tests/test_generated_code.py"
    click test_openai "https://github.com/ylanv/datalive/blob/main/src/tests/test_openai.py"
    click test_plot "https://github.com/ylanv/datalive/blob/main/src/tests/test_plot.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFD700,stroke:#000,stroke-width:1px
    classDef data fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef test fill:#E6E6FA,stroke:#000,stroke-width:1px
```
