# atharvadchaudhari05/coverindex-ai architecture

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

- Interactive diagram: https://gitdiagram.com/atharvadchaudhari05/coverindex-ai
- Repository: https://github.com/atharvadchaudhari05/coverindex-ai

## Overview

CoverIndex AI is an insurance-policy question-answering and recommendation app. Users ask questions or upload a PDF; the backend routes the query, retrieves relevant indexed pages, generates a cited response, and can offer a confirmed live-web fallback when document evidence is insufficient. The frontend also supports local chat history and conversation search. The README documents the advisor and fallback capabilities; source excerpts show the API, ingestion, retrieval, and generation components, but do not expose every internal handoff, so undocumented links are omitted.

Main entry points: [`policy_rag/server.py`](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/server.py) (HTTP API), [`policy_rag/agent.py`](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py) (Answer generation), [`policy_rag/ingest.py`](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/ingest.py) (PDF ingestion), [`public/app.js`](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/public/app.js) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User experience"]
  node_webapp["Chat interface<br/>[app.js]"]
  node_edge["Edge gateway<br/>[worker.js]"]
end

subgraph group_backend["Query and advice"]
  node_server["HTTP API<br/>[server.py]"]
  node_router["Query routing<br/>[agent.py]"]
  node_advisor["Answer generation<br/>[agent.py]"]
  node_prompts["AI instructions"]
  node_citations["Citations and sources<br/>[agent.py]"]
  node_fallback["Web fallback<br/>[agent.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_documents["Policy knowledge"]
  node_upload["PDF ingestion<br/>[ingest.py]"]
  node_pdfs["Policy PDFs"]
  node_pageindex["Page search index<br/>[index.py]"]
  node_cache[("Index cache")]
  node_records["Page records<br/>[models.py]"]
end

subgraph group_integrations["External services"]
  node_search["DuckDuckGo search<br/>[utils.py]"]
  node_llm["Language models"]
end

node_user(("Policy seeker"))

node_user -->|"asks or uploads"| node_webapp
node_webapp -.->|"sends API requests"| node_edge
node_webapp -->|"posts uploads"| node_server
node_edge -->|"proxies API"| node_server
node_server -->|"routes query"| node_router
node_server -->|"requests answer"| node_advisor
node_server -->|"processes upload"| node_upload
node_pdfs -->|"provides documents"| node_upload
node_upload -->|"extracts pages"| node_records
node_upload -->|"loads and saves"| node_cache
node_pageindex -->|"builds page index"| node_upload
node_pageindex -->|"searches pages"| node_records
node_advisor -->|"retrieves context"| node_pageindex
node_advisor -->|"generates response"| node_llm
node_advisor -->|"loads instructions"| node_prompts
node_advisor -->|"formats sources"| node_citations
node_server -->|"awaits confirmation"| node_fallback
node_fallback -->|"searches web"| node_search
node_fallback -.->|"writes sourced answer"| node_llm
node_config -->|"loads prompt files"| node_prompts

click node_webapp "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/public/app.js"
click node_edge "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/worker.js"
click node_server "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/server.py"
click node_router "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py"
click node_advisor "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py"
click node_prompts "https://github.com/atharvadchaudhari05/coverindex-ai/tree/main/prompts"
click node_citations "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py"
click node_fallback "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py"
click node_search "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/utils.py"
click node_upload "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/ingest.py"
click node_pdfs "https://github.com/atharvadchaudhari05/coverindex-ai/tree/main/Policy%20Documents"
click node_pageindex "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/index.py"
click node_cache "https://github.com/atharvadchaudhari05/coverindex-ai/tree/main/cache"
click node_records "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/models.py"
click node_config "https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/config.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_webapp,node_edge toneBlue
class node_server,node_router,node_advisor,node_prompts,node_citations,node_fallback,node_config toneAmber
class node_upload,node_pdfs,node_pageindex,node_cache,node_records toneMint
class node_search,node_llm toneRose
class node_user toneIndigo
```

## Components

### User experience

- [Chat interface](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/public/app.js): `public/app.js`
- [Edge gateway](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/worker.js): `worker.js`

### Query and advice

- [HTTP API](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/server.py): `policy_rag/server.py`
- [Query routing](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py): `policy_rag/agent.py`
- [Answer generation](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py): `policy_rag/agent.py`
- [AI instructions](https://github.com/atharvadchaudhari05/coverindex-ai/tree/main/prompts): `prompts`
- [Citations and sources](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py): `policy_rag/agent.py`
- [Web fallback](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/agent.py): `policy_rag/agent.py`
- [Runtime configuration](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/config.py): `policy_rag/config.py`

### Policy knowledge

- [PDF ingestion](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/ingest.py): `policy_rag/ingest.py`
- [Policy PDFs](https://github.com/atharvadchaudhari05/coverindex-ai/tree/main/Policy%20Documents): `Policy Documents`
- [Page search index](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/index.py): `policy_rag/index.py`
- [Index cache](https://github.com/atharvadchaudhari05/coverindex-ai/tree/main/cache): `cache`
- [Page records](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/models.py): `policy_rag/models.py`

### External services

- [DuckDuckGo search](https://github.com/atharvadchaudhari05/coverindex-ai/blob/main/policy_rag/utils.py): `policy_rag/utils.py`
- **Language models**

### Other components

- **Policy seeker**

## Connections

- Policy seeker → Chat interface: asks or uploads (evidence: `README.md`)
- Chat interface → Edge gateway: sends API requests
- Chat interface → HTTP API: posts uploads (evidence: `public/app.js`)
- Edge gateway → HTTP API: proxies API (evidence: `worker.js`)
- HTTP API → Query routing: routes query (evidence: `policy_rag/server.py`)
- HTTP API → Answer generation: requests answer (evidence: `policy_rag/server.py`)
- HTTP API → PDF ingestion: processes upload (evidence: `policy_rag/server.py`)
- Policy PDFs → PDF ingestion: provides documents (evidence: `README.md`)
- PDF ingestion → Page records: extracts pages (evidence: `policy_rag/ingest.py`)
- PDF ingestion → Index cache: loads and saves (evidence: `policy_rag/ingest.py`)
- Page search index → PDF ingestion: builds page index (evidence: `policy_rag/index.py`)
- Page search index → Page records: searches pages (evidence: `policy_rag/index.py`)
- Answer generation → Page search index: retrieves context (evidence: `policy_rag/agent.py`)
- Answer generation → Language models: generates response (evidence: `policy_rag/agent.py`)
- Answer generation → AI instructions: loads instructions
- Answer generation → Citations and sources: formats sources (evidence: `policy_rag/agent.py`)
- HTTP API → Web fallback: awaits confirmation (evidence: `policy_rag/server.py`)
- Web fallback → DuckDuckGo search: searches web (evidence: `README.md`)
- Web fallback → Language models: writes sourced answer
- Runtime configuration → AI instructions: loads prompt files (evidence: `policy_rag/config.py`)
