# drizgolovicha/ai-chatbot-js architecture

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

- Interactive diagram: https://gitdiagram.com/drizgolovicha/ai-chatbot-js
- Repository: https://github.com/drizgolovicha/ai-chatbot-js

## Overview

##### Project Type and Purpose
- This is a full-stack, Retrieval-Augmented Generation (RAG) AI assistant.
- Backend: Python FastAPI serving as the API and RAG pipeline.
- Frontend: Pure JavaScript UI (chat.html, chat.js) embeddable into any website.
- Data pipeline: Scripts to scrape, enrich, and ingest content into a local vector store (ChromaDB).
- Pluggable LLM providers: Local (Ollama/Llama) or remote (Together.ai).

##### File Structure Analysis
- Top level
- main.py – FastAPI entrypoint.
- pyproject.toml / requirements.txt – dependencies.
- data/links.txt – seed URLs for scraping.
- public/ – static UI files (HTML, JS, CSS, libs).
- Directories
- scripts/ – ETL pipeline: scrapper.py → ingest.py → text_enrichment.py → terminal.py.
- providers/ – abstraction for AI providers (ollama.py, together.py).
- models/ – domain models and index logic for vector DB.
- utils/ – docstore and indexing utilities.
- dialogs/ & docs/ – version control placeholders.

##### README Insights
- RAG-based pipeline: scrape web pages → markdown → embeddings → ChromaDB/SQLite → API.
- LLM integration: local or cloud.
- UI injection: public/chat.html or iframe.html.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Pipeline Layer
    subgraph "Data Ingestion Layer"
        direction TB
        LinksTxt["data/links.txt"]:::data
        Scraper["scripts/scrapper.py"]:::data
        Enricher["scripts/text_enrichment.py"]:::data
        Ingestor["scripts/ingest.py"]:::data
    end

    %% Storage Layer
    subgraph "Storage Layer"
        direction TB
        ChromaDB["ChromaDB (SQLite)"]:::storage
        DomainIndex["models/index.py"]:::storage
        DocstoreUtil["utils/docstore.py"]:::storage
        IndexUtil["utils/index.py"]:::storage
    end

    %% API & RAG Pipeline
    subgraph "API & RAG Pipeline"
        direction TB
        API["main.py (FastAPI)"]:::api
        QueryOrch["Query Orchestrator\n(models/index.py)"]:::api
    end

    %% Provider Abstraction
    subgraph "Provider Adapters"
        direction TB
        OllamaAdapter["providers/ollama.py"]:::api
        TogetherAdapter["providers/together.py"]:::api
    end

    %% External Services
    subgraph "External LLM Services"
        direction TB
        LocalLLM["Ollama Runtime"]:::external
        TogetherAI["Together.ai API"]:::external
    end

    %% Frontend UI
    subgraph "Frontend UI"
        direction TB
        ChatHTML["public/chat.html"]:::frontend
        ChatJS["public/chat.js"]:::frontend
        IframeHTML["public/iframe.html"]:::frontend
        CSS["public/css/style.css"]:::frontend
        Drawdown["public/libs/drawdown.js"]:::frontend
    end

    %% Connections: Data Pipeline to Storage
    LinksTxt -->|"scrape→markdown"| Scraper
    Scraper -->|"enrich→md"| Enricher
    Enricher -->|"generate embeddings"| Ingestor
    Ingestor -->|"store embeddings"| ChromaDB

    %% Storage to API
    ChromaDB -->|"query embeddings"| QueryOrch
    DomainIndex -->|"index lookup"| QueryOrch
    DocstoreUtil -->|"doc retrieval"| QueryOrch
    IndexUtil -->|"helper utilities"| QueryOrch

    %% API to Providers
    QueryOrch -->|"select provider"| OllamaAdapter
    QueryOrch -->|"select provider"| TogetherAdapter
    OllamaAdapter -.->|"LLM call"| LocalLLM
    TogetherAdapter -.->|"LLM call"| TogetherAI

    %% Frontend to API
    ChatJS -->|"REST/WebSocket"| API
    API -->|"response→render"| ChatJS
    ChatHTML --> ChatJS
    IframeHTML --> ChatJS
    ChatJS -->|"render chat"| Drawdown
    CSS --> ChatHTML

    %% File-level interactions
    Scraper --> DomainIndex
    Enricher --> IndexUtil

    %% Click events
    click LinksTxt "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/data/links.txt"
    click Scraper "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/scripts/scrapper.py"
    click Enricher "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/scripts/text_enrichment.py"
    click Ingestor "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/scripts/ingest.py"
    click DomainIndex "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/models/index.py"
    click DocstoreUtil "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/utils/docstore.py"
    click IndexUtil "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/utils/index.py"
    click API "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/main.py"
    click OllamaAdapter "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/providers/ollama.py"
    click TogetherAdapter "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/providers/together.py"
    click ChatHTML "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/public/chat.html"
    click ChatJS "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/public/chat.js"
    click IframeHTML "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/public/iframe.html"
    click CSS "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/public/css/style.css"
    click Drawdown "https://github.com/drizgolovicha/ai-chatbot-js/blob/main/public/libs/drawdown.js"

    %% Styles
    classDef data fill:#cce5ff,stroke:#66b0ff,color:#000;
    classDef storage fill:#d4edda,stroke:#70c28a,color:#000;
    classDef api fill:#ffe5b4,stroke:#ffb766,color:#000;
    classDef frontend fill:#e5ccff,stroke:#b766ff,color:#000;
    classDef external fill:#f8d7da,stroke:#e29a9b,color:#000;
```
