# ariharasudhan-adaikalam/wikibot architecture

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

- Interactive diagram: https://gitdiagram.com/ariharasudhan-adaikalam/wikibot
- Repository: https://github.com/ariharasudhan-adaikalam/wikibot

## Overview

##### Project Type and Purpose
- This is a full-stack Python application implementing a Retrieval-Augmented Generation (RAG) chatbot (“WikiBot🤖”) with a Streamlit UI, Wikipedia scraper, embedding pipeline, vector store, and LLM via HuggingFace.

##### File-Structure Analysis
- Top-level scripts:
- wikibot.py – entry point (Streamlit UI + orchestration)
- wiki_content.py – fetch & parse Wikipedia pages
- vector_embeddings.py – chunk text & build embeddings
- Config: .env (HuggingFace API token), requirements.txt, wheel for pysqlite3
- No sub-folders: a monolithic Python service with clearly separated modules.

##### Main Components
a. Streamlit UI (wikibot.py) – user-facing web interface
b. Wikipedia Scraper (wiki_content.py) – HTTP GET to wikipedia.org → parse HTML → extract text
c. Text Splitter & Embedding Generator (vector_embeddings.py) – use RecursiveTextSplitter → sentence-transformers model → produce embeddings
d. Chroma Vector Store – local vector DB (via chromadb + pysqlite3)
e. LangChain Orchestrator – glue code that handles retrieval and calls LLM
g. External Services – Wikipedia (HTTP), HuggingFace Hub API

##### Relationships and Data Flow
1. User enters query in Streamlit UI
2. UI → calls LangChain orchestrator in wikibot.py
3. Orchestrator invokes:
- Scraper module to fetch & parse Wikipedia
- Text splitter & embedding module to chunk & embed content
- Stores embeddings + chunks in Chroma DB (if not already cached)
4. For each new query:
- Retrieve top-k relevant chunks from Chroma by embedding the query
- Construct prompt (directive-based pattern) with retrieved chunks
- Send prompt to HuggingFace LLM API → receive generated answer
5. UI displays answer back to user

##### Architectural Patterns & Principles
- Modular design: separation of concerns (UI, scraping, embedding, storage, retrieval, generation)
- RAG pattern: combine external retrieval (Wikipedia + vector store) with generative model
- Caching: persist embeddings in Chroma to avoid re-computing
- Single process container (monolith) but logically divided into components

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface"
        UI["<i class='fas fa-browser'></i><br/>Streamlit UI"]:::ui
    end

    subgraph "Backend"
        direction TB
        ORCH["LangChain Orchestrator<br/>(wikibot.py)"]:::modules
        SCRAPER["Wikipedia Scraper<br/>(requests + BeautifulSoup)"]:::modules
        EMBED["Text Splitter & Embedding<br/>(RecursiveTextSplitter + sentence-transformers)"]:::modules
        STORE["Chroma Vector Store<br/>(chromadb + pysqlite3)"]:::datastore
        PROMPT["Prompt Constructor<br/>(LangChain)"]:::modules
    end

    subgraph "External Services"
        direction TB
        WIKI["Wikipedia"]:::external
        HF["HuggingFace LLM API<br/>(Meta-Llama-3-8B-Instruct)"]:::external
    end

    subgraph "Documentation & Config"
        direction TB
        ENV[".env"]:::modules
        REQ["requirements.txt"]:::modules
        DOC["README.md"]:::modules
    end

    UI -->|"submit query"| ORCH
    ORCH -->|"fetch HTML (HTTP)"| SCRAPER
    SCRAPER -->|"parsed text"| EMBED
    EMBED -->|"persist embeddings"| STORE

    ORCH -->|"embed query"| EMBED
    EMBED -->|"query embeddings"| STORE
    STORE -->|"relevant chunks"| PROMPT
    PROMPT -->|"API call (JSON prompt)"| HF
    HF -->|"generated answer (JSON)"| ORCH
    ORCH -->|"display answer"| UI

    classDef ui fill:#D6CADD,stroke:#7F3FBF,color:#4B0082;
    classDef modules fill:#ADD8E6,stroke:#0366D6,color:#00008B;
    classDef datastore fill:#D5F5E3,stroke:#27AE60,color:#006400;
    classDef external fill:#FDEBD0,stroke:#D35400,color:#A04000;

    click UI "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/wikibot.py"
    click ORCH "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/wikibot.py"
    click SCRAPER "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/wiki_content.py"
    click EMBED "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/vector_embeddings.py"
    click ENV "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/.env"
    click REQ "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/requirements.txt"
    click DOC "https://github.com/ariharasudhan-adaikalam/wikibot/blob/main/README.md"
```
