# pigpig1524/chat_your_data architecture

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

- Interactive diagram: https://gitdiagram.com/pigpig1524/chat_your_data
- Repository: https://github.com/pigpig1524/chat_your_data

## Overview

##### Project Type and Purpose
- The project is a Streamlit application that runs as a local web app (with “streamlit run app.py”).
- Its purpose is to offer several interactive pages (e.g., chatbot, data, guide) that leverage backend utility functions for core functionalities.
- The README instructions focus on setting up the environment and include directions on installing required libraries and secret keys, suggesting integration with external configuration (via secrets in .streamlit).

##### File Structure – Identifying Main Components
a. Entry Point:
- app.py: This file is the main entry point likely responsible for initializing the Streamlit app, handling routing, and dispatching to different pages.
b. Configuration:
- config.py: Contains configuration details.
- External secrets configuration stored in a .streamlit folder (mentioned in README).
c. Page Components:
- The pages folder contains individual Python files (chatbot.py, data.py, guide.py) which probably represent different interactive pages or features.
d. Utility Modules:
- The utils folder holds various modules (agent.py, chunking.py, indexing.py, init_state.py) that encapsulate business or core application logic.
e. Additional Helper/Test Scripts:
- Files such as try.py, try_2.py may serve for testing or experimental purposes.

##### High-Level Architectural Patterns & Relationships
- There is a clear separation between the UI (Streamlit pages) and the logic/business layer (utils modules).
- This modular division resembles a simplistic MVC (Model-View-Controller) pattern:
- The “View” is provided by the Streamlit interface (app.py & pages/*).
- The “Controller” might be partly in app.py by routing between pages and managing user interactions.
- The “Model/Service” logic is encapsulated in the utils modules.
- Configurations and external keys act as settings that feed into the system’s behavior.

- Branch out to a "Pages" container that includes:
- Chatbot Page (pages/chatbot.py)
- Data Page (pages/data.py)
- Guide Page (pages/guide.py)
- Agent Functions (utils/agent.py)
- Chunking (utils/chunking.py)
- Indexing (utils/indexing.py)
- Initial State Management (utils/init_state.py)
- A configuration block (config.py) that feeds into the app and maybe also directly into utility modules.
- Dependency on external secrets, stored in the .streamlit folder as per the README.
- Utility scripts as supporting services that handle computations, state, and data processing for the interactive components.
- You could optionally mark the try.py and try_2.py as “Test/Experimental Scripts” if needed for clarity, but the focus should be on the core functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration"
        C2[".streamlit (Secrets)"]:::config
        C1["config.py"]:::config
        C2 -->|"provides"| C1
    end

    %% Streamlit UI Layer
    subgraph "Streamlit UI Layer"
        A1["app.py (Streamlit Entry Point)"]:::ui
        subgraph "Pages"
            P1["pages/chatbot.py"]:::ui
            P2["pages/data.py"]:::ui
            P3["pages/guide.py"]:::ui
        end
    end

    %% Business Logic / Utilities Layer
    subgraph "Business Logic / Utilities"
        U1["utils/agent.py"]:::util
        U2["utils/chunking.py"]:::util
        U3["utils/indexing.py"]:::util
        U4["utils/init_state.py"]:::util
    end

    %% Connections from Configuration
    C1 -->|"configures"| A1
    C1 -->|"configures"| U1
    C1 -->|"configures"| U2
    C1 -->|"configures"| U3
    C1 -->|"configures"| U4

    %% Connections from Entry Point to Pages
    A1 -->|"routes"| P1
    A1 -->|"routes"| P2
    A1 -->|"routes"| P3

    %% Connections from Pages to Utility Modules
    P1 -->|"calls"| U1
    P1 -->|"calls"| U2
    P1 -->|"calls"| U3
    P1 -->|"calls"| U4

    P2 -->|"calls"| U1
    P2 -->|"calls"| U2
    P2 -->|"calls"| U3
    P2 -->|"calls"| U4

    P3 -->|"calls"| U1
    P3 -->|"calls"| U2
    P3 -->|"calls"| U3
    P3 -->|"calls"| U4

    %% Click Events
    click A1 "https://github.com/pigpig1524/chat_your_data/blob/main/app.py"
    click C1 "https://github.com/pigpig1524/chat_your_data/blob/main/config.py"
    click C2 "https://github.com/pigpig1524/chat_your_data/blob/main/.streamlit"
    click P1 "https://github.com/pigpig1524/chat_your_data/blob/main/pages/chatbot.py"
    click P2 "https://github.com/pigpig1524/chat_your_data/blob/main/pages/data.py"
    click P3 "https://github.com/pigpig1524/chat_your_data/blob/main/pages/guide.py"
    click U1 "https://github.com/pigpig1524/chat_your_data/blob/main/utils/agent.py"
    click U2 "https://github.com/pigpig1524/chat_your_data/blob/main/utils/chunking.py"
    click U3 "https://github.com/pigpig1524/chat_your_data/blob/main/utils/indexing.py"
    click U4 "https://github.com/pigpig1524/chat_your_data/blob/main/utils/init_state.py"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef config fill:#ffe5cc,stroke:#e69500,stroke-width:2px;
    classDef util fill:#d4edda,stroke:#155724,stroke-width:2px;
```
