# alejandro-ao/chat-with-websites architecture

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

- Interactive diagram: https://gitdiagram.com/alejandro-ao/chat-with-websites
- Repository: https://github.com/alejandro-ao/chat-with-websites

## Overview

##### Project type and purpose
- This is a Python‐based, single‐page web application that implements a Retrieval-Augmented Generation (RAG) chatbot.
- It uses LangChain to fetch and vector-index website content, an LLM (e.g. GPT-4 via OpenAI API) for chat, and a Streamlit GUI for user interaction.

##### File structure
- Top‐level files:
- .env.example / .gitignore / requirements.txt – environment and dependency config
- readme.md – project overview and instructions
- src/app.py – main entry point combining Streamlit UI and LangChain pipeline

##### README for additional insights
- The README confirms:
- RAG pipeline: vectorize text, retrieve top matches, prefix them to the LLM prompt
- Streamlit frontend launch command
- External dependencies: OpenAI API, Python libraries listed in requirements.txt

##### Main components
a. Frontend (Streamlit GUI)
– Display area for chat output
b. Backend / Pipeline (LangChain)
– Website Loader (scrapes and cleans web content)
– Text Splitter & Embedding Module (vectorizes chunks)
– Vector Store (Chroma or similar in-memory/ disk store)
– Retriever (finds top-k similar chunks)
– LLM Module (OpenAI GPT-4 or alternative)
c. External Services
– OpenAI API endpoint
– Optional external vector DB if configured
d. Configuration & Environment
– .env for storing OPENAI_API_KEY

##### Relationships and data flow
- User submits URL and query in Streamlit →
- Website Loader fetches and parses raw HTML →
- Text Splitter feeds segments to the Embedding Module →
- Embeddings stored in Vector Store →
- Retriever searches for nearest neighbors based on query embedding →
- Retrieved text chunks + user query passed to LLM Module →
- Model response returned to Streamlit UI for display

##### Architectural patterns and design principles
- Modular pipeline: each stage (loader, embedder, retriever, LLM) is a separate component
- Single-page GUI decoupled from business logic
- Environment-driven configuration for API keys
- Reusable RAG chain: easy to swap LLM or vector store implementation

##### Final checklist
- GUI vs. Pipeline vs. External services
- Optional side note callout for README/ docs reference image
- Essential components without adding superfluous detail

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Frontend Layer
  subgraph "Frontend (Streamlit GUI)"
    UI["Streamlit UI (Input & Chat Display)"]:::frontend
  end

  %% Processing Pipeline
  subgraph "RAG Pipeline (LangChain)"
    Loader["Website Loader"]:::processing
    SplitEmbed["Text Splitter & Embedding Module"]:::processing
    VectorStore["Vector Store (Chroma)"]:::processing
    Retriever["Retriever"]:::processing
    LLM["LLM Module (OpenAI GPT-4)"]:::processing
  end

  %% External Services and Config
  subgraph "External Services & Config"
    OpenAIAPI["OpenAI API"]:::external
    Env["Configuration (.env)"]:::external
    Requirements["Dependency Config (requirements.txt)"]:::external
    README["Project Overview (readme.md)"]:::external
    DiagramRef["Reference Diagram"]:::external
  end

  %% Data Flow
  UI -->|"URL & Query"| Loader
  Loader -->|"parsed HTML"| SplitEmbed
  SplitEmbed -->|"embeddings"| VectorStore
  VectorStore -->|"index"| Retriever
  Retriever -->|"top-k chunks + query"| LLM
  LLM -->|"response"| UI

  %% Config & External Links
  Env --> UI
  Env --> LLM
  OpenAIAPI --> LLM

  %% Documentation Links
  Requirements -.-> UI
  README -.-> UI
  DiagramRef -.-> SplitEmbed

  %% Click Events
  click UI "https://github.com/alejandro-ao/chat-with-websites/blob/master/src/app.py"
  click Loader "https://github.com/alejandro-ao/chat-with-websites/blob/master/src/app.py"
  click SplitEmbed "https://github.com/alejandro-ao/chat-with-websites/blob/master/src/app.py"
  click VectorStore "https://github.com/alejandro-ao/chat-with-websites/blob/master/src/app.py"
  click Retriever "https://github.com/alejandro-ao/chat-with-websites/blob/master/src/app.py"
  click LLM "https://github.com/alejandro-ao/chat-with-websites/blob/master/src/app.py"
  click Env "https://github.com/alejandro-ao/chat-with-websites/blob/master/.env.example"
  click Requirements "https://github.com/alejandro-ao/chat-with-websites/blob/master/requirements.txt"
  click README "https://github.com/alejandro-ao/chat-with-websites/blob/master/readme.md"
  click DiagramRef "https://github.com/alejandro-ao/chat-with-websites/blob/master/docs/HTML-rag-diagram.jpg"

  %% Styles
  classDef frontend fill:#AED6F1,stroke:#1F618D,color:#1B2631
  classDef processing fill:#A9DFBF,stroke:#196F3D,color:#1B2631
  classDef external fill:#FAD7A0,stroke:#B9770E,color:#1B2631
```
