# dhairyaaa15/webpage-bot-extension architecture

> Architecture diagram of the GitHub repository dhairyaaa15/webpage-bot-extension, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhairyaaa15/webpage-bot-extension
- Repository: https://github.com/dhairyaaa15/webpage-bot-extension

## Overview

##### Backend’s purpose and main components
- Purpose: Expose two HTTP endpoints (`/analyze`, `/ask`) that crawl webpages, summarize content, and answer user questions via an AI model.
- Components:
- Flask app (`app.py`)
- Analyzer module (`analyzer.py`)
- Chatbot module (`chatbot.py`)
- External services: Playwright browser, Gemini LLM API
- Session store (in-memory or simple dict in `app.py`)

A. Client → POST /analyze
1. Flask route handler in `app.py` receives `{ "url": "..." }`.
2. Calls `analyzer.py`:
- Launches Playwright, navigates to the URL
- Extracts page content, generates a summary/chunked context
- Returns `{ message, prompt_preview, session_id }`
3. `app.py` stores the summary & session context keyed by `session_id`.
4. Response sent back to client with JSON payload.

B. Client → POST /ask
1. Flask route handler in `app.py` receives `{ "question", "session_id" }`.
2. Looks up context using `session_id`.
3. Calls `chatbot.py`:
- Sends the stored context + user question to Gemini LLM API
- Receives AI’s answer
4. Returns `{ "answer": "<AI's answer>" }` to client.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["HTTP Client"]:::external
    Flask["Flask App"]:::internal
    Analyzer["Analyzer Module"]:::internal
    Playwright["Playwright"]:::external
    SessionStore["Session Store"]:::store
    Chatbot["Chatbot Module"]:::internal
    Gemini["Gemini LLM API"]:::external

    Client -->|"POST /analyze {url}"| Flask
    Flask -->|"analyze(url)"| Analyzer
    Analyzer -->|"launch & scrape"| Playwright
    Playwright -->|"page content"| Analyzer
    Analyzer -->|"summary + session_id"| Flask
    Flask -->|"store session context"| SessionStore
    Flask -->|"response JSON"| Client

    Client -->|"POST /ask {question, session_id}"| Flask
    Flask -->|"retrieve context"| SessionStore
    SessionStore -->|"context"| Flask
    Flask -->|"ask(question,context)"| Chatbot
    Chatbot -->|"REST call question+context"| Gemini
    Gemini -->|"AI answer"| Chatbot
    Chatbot -->|"AI answer"| Flask
    Flask -->|"response JSON"| Client

    click Flask "https://github.com/dhairyaaa15/webpage-bot-extension/blob/main/backend/app.py"
    click Analyzer "https://github.com/dhairyaaa15/webpage-bot-extension/blob/main/backend/analyzer.py"
    click Playwright "https://github.com/dhairyaaa15/webpage-bot-extension/blob/main/backend/analyzer.py"
    click SessionStore "https://github.com/dhairyaaa15/webpage-bot-extension/blob/main/backend/app.py"
    click Chatbot "https://github.com/dhairyaaa15/webpage-bot-extension/blob/main/backend/chatbot.py"
    click Gemini "https://github.com/dhairyaaa15/webpage-bot-extension/blob/main/backend/chatbot.py"

    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px
    classDef store fill:#FFA500,stroke:#000,stroke-width:1px
```
