# nayankr8625/wordpressaibot architecture

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

- Interactive diagram: https://gitdiagram.com/nayankr8625/wordpressaibot
- Repository: https://github.com/nayankr8625/wordpressaibot

## Overview

##### Project Type and Purpose
- This is a full-stack chatbot system leveraging Retrieval-Augmented Generation (RAG) and Chain-of-Thought (CoT) techniques to serve context-aware answers on WordPress blogs.
- Key functions: content ingestion (WordPress API), embedding generation (Sentence-BERT), vector indexing (Faiss), RAG processing, CoT logic, LLM query orchestration, and UI integration (Streamlit local demo & WordPress plugin).

##### File Structure
- Top-level orchestrators:  • app.py (likely Flask/FastAPI service)  • streamlit_app.py (demo UI)  • Dockerfile/requirements.txt
- Data ingestion:  • data_collection/data_collection.py
- Embedding/indexing:  • embedding/create_index.py
- Storage:  • doc_embedding_store/… (prebuilt .faiss + .pkl indexes per document set)
- RAG & LLM logic:  • gen_ai/prompts.py  • gen_ai/query_llm.py
- Presentation template:  • template/htmlTemplate.py (for WordPress plugin)

##### Extract Architectural Insights from README
- Components called out: Data Retrieval (WP API), Embedding Generator, Vector Database (Faiss), RAG Processor, Chain of Thought Module, User Interface (chat widget or Streamlit).
- Deployment: packaged as a Docker image, integrated via a WordPress plugin.

##### Main Components & Their Interactions
a. Data Retrieval Service
- Fetches blog content through WordPress REST API (data_collection).
- Outputs raw text to embedding pipeline.
b. Embedding Generator
- Uses create_index.py (Sentence-BERT) to convert text to vectors.
- Stores vectors + metadata in Faiss index + pickle files (doc_embedding_store).
c. Vector Database (Faiss)
- Provides high-speed semantic similarity search for RAG retrieval.
d. RAG Processor & CoT Module
- query_llm.py orchestrates:
1. Receive user query via app.py or streamlit_app.py
2. Retrieve top-k embeddings from Faiss
3. Construct RAG prompt with Chain-of-Thought scaffolding (prompts.py)
4. Send to LLM (OpenAI, etc.) and receive response
e. Application Layer / API
- app.py: exposes REST endpoints for the WordPress plugin or external UIs
- streamlit_app.py: local/demo UI that consumes same RAG endpoints
f. Front-End Integration
- template/htmlTemplate.py: chat widget HTML + JS for WordPress
- Deployed as a WordPress plugin, invoking the external API

##### Architectural Patterns & Design Principles
- Separation of concerns: ingestion, processing, storage, API, UI
- Micro-service-style modules (each directory = logical service)
- Stateless API layer with external stateful vector DB
- Containerized deployment (Dockerfile) for portability
- Precomputed indexes for efficient startup and scaling

- Optional: Deployment artifacts (Docker container, volumes for doc_embedding_store)

Checklist Before Finalizing:
[ ] All six major components represented
[ ] Two workflows clearly delineated (Indexing vs Query)
[ ] Technology logos or annotations (Faiss, SBERT, OpenAI, Docker)
[ ] Environment boundaries (WP site vs Chatbot service)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Environment Boundary
    subgraph "On-Premises WordPress Site"
        WPAPI["WordPress REST API"]:::external
    end

    %% Indexing Pipeline
    subgraph "Indexing Pipeline" 
        direction TB
        DR["Data Retrieval Service"]:::dataIngestion
        EG["Embedding Generator"]:::dataIngestion
        DB["Faiss Vector Store"]:::storage
    end

    %% Query Pipeline
    subgraph "Query Pipeline"
        direction TB
        WPWidget["WP Chat Widget"]:::ui
        Streamlit["Streamlit Demo UI"]:::ui
        API["API Layer (app.py)"]:::api
        QLLM["LLM Orchestration"]:::processing
        PROMPT["Prompt Module"]:::processing
        DB2["Faiss Vector Store"]:::storage
        LLM["LLM (OpenAI)"]:::processing
    end

    %% Indexing Flow
    WPAPI -->|"fetch content"| DR
    DR -->|"generate embeddings"| EG
    EG -->|"indexing"| DB

    %% Query Flow
    WPWidget -.->|"Query"| API
    Streamlit -.->|"Query"| API
    API -->|"forward query"| QLLM
    QLLM -->|"retrieve vectors"| DB2
    DB2 -->|"vectors"| QLLM
    QLLM -->|"build CoT prompt"| PROMPT
    PROMPT -->|"prompt text"| QLLM
    QLLM -->|"LLM call"| LLM
    LLM -->|"response"| QLLM
    QLLM -->|"answer"| API
    API -->|"deliver response"| WPWidget
    API -->|"deliver response"| Streamlit

    %% Deployment
    subgraph "Deployment Artifacts"
        direction TB
        Docker["Docker Container"]:::infra
        Req["requirements.txt"]:::infra
    end
    Docker --- API
    Docker --- DR
    Docker --- Streamlit

    %% Click Events
    click DR "https://github.com/nayankr8625/wordpressaibot/blob/master/data_collection/data_collection.py"
    click EG "https://github.com/nayankr8625/wordpressaibot/blob/master/embedding/create_index.py"
    click DB "https://github.com/nayankr8625/wordpressaibot/tree/master/doc_embedding_store/"
    click QLLM "https://github.com/nayankr8625/wordpressaibot/blob/master/gen_ai/query_llm.py"
    click PROMPT "https://github.com/nayankr8625/wordpressaibot/blob/master/gen_ai/prompts.py"
    click API "https://github.com/nayankr8625/wordpressaibot/blob/master/app.py"
    click Streamlit "https://github.com/nayankr8625/wordpressaibot/blob/master/streamlit_app.py"
    click WPWidget "https://github.com/nayankr8625/wordpressaibot/blob/master/template/htmlTemplate.py"
    click Docker "https://github.com/nayankr8625/wordpressaibot/tree/master/Dockerfile"
    click Req "https://github.com/nayankr8625/wordpressaibot/blob/master/requirements.txt"

    %% Styles
    classDef dataIngestion fill:#D6EFFF,stroke:#0077B6,color:#000
    classDef storage fill:#DFFEE0,stroke:#2E7D32,color:#000
    classDef processing fill:#FFE6CC,stroke:#EF6C00,color:#000
    classDef api fill:#F3E8FF,stroke:#6A1B9A,color:#000
    classDef ui fill:#FFF8E1,stroke:#F9A825,color:#000
    classDef infra fill:#ECEFF1,stroke:#546E7A,color:#000
    classDef external fill:#F0F0F0,stroke:#9E9E9E,color:#000

    %% Legend
    subgraph Legend
        direction LR
        A["Data Ingestion"]:::dataIngestion
        B["Storage & Retrieval"]:::storage
        C["Processing & Orchestration"]:::processing
        D["API Layer"]:::api
        E["User Interfaces"]:::ui
        F["Infrastructure"]:::infra
    end
```
