# ntdat02092002/lol-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/ntdat02092002/lol-chatbot
- Repository: https://github.com/ntdat02092002/lol-chatbot

## Overview

##### Project Type and Purpose
- This is a full-stack, RAG-based chatbot application with two main concerns:
a. Automated data pipeline to crawl, embed, and store League of Legends patch notes.
b. Interactive Streamlit UI that uses a vector DB and LLM to answer user questions about the latest patch.

##### File Structure
- Top-level scripts and their roles:
- chatbot.py & main.py – entrypoint for the Streamlit UI and orchestrator of the chat interactions.
- pinecone_data_flow.py – defines a Prefect flow to crawl patch notes, embed text, and upsert into Pinecone.
- prefect_deployment.py – registers and deploys the Prefect flow to Prefect Cloud.
- prompt_template.py – holds reusable prompt formats for LangChain.
- utils.py & test.py – utility functions and unit tests.
- config.json – model/configuration settings for different LLMs/embeddings.
- Infrastructure as code / CI files in .github/workflows
- Requirements.txt, .python-version for environment reproducibility

##### Extract Insights from README
- Tech Stack: Streamlit for UI, LangChain + Google AI for LLM & embeddings, Pinecone for vector store, Prefect for workflow orchestration, BeautifulSoup for crawling, WandB for logging.
- Data Flow: daily crawl → embed → Pinecone index → RAG retrieval → Streamlit UI → LLM → user.
- External Dependencies: Google AI Studio (LLM & embeddings), Pinecone, Prefect Cloud, Weights & Biases.

##### Main Components & Their Interactions
a. User Interface (Streamlit)
- Accepts user queries, invokes the retrieval chain, displays LLM responses.
b. Retrieval & Generation Layer (LangChain)
- Self-query retriever against Pinecone, constructs prompts via prompt_template.py, calls Google AI LLM.
c. Vector Database (Pinecone)
- Stores embeddings of patch notes, supports similarity search.
d. Workflow Orchestrator (Prefect)
- Scheduled/Manual flows to crawl (BeautifulSoup), process, embed, and upsert into Pinecone.
e. External Services
- Google AI Studio API, Pinecone API, Prefect Cloud API, WandB API for logging interactions.

##### Architectural Patterns & Design Principles
- Separation of concerns: data ingestion pipeline decoupled from UI.
- RAG (Retrieval-Augmented Generation) pattern for context-aware Q&A.
- Modular design: prompt templates, utilities, and config abstracted out.
- Workflow scheduling via Prefect, enabling reproducibility and visibility.

##### Final Checklist
- All components distinctly labeled.
- Annotation of external dependencies and environment variables (e.g., PINECONE_API_KEY).
- Coverage of both the automated flow and the real-time chat flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Offline Data Pipeline
    subgraph "Offline Data Pipeline"
        direction TB
        PrefectScheduler["Prefect Scheduler"]:::orchestration
        PrefectScheduler -->|"daily cron"| PineconeFlow["pinecone_data_flow.py"]:::orchestration
        PrefectDeploy["prefect_deployment.py"]:::orchestration
        PrefectScheduler -->|"registers flow"| PrefectDeploy
        PineconeFlow -->|"crawls & parses"| Crawler["BeautifulSoup Crawler"]:::code
        Crawler -->|"generate embeddings"| Embeddings["Text Embeddings"]:::code
        Embeddings -->|"upsert_embeddings"| PineconeDB["Pinecone Index"]:::store
        CI_Pipeline["CI / IaC (.github workflows)"]:::orchestration
    end

    %% Online Chat Flow
    subgraph "Online Chat Flow"
        direction TB
        User["User"]:::external
        StreamlitUI["Streamlit UI"]:::ui
        Retrieval["LangChain Retrieval & Generation"]:::ui
        LLM["Google AI LLM"]:::external
        WandB["Weights & Biases"]:::store

        User -->|"asks question"| StreamlitUI
        StreamlitUI -->|"retrieve_chain"| Retrieval
        Retrieval -->|"similarity_search"| PineconeDB
        Retrieval -->|"construct_prompt"| PromptTemplate["prompt_template.py"]:::code
        PromptTemplate --> Retrieval
        Retrieval -->|"call LLM"| LLM
        LLM -->|"response"| StreamlitUI
        StreamlitUI -->|"log_interaction"| WandB
    end

    %% Configuration
    Config["config.json"]:::code
    Config -.-> StreamlitUI
    Config -.-> PineconeFlow

    %% External APIs
    PineconeAPI["Pinecone API"]:::external
    PrefectCloudAPI["Prefect Cloud API"]:::external
    GoogleAPI["Google AI Studio API"]:::external

    PineconeFlow -->|"calls Pinecone API"| PineconeAPI
    Retrieval -->|"calls Google AI Studio"| GoogleAPI
    PrefectScheduler -->|"uses Prefect Cloud"| PrefectCloudAPI

    %% Utilities & Testing
    Utils["utils.py"]:::code
    Test["test.py"]:::code

    Utils --> Retrieval
    Utils --> PineconeFlow
    Test --> Utils

    %% Click Events
    click StreamlitUI "https://github.com/ntdat02092002/lol-chatbot/blob/main/chatbot.py"
    click StreamlitUI "https://github.com/ntdat02092002/lol-chatbot/blob/main/main.py"
    click PromptTemplate "https://github.com/ntdat02092002/lol-chatbot/blob/main/prompt_template.py"
    click Utils "https://github.com/ntdat02092002/lol-chatbot/blob/main/utils.py"
    click PineconeFlow "https://github.com/ntdat02092002/lol-chatbot/blob/main/pinecone_data_flow.py"
    click PrefectDeploy "https://github.com/ntdat02092002/lol-chatbot/blob/main/prefect_deployment.py"
    click CI_Pipeline "https://github.com/ntdat02092002/lol-chatbot/blob/main/.github/workflows/prefect_flow.yml"
    click CI_Pipeline "https://github.com/ntdat02092002/lol-chatbot/blob/main/.github/workflows/check.yml"
    click CI_Pipeline "https://github.com/ntdat02092002/lol-chatbot/blob/main/.github/workflows/main.yml"
    click Config "https://github.com/ntdat02092002/lol-chatbot/blob/main/config.json"
    click Test "https://github.com/ntdat02092002/lol-chatbot/blob/main/test.py"

    %% Styles
    classDef ui fill:#bae1ff,stroke:#000
    classDef store fill:#baffc9,stroke:#000
    classDef orchestration fill:#ffffba,stroke:#000
    classDef external fill:#e0e0e0,stroke:#000
    classDef code fill:#ffffff,stroke:#000
```
