# bahawal32/chat_with_data architecture

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

- Interactive diagram: https://gitdiagram.com/bahawal32/chat_with_data
- Repository: https://github.com/bahawal32/chat_with_data

## Overview

##### Project type and purpose
- This is a full-stack “chat” application that lets users pull voting data from a blockchain smart contract and then ask natural-language questions about that data.
- The backend is a FastAPI service that fetches contract data and proxies queries to the OpenAI API. The frontend is a Streamlit app providing a chat-style UI.

##### File structure
- Top-level scripts only (no directories), each mapping to a logical component:
- api_url.py → defines FastAPI endpoints and request routing
- get_voting_data.py → data-access layer for connecting to the blockchain smart contract
- stream_output.py → Streamlit UI for user interaction
- (other helpers such as configuration or wrapper logic may live in these files)
- README files describe the overall flow and tech stack but no separate build or deployment folders.

##### README for additional insights
- Confirms use of FastAPI, Streamlit, OpenAI API, and a blockchain voting smart contract.
- Workflow: fetch data → set context → user asks questions → call OpenAI → display conversation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        User["User"]:::external
        Streamlit["Streamlit UI\n(stream_output.py)"]:::internal
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        FastAPI["FastAPI Service\n(api_url.py)"]:::internal
        DataAccess["Blockchain Data-Access\n(get_voting_data.py)"]:::internal
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        SmartContract["Voting Smart Contract\n(Blockchain Node)"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OpenAI["OpenAI ChatGPT API"]:::external
    end

    %% Documentation
    README["Project Documentation\n(README.md)"]:::doc

    %% Connections
    User -->|"types question"| Streamlit
    Streamlit -->|"HTTP POST /chat"| FastAPI
    FastAPI -->|"calls fetchVotes()"| DataAccess
    DataAccess -->|"Web3 RPC: getVotes()"| SmartContract
    FastAPI -->|"OpenAI ChatCompletion"| OpenAI
    OpenAI -->|"streamed response"| FastAPI
    FastAPI -->|"stream response"| Streamlit
    Streamlit -->|"renders chat"| User

    %% Documentation link
    README -.-> Streamlit
    README -.-> FastAPI

    %% Click Events
    click Streamlit "https://github.com/bahawal32/chat_with_data/blob/main/stream_output.py"
    click FastAPI "https://github.com/bahawal32/chat_with_data/blob/main/api_url.py"
    click DataAccess "https://github.com/bahawal32/chat_with_data/blob/main/get_voting_data.py"
    click README "https://github.com/bahawal32/chat_with_data/blob/main/README.md"

    %% Styles
    classDef internal fill:#aed6f1,stroke:#21618c,color:#1b2631;
    classDef data fill:#abebc6,stroke:#148f77,color:#1b2631;
    classDef external fill:#f9e79f,stroke:#b9770e,color:#1b2631;
    classDef doc fill:#d7bde2,stroke:#6c3483,color:#1b2631;
```
