# besser-pearl/databot architecture

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

- Interactive diagram: https://gitdiagram.com/besser-pearl/databot
- Repository: https://github.com/besser-pearl/databot

## Overview

##### Main Components

a) Frontend Layer:
- Streamlit UI components (found in src/ui/)
- Key components: playground, admin, settings, sidebar, bot container
- User interaction points (chat and voice interfaces)

b) Core Application Layer:
- Bot Framework Integration
- Data Processing Components
- Schema Management

c) Bot Engine Layer:
- Workflow Management
- Query Processing
- Chart Generation
- Table Generation

d) External Services:
- OpenAI API Integration
- Speech-to-Text Service
- Open Data Portal API Connection

**[User Interface Layer]**
- ↑↓
**[Application Layer]**
- ↑↓
**[Service Layer]**

##### Component Relationships

- User → UI Layer (chat/voice input)
- UI Layer → Bot Engine (intent recognition)
- Bot Engine → Query Processors (data retrieval)
- Query Processors → Chart/Table Generators
- Application Layer ↔ External Services

##### Specific Implementation Details

a) Bot Framework Components:
- Intent Recognition (src/app/bot/library/databot_intents.py)
- Entity Extraction (src/app/bot/library/databot_entities.py)
- Workflow Management (src/app/bot/workflows/)

b) Query Types:
- Chart Generators (src/app/bot/workflows/queries/charts/)
- Table Generators (src/app/bot/workflows/queries/tables/)

c) Schema Management:
- Data Schema (src/schema/data_schema.py)
- Field Schema (src/schema/field_schema.py)
- Category Management (src/schema/category.py)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph User["User Interface"]
        UI_Input["User Input"]
        UI_Output["Response Output"]
    end

    subgraph Frontend["Frontend Layer"]
        BC["Bot Container"]:::ui
        AD["Admin Interface"]:::ui
        ST["Settings Panel"]:::ui
        SB["Sidebar"]:::ui
        PG["Playground"]:::ui
    end

    subgraph Core["Core Application Layer"]
        APP["Main Application"]:::core
        PM["Project Management"]:::core
        S2T["Speech-to-Text Service"]:::core
        SM["Session Monitoring"]:::core
    end

    subgraph BotEngine["Bot Engine Layer"]
        ML["Main Bot Logic"]:::bot
        IR["Intent Recognition"]:::bot
        EE["Entity Extraction"]:::bot
        WM["Workflow Management"]:::bot
        LLM["LLM Integration"]:::bot
    end

    subgraph QueryProcessing["Query Processing"]
        subgraph Charts["Chart Generators"]
            BC_G["Bar Charts"]:::chart
            LC_G["Line Charts"]:::chart
            PC_G["Pie Charts"]:::chart
            SC_G["Scatter Charts"]:::chart
        end

        subgraph Tables["Table Generators"]
            FD["Field Distincts"]:::table
            VF["Value Frequency"]:::table
            CS["Conditional Selections"]:::table
        end
    end

    subgraph Schema["Schema Management"]
        DS["Data Schema"]:::schema
        FS["Field Schema"]:::schema
        CM["Category Management"]:::schema
        FT["Field Type Definitions"]:::schema
        FM["Filter Management"]:::schema
        SE["Schema Enhancement"]:::schema
    end

    subgraph External["External Services"]
        OAI["OpenAI API"]:::external
        ODP["Open Data Portal"]:::external
    end

    %% Relationships
    UI_Input --> BC
    BC --> ML
    ML --> IR
    IR --> EE
    EE --> WM
    WM --> LLM
    LLM --> Charts
    LLM --> Tables
    Charts --> UI_Output
    Tables --> UI_Output
    WM --> Schema
    APP --> PM
    PM --> Schema
    S2T --> UI_Input
    ML --> OAI
    Schema --> ODP

    %% Click Events
    click BC "https://github.com/BESSER-PEARL/databot/blob/main/src/ui/bot_container.py"
    click AD "https://github.com/BESSER-PEARL/databot/blob/main/src/ui/admin.py"
    click ST "https://github.com/BESSER-PEARL/databot/blob/main/src/ui/settings.py"
    click SB "https://github.com/BESSER-PEARL/databot/blob/main/src/ui/sidebar.py"
    click PG "https://github.com/BESSER-PEARL/databot/blob/main/src/ui/playground.py"
    click ML "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/databot.py"
    click IR "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/library/databot_intents.py"
    click EE "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/library/databot_entities.py"
    click WM "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/abstract_query_workflow.py"
    click LLM "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/llm_query.py"
    click BC_G "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/charts/bar_chart.py"
    click LC_G "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/charts/line_chart.py"
    click PC_G "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/charts/pie_chart.py"
    click SC_G "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/charts/scatter_chart.py"
    click FD "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/tables/field_distinct.py"
    click VF "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/tables/value_frequency.py"
    click CS "https://github.com/BESSER-PEARL/databot/blob/main/src/app/bot/workflows/queries/tables/select_fields_with_conditions.py"
    click DS "https://github.com/BESSER-PEARL/databot/blob/main/src/schema/data_schema.py"
    click FS "https://github.com/BESSER-PEARL/databot/blob/main/src/schema/field_schema.py"
    click CM "https://github.com/BESSER-PEARL/databot/blob/main/src/schema/category.py"
    click FT "https://github.com/BESSER-PEARL/databot/blob/main/src/schema/field_type.py"
    click FM "https://github.com/BESSER-PEARL/databot/blob/main/src/schema/filter.py"
    click S2T "https://github.com/BESSER-PEARL/databot/blob/main/src/app/speech2text.py"
    click SE "https://github.com/BESSER-PEARL/databot/blob/main/src/utils/data_schema_enhancement.py"
    click SM "https://github.com/BESSER-PEARL/databot/blob/main/src/utils/session_monitoring.py"
    click APP "https://github.com/BESSER-PEARL/databot/blob/main/src/app/app.py"
    click PM "https://github.com/BESSER-PEARL/databot/blob/main/src/app/project.py"

    %% Styles
    classDef ui fill:#2374AB
    classDef core fill:#48A9A6
    classDef bot fill:#4B644A
    classDef chart fill:#E4B363
    classDef table fill:#E4C963
    classDef schema fill:#C1666B
    classDef external fill:#9B4F96
```
