# rengha93/ai-bill-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/rengha93/ai-bill-analyzer
- Repository: https://github.com/rengha93/ai-bill-analyzer

## Overview

AI Bill Analyzer lets users upload telecom bills, then ask session-scoped questions across them. Upload processing extracts PDF text, indexes chunks for semantic retrieval, and separately extracts typed bill data for exact summaries and comparisons. Chat combines retrieved context with model-selected data tools and optional web search, then streams answers to the UI. The graph reflects the documented pipeline and sampled call sites; unsampled component internals are represented only where the tree and available references support them.

Main entry points: [`actions/embedBills.ts`](https://github.com/rengha93/ai-bill-analyzer/blob/master/actions/embedBills.ts) (Bill processing action), [`app/components/Workspace.tsx`](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/Workspace.tsx) (Workspace), [`app/api/chat/route.ts`](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts) (Chat API), [`lib/tools.ts`](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/tools.ts) (Bill data tools)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_page["Dashboard page<br/>[page.tsx]"]
  node_workspace["Workspace<br/>[Workspace.tsx]"]
  node_dropzone["Bill dropzone<br/>[DropzoneUI.tsx]"]
  node_chatui["Chat interface<br/>[ChatBarUI.tsx]"]
end

subgraph group_ingestion["Bill ingestion"]
  node_upload["Bill processing action<br/>[embedBills.ts]"]
  node_text["PDF text extraction<br/>[embedBills.ts]"]
  node_chunker["Text chunking<br/>[chunker.ts]"]
  node_embedding["Text embeddings<br/>[embedding.ts]"]
  node_schema["Bill data schema<br/>[schema.ts]"]
end

subgraph group_chat["Chat and retrieval"]
  node_chatapi["Chat API<br/>[route.ts]"]
  node_retrieval["Semantic retrieval<br/>[route.ts]"]
  node_agent["Gemini agent<br/>[route.ts]"]
  node_tools["Bill data tools<br/>[tools.ts]"]
  node_market["Market plan search<br/>[tools.ts]"]
end

subgraph group_data["Data and integrations"]
  node_pinecone[("Vector index<br/>[pinecone.ts]")]
  node_mongodb[("Bill database<br/>[mongodb.ts]")]
end

node_user(("Bill analyst"))
node_gemini["Google Gemini"]
node_tavily["Tavily search"]

node_user -->|"opens"| node_page
node_page -->|"renders"| node_workspace
node_workspace -->|"renders"| node_dropzone
node_workspace -->|"renders"| node_chatui
node_dropzone -->|"selects files"| node_workspace
node_chatui -.->|"submits questions"| node_workspace
node_workspace -->|"uploads bills"| node_upload
node_upload -->|"extracts text"| node_text
node_upload -->|"chunks text"| node_chunker
node_upload -->|"embeds chunks"| node_embedding
node_upload -->|"upserts vectors"| node_pinecone
node_upload -->|"validates extraction"| node_schema
node_upload -->|"extracts bill data"| node_gemini
node_upload -->|"stores bill records"| node_mongodb
node_workspace -->|"sends chat requests"| node_chatapi
node_chatapi -->|"retrieves context"| node_retrieval
node_retrieval -->|"embeds query"| node_embedding
node_retrieval -->|"queries vectors"| node_pinecone
node_chatapi -->|"streams response"| node_agent
node_agent -->|"generates answer"| node_gemini
node_agent -->|"dispatches tools"| node_tools
node_tools -->|"reads bill data"| node_mongodb
node_tools -->|"offers market lookup"| node_market
node_market -->|"searches plans"| node_tavily
node_chatapi -.->|"streams answers"| node_chatui

click node_page "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/page.tsx"
click node_workspace "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/Workspace.tsx"
click node_dropzone "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/DropzoneUI.tsx"
click node_chatui "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/ChatBarUI.tsx"
click node_upload "https://github.com/rengha93/ai-bill-analyzer/blob/master/actions/embedBills.ts"
click node_text "https://github.com/rengha93/ai-bill-analyzer/blob/master/actions/embedBills.ts"
click node_chunker "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/chunker.ts"
click node_embedding "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/embedding.ts"
click node_schema "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/schema.ts"
click node_pinecone "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/pinecone.ts"
click node_mongodb "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/mongodb.ts"
click node_chatapi "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts"
click node_retrieval "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts"
click node_agent "https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts"
click node_tools "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/tools.ts"
click node_market "https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/tools.ts"

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_page,node_workspace,node_dropzone,node_chatui toneBlue
class node_upload,node_text,node_chunker,node_embedding,node_schema toneAmber
class node_chatapi,node_retrieval,node_agent,node_tools,node_market toneMint
class node_pinecone,node_mongodb toneRose
class node_user,node_gemini,node_tavily toneIndigo
```

## Components

### User interface

- [Dashboard page](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/page.tsx): `app/page.tsx`
- [Workspace](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/Workspace.tsx): `app/components/Workspace.tsx`
- [Bill dropzone](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/DropzoneUI.tsx): `app/components/DropzoneUI.tsx`
- [Chat interface](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/components/ChatBarUI.tsx): `app/components/ChatBarUI.tsx`

### Bill ingestion

- [Bill processing action](https://github.com/rengha93/ai-bill-analyzer/blob/master/actions/embedBills.ts): `actions/embedBills.ts`
- [PDF text extraction](https://github.com/rengha93/ai-bill-analyzer/blob/master/actions/embedBills.ts): `actions/embedBills.ts`
- [Text chunking](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/chunker.ts): `lib/chunker.ts`
- [Text embeddings](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/embedding.ts): `lib/embedding.ts`
- [Bill data schema](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/schema.ts): `lib/schema.ts`

### Chat and retrieval

- [Chat API](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Semantic retrieval](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Gemini agent](https://github.com/rengha93/ai-bill-analyzer/blob/master/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Bill data tools](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/tools.ts): `lib/tools.ts`
- [Market plan search](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/tools.ts): `lib/tools.ts`

### Data and integrations

- [Vector index](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/pinecone.ts): `lib/pinecone.ts`
- [Bill database](https://github.com/rengha93/ai-bill-analyzer/blob/master/lib/mongodb.ts): `lib/mongodb.ts`

### Other components

- **Bill analyst**
- **Google Gemini**
- **Tavily search**

## Connections

- Bill analyst → Dashboard page: opens (evidence: `README.md`)
- Dashboard page → Workspace: renders (evidence: `app/page.tsx`)
- Workspace → Bill dropzone: renders (evidence: `app/components/Workspace.tsx`)
- Workspace → Chat interface: renders (evidence: `app/components/Workspace.tsx`)
- Bill dropzone → Workspace: selects files (evidence: `app/components/Workspace.tsx`)
- Chat interface → Workspace: submits questions (evidence: `app/components/Workspace.tsx`)
- Workspace → Bill processing action: uploads bills (evidence: `app/components/Workspace.tsx`)
- Bill processing action → PDF text extraction: extracts text (evidence: `actions/embedBills.ts`)
- Bill processing action → Text chunking: chunks text (evidence: `actions/embedBills.ts`)
- Bill processing action → Text embeddings: embeds chunks (evidence: `actions/embedBills.ts`)
- Bill processing action → Vector index: upserts vectors (evidence: `actions/embedBills.ts`)
- Bill processing action → Bill data schema: validates extraction (evidence: `actions/embedBills.ts`)
- Bill processing action → Google Gemini: extracts bill data (evidence: `actions/embedBills.ts`)
- Bill processing action → Bill database: stores bill records (evidence: `actions/embedBills.ts`)
- Workspace → Chat API: sends chat requests (evidence: `app/components/Workspace.tsx`)
- Chat API → Semantic retrieval: retrieves context (evidence: `app/api/chat/route.ts`)
- Semantic retrieval → Text embeddings: embeds query (evidence: `app/api/chat/route.ts`)
- Semantic retrieval → Vector index: queries vectors (evidence: `app/api/chat/route.ts`)
- Chat API → Gemini agent: streams response (evidence: `app/api/chat/route.ts`)
- Gemini agent → Google Gemini: generates answer (evidence: `app/api/chat/route.ts`)
- Gemini agent → Bill data tools: dispatches tools (evidence: `app/api/chat/route.ts`)
- Bill data tools → Bill database: reads bill data (evidence: `lib/tools.ts`)
- Bill data tools → Market plan search: offers market lookup (evidence: `lib/tools.ts`)
- Market plan search → Tavily search: searches plans (evidence: `lib/tools.ts`)
- Chat API → Chat interface: streams answers
