# hassameh7543/langgraph_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/hassameh7543/langgraph_chatbot
- Repository: https://github.com/hassameh7543/langgraph_chatbot

## Overview

##### Project Type and Purpose
- This is a lightweight full-stack conversational AI app.
- Frontend: Streamlit UI for chat threads, animations, downloads
- Backend: Python logic (LangGraph + Groq LLM integration)
- Persistence: SQLite database for chat history (chatbot.db)

##### File Structure
- Top-level:
- chatbot_frontend.py – Streamlit UI
- chatbot_backend.py  – business logic & threading
- chatbot.db          – SQLite persistence
- README.md, .gitignore
- No separate “src” folder: frontend and backend live at top level
- Single database file implies an embedded data layer

##### Key Insights from README
- Multi-threaded conversations tracked by thread_id
- Persistent memory via SQLite checkpoints
- Streamed AI responses with typing animation
- Downloadable transcript feature

##### Main Components
a. Frontend (Streamlit App)
- User input, chat UI, buttons (new thread, download transcript)
- Displays streaming responses and animations
b. Backend Logic
- Thread management (thread_id generation)
- LangGraph orchestrator + ChatGroq client
- Streams tokens back to UI
- Writes/reads from SQLite
c. Database
- SQLite file ‘chatbot.db’
- Tables: threads, messages
d. External AI Service
- Groq LLM endpoint (openai/gpt-oss-120b)

##### Relationships and Data Flows
- User → Frontend: enters message, selects thread
- Frontend → Backend: HTTP/RPC call or local function invocation
- Backend ↔ Database:
– Write new message
– Fetch existing history
- Backend → Groq LLM API: send prompt, stream response
- Groq LLM → Backend → Frontend: streaming tokens
- Frontend → User: render streamed response

##### Architectural Patterns & Design Principles
- Layered architecture: Presentation (UI) → Business (chat logic) → Data (SQLite)
- Single-process multi-threading for thread isolation
- Streaming data pipeline for real-time UX
- Simple persistence (no external DB server)

##### Final Recommendations
- Break out the App into two sub-components: Frontend & Backend
- Detail interactions: thread creation, message storage, token streaming
- Keep it simple but capture every moving part: UI, business logic, data, external service
- Review with stakeholders to ensure no component is missed

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::user

    %% Frontend Layer
    subgraph "Frontend (Streamlit UI)"
        UI["Streamlit UI"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Business Logic)"
        BackendLogic["Backend Logic"]:::business
    end

    %% Database
    DB["SQLite Database"]:::database

    %% External AI Service
    AI["Groq LLM API\n(openai/gpt-oss-120b)"]:::external

    %% Data Flows
    User -->|"enters message\nselects thread"| UI
    UI -->|"send message\nand thread_id"| BackendLogic
    BackendLogic -->|"<back-and-forth>\nCRUD operations"| DB
    BackendLogic -->|"send prompt\n(stream request)"| AI
    AI -->|"streaming response\n(tokens)"| BackendLogic
    BackendLogic -->|"streamed tokens"| UI
    UI -->|"render response\ntranscript/download"| User

    %% Click Events
    click UI "https://github.com/hassameh7543/langgraph_chatbot/blob/main/chatbot_frontend.py"
    click BackendLogic "https://github.com/hassameh7543/langgraph_chatbot/blob/main/chatbot_backend.py"
    click DB "https://github.com/hassameh7543/langgraph_chatbot/blob/main/chatbot.db"

    %% Styles
    classDef user fill:#FFD580,stroke:#333,stroke-width:1px;
    classDef frontend fill:#80C1FF,stroke:#333,stroke-width:1px;
    classDef business fill:#A3FF80,stroke:#333,stroke-width:1px;
    classDef database fill:#FFB3E6,stroke:#333,stroke-width:1px;
    classDef external fill:#D9D9D9,stroke:#333,stroke-width:1px;
```
