# harsha943vf/page_chat architecture

> Architecture diagram of the GitHub repository harsha943vf/page_chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harsha943vf/page_chat
- Repository: https://github.com/harsha943vf/page_chat

## Overview

PageChat is a Flask app for loading a web page, preparing searchable chunks, and answering questions about that page with a local Ollama model. The main workflow runs through page loading and chat API handlers in app.py; the static HTML is the browser-facing interface, but its wiring is not shown in the excerpts. The graph preserves documented capabilities such as chunk browsing, caching, and performance statistics. Some internal calls are in omitted portions of app.py, so those links are marked unverified rather than asserted.

Main entry points: [`pagechat/app.py`](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py) (Chat API), [`pagechat/static/index.html`](https://github.com/harsha943vf/page_chat/blob/main/pagechat/static/index.html) (PageChat UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_page["Page preparation"]
  node_load_api["Page load API<br/>[app.py]"]
  node_extract["Page extraction<br/>[app.py]"]
  node_chunk["Section chunking<br/>[app.py]"]
  node_embed["Embedding preparation<br/>[app.py]"]
  node_chunks_api["Chunk browsing API<br/>[app.py]"]
end

subgraph group_answer["Question answering"]
  node_chat_api["Chat API<br/>[app.py]"]
  node_retrieval["Hybrid retrieval<br/>[app.py]"]
  node_context["Context assembly<br/>[app.py]"]
end

subgraph group_state["Page and session state"]
  node_page_cache[("Page cache<br/>[app.py]")]
  node_conversation[("Conversation history<br/>[app.py]")]
  node_stats_api["Cache statistics API<br/>[app.py]"]
  node_clear_api["Cache and chat clearing<br/>[app.py]"]
end

subgraph group_interface["Browser interface"]
  node_browser["PageChat UI<br/>[index.html]"]
end

node_user(("User"))
node_web["Web page"]
node_ollama_embed["Ollama embeddings"]
node_chat_model["Ollama chat model"]

node_user -.->|"uses"| node_browser
node_browser -.->|"requests page"| node_load_api
node_load_api -->|"calls"| node_extract
node_extract -->|"fetches"| node_web
node_load_api -->|"chunks sections"| node_chunk
node_load_api -->|"precomputes"| node_embed
node_embed -.->|"requests embeddings"| node_ollama_embed
node_load_api -.->|"stores page"| node_page_cache
node_browser -.->|"browses chunks"| node_chunks_api
node_chunks_api -->|"reads page"| node_page_cache
node_browser -.->|"asks question"| node_chat_api
node_chat_api -->|"reads chunks"| node_page_cache
node_chat_api -->|"manages history"| node_conversation
node_chat_api -.->|"selects context"| node_retrieval
node_retrieval -.->|"provides chunks"| node_context
node_chat_api -->|"calls chat"| node_chat_model
node_context -.->|"supplies prompt"| node_chat_api
node_chat_api -.->|"returns answer"| node_browser
node_browser -.->|"requests stats"| node_stats_api
node_stats_api -.->|"reports cache"| node_page_cache
node_browser -.->|"clears state"| node_clear_api
node_clear_api -->|"clears pages"| node_page_cache
node_clear_api -->|"clears history"| node_conversation

click node_browser "https://github.com/harsha943vf/page_chat/blob/main/pagechat/static/index.html"
click node_load_api "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_extract "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_chunk "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_embed "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_page_cache "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_chunks_api "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_chat_api "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_retrieval "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_context "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_conversation "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_stats_api "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"
click node_clear_api "https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_load_api,node_extract,node_chunk,node_embed,node_chunks_api,node_user toneBlue
class node_chat_api,node_retrieval,node_context toneAmber
class node_page_cache,node_conversation,node_stats_api,node_clear_api toneMint
class node_browser toneRose
class node_web,node_ollama_embed,node_chat_model toneIndigo
```

## Components

### Page preparation

- [Page load API](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Page extraction](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Section chunking](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Embedding preparation](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Chunk browsing API](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`

### Question answering

- [Chat API](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Hybrid retrieval](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Context assembly](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`

### Page and session state

- [Page cache](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Conversation history](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Cache statistics API](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`
- [Cache and chat clearing](https://github.com/harsha943vf/page_chat/blob/main/pagechat/app.py): `pagechat/app.py`

### Browser interface

- [PageChat UI](https://github.com/harsha943vf/page_chat/blob/main/pagechat/static/index.html): `pagechat/static/index.html`

### Other components

- **User**
- **Web page**
- **Ollama embeddings**
- **Ollama chat model**

## Connections

- User → PageChat UI: uses
- PageChat UI → Page load API: requests page
- Page load API → Page extraction: calls (evidence: `pagechat/app.py`)
- Page extraction → Web page: fetches (evidence: `pagechat/app.py`)
- Page load API → Section chunking: chunks sections (evidence: `pagechat/app.py`)
- Page load API → Embedding preparation: precomputes (evidence: `pagechat/app.py`)
- Embedding preparation → Ollama embeddings: requests embeddings
- Page load API → Page cache: stores page (evidence: `pagechat/app.py`)
- PageChat UI → Chunk browsing API: browses chunks
- Chunk browsing API → Page cache: reads page (evidence: `pagechat/app.py`)
- PageChat UI → Chat API: asks question
- Chat API → Page cache: reads chunks (evidence: `pagechat/app.py`)
- Chat API → Conversation history: manages history (evidence: `pagechat/app.py`)
- Chat API → Hybrid retrieval: selects context (evidence: `pagechat/app.py`)
- Hybrid retrieval → Context assembly: provides chunks (evidence: `pagechat/app.py`)
- Chat API → Ollama chat model: calls chat (evidence: `pagechat/app.py`)
- Context assembly → Chat API: supplies prompt (evidence: `pagechat/app.py`)
- Chat API → PageChat UI: returns answer
- PageChat UI → Cache statistics API: requests stats
- Cache statistics API → Page cache: reports cache (evidence: `pagechat/app.py`)
- PageChat UI → Cache and chat clearing: clears state
- Cache and chat clearing → Page cache: clears pages (evidence: `pagechat/app.py`)
- Cache and chat clearing → Conversation history: clears history (evidence: `pagechat/app.py`)
