# sudarshan-koirala/chat-with-website architecture

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

- Interactive diagram: https://gitdiagram.com/sudarshan-koirala/chat-with-website
- Repository: https://github.com/sudarshan-koirala/chat-with-website

## Overview

This project is a lightweight full-stack application designed to allow users to interact with a website’s content using chat interfaces. It leverages Large Language Models (LLMs) via two different UIs – Streamlit and Chainlit – and integrates with LangChain for LLM management. The codebase supports two types of LLM providers (OpenAI and Ollama/mistral), and also includes a document ingestion component.

##### Main Components
- Environment/Configuration: Represent the configuration files (example.env renamed to .env), requirements.txt, and licensing files.
- UI Layer:
◦ Streamlit-based interface (chat_with_website_openai.py & chat_with_website_ollama.py)
◦ Chainlit interface (main.py alongside ingest.py for ingestion)
- Ingestion Module:
◦ ingest.py – this component is responsible for preprocessing or loading the website’s documents.
- LLM Integrations:
◦ OpenAI model integration (referenced in chat_with_website_openai.py)
◦ Ollama/mistral integration (referenced in chat_with_website_ollama.py)
- Framework Integration:
◦ LangChain – the integration acts as the backbone to interface with various LLMs and manage conversational context.

##### Relationships & Interactions
- The LangChain framework is central and interacts with both the UI components and the LLM integrations, managing requests and relaying responses.

##### Architectural Patterns
- Separation of Concerns: Different Python scripts handle distinct responsibilities (e.g., separate UIs, ingestion logic, LLM integration).
- Multi-Interface Support: Highlight how both Streamlit and Chainlit serve as different front ends interfacing with the same underlying logic.
- Config-driven Behavior: Environment variables (from .env) control API keys and runtime settings.

##### Relevant Technologies & Libraries
- Python 3.9+ is the runtime.
- Streamlit and Chainlit for UI deployments.
- LangChain for LLM integration.
- External LLMs (OpenAI and Ollama/mistral) which provide natural language processing capabilities.
- Git, licensing, and configuration management files for project governance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration Layer
    subgraph "Configuration Layer"
        ENV[".env"]:::config
        REQ["requirements.txt"]:::config
        LIC["LICENSE"]:::config
    end

    %% UI Layer
    subgraph "UI Layer"
        subgraph "Streamlit UI"
            ST_OpenAI["Streamlit Chat (OpenAI)"]:::ui
            ST_Ollama["Streamlit Chat (Ollama)"]:::ui
        end
        subgraph "Chainlit UI"
            CL["Chainlit Chat Interface"]:::ui
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        LC["LLM Integration (LangChain)"]:::logic
        ING["Document Ingestion Module"]:::logic
    end

    %% External LLM Providers
    subgraph "External LLM Providers"
        OA["OpenAI LLM Provider"]:::external
        OL["Ollama/mistral LLM Provider"]:::external
    end

    %% Relationships
    %% Configuration supports Business Logic
    ENV -->|"configures"| LC
    REQ --> LC
    LIC --> LC

    %% UI components send queries to LangChain
    ST_OpenAI -->|"sends_query"| LC
    ST_Ollama -->|"sends_query"| LC
    CL -->|"sends_query"| LC

    %% Document Ingestion interacts with UI Layer
    ING -->|"provides_docs"| ST_OpenAI
    ING -->|"provides_docs"| ST_Ollama
    ING -->|"provides_docs"| CL

    %% LangChain interacts with External LLM Providers
    LC -->|"calls"| OA
    LC -->|"calls"| OL
    OA -->|"responds"| LC
    OL -->|"responds"| LC

    %% Styling Classes
    classDef config fill:#ffcccb,stroke:#ff0000,stroke-width:2px;
    classDef ui fill:#ccffcc,stroke:#008000,stroke-width:2px;
    classDef logic fill:#cce5ff,stroke:#004080,stroke-width:2px;
    classDef external fill:#fff2cc,stroke:#d79b00,stroke-width:2px;

    %% Click Events
    click ENV "https://github.com/sudarshan-koirala/chat-with-website/blob/main/.env"
    click REQ "https://github.com/sudarshan-koirala/chat-with-website/blob/main/requirements.txt"
    click LIC "https://github.com/sudarshan-koirala/chat-with-website/tree/main/LICENSE"
    click ST_OpenAI "https://github.com/sudarshan-koirala/chat-with-website/blob/main/chat_with_website_openai.py"
    click ST_Ollama "https://github.com/sudarshan-koirala/chat-with-website/blob/main/chat_with_website_ollama.py"
    click CL "https://github.com/sudarshan-koirala/chat-with-website/blob/main/main.py"
    click ING "https://github.com/sudarshan-koirala/chat-with-website/blob/main/ingest.py"
```
