# hardikmangal-9024/benefits-chat-app architecture

> Architecture diagram of the GitHub repository hardikmangal-9024/benefits-chat-app, 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/hardikmangal-9024/benefits-chat-app
- Repository: https://github.com/hardikmangal-9024/benefits-chat-app

## Overview

BenefitLens accepts PDFs or URLs, turns them into sectioned documents, and lets users ask questions with streaming answers and citations. Its main flow runs from the landing-page upload controls through document state and an ingestion API, into cached document context used by chat. The chat interface also presents extracted benefits and supports report export; demo mode is a documented capability. Source excerpts establish the central calls, while some client-to-API wiring and demo wiring were not shown, so those links are marked unverified.

Main entry points: [`src/app/page.tsx`](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/page.tsx) (Landing page), [`src/app/chat/page.tsx`](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/chat/page.tsx) (Chat page), [`src/store/documentStore.ts`](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/store/documentStore.ts) (Document state), [`src/app/api/upload/route.ts`](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/upload/route.ts) (PDF upload API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and ingestion"]
  node_landing["Landing page<br/>[page.tsx]"]
  node_upload_controls["Upload controls<br/>[DropZone.tsx]"]
  node_document_state["Document state<br/>[documentStore.ts]"]
end

subgraph group_processing["Document processing"]
  node_pdf_ingest["PDF upload API<br/>[route.ts]"]
  node_url_ingest["URL upload API<br/>[route.ts]"]
  node_pdf_parser["PDF parser<br/>[pdf.ts]"]
  node_url_fetcher["URL processor<br/>[urlFetcher.ts]"]
  node_document_cache[("Document cache<br/>[documentCache.ts]")]
  node_document_model["Document model<br/>[types.ts]"]
  node_extract_api["Benefit extraction API<br/>[route.ts]"]
  node_benefit_logic["Benefit logic<br/>[benefits.ts]"]
  node_demo_data["Demo data<br/>[demo.ts]"]
end

subgraph group_assistant["Chat and AI"]
  node_chat_state["Chat state<br/>[chatStore.ts]"]
  node_chat_api["Streaming chat API<br/>[route.ts]"]
  node_ai_stream["AI streaming<br/>[gemini.ts]"]
end

subgraph group_presentation["Results and export"]
  node_chat_page["Chat page<br/>[page.tsx]"]
  node_chat_window["Chat window<br/>[ChatWindow.tsx]"]
  node_benefits_panel["Benefits panel<br/>[BenefitsPanel.tsx]"]
  node_message_view["Message display<br/>[MessageBubble.tsx]"]
  node_followups["Follow-up suggestions"]
  node_citation_view["Citation badge<br/>[CitationBadge.tsx]"]
  node_export_button["Export control<br/>[ExportButton.tsx]"]
  node_export_report["Report generation<br/>[exportReport.ts]"]
end

node_user(("User"))

node_user -->|"opens"| node_landing
node_landing -->|"renders"| node_upload_controls
node_landing -->|"starts upload"| node_document_state
node_upload_controls -->|"submits file or URL"| node_landing
node_document_state -.->|"posts PDF"| node_pdf_ingest
node_document_state -.->|"posts URL"| node_url_ingest
node_pdf_ingest -->|"processes PDF"| node_pdf_parser
node_pdf_ingest -->|"stores document"| node_document_cache
node_url_ingest -->|"processes URL"| node_url_fetcher
node_url_ingest -->|"stores document"| node_document_cache
node_pdf_parser -->|"produces"| node_document_model
node_url_fetcher -->|"produces"| node_document_model
node_pdf_ingest -->|"returns document"| node_document_model
node_landing -->|"navigates after upload"| node_chat_page
node_chat_page -->|"renders"| node_chat_window
node_chat_page -->|"reads document"| node_document_state
node_chat_window -->|"reads and updates"| node_chat_state
node_chat_state -->|"posts messages"| node_chat_api
node_chat_api -->|"reads document"| node_document_cache
node_chat_api -->|"streams completion"| node_ai_stream
node_chat_window -->|"renders messages"| node_message_view
node_message_view -->|"renders suggestions"| node_followups
node_message_view -->|"sends follow-up"| node_chat_state
node_chat_page -.->|"shows benefits"| node_benefits_panel
node_extract_api -->|"reads document"| node_document_cache
node_benefit_logic -->|"uses AI"| node_ai_stream
node_chat_page -->|"renders"| node_export_button
node_export_button -->|"reads messages"| node_chat_state
node_export_button -->|"reads document"| node_document_state
node_export_button -->|"generates and downloads"| node_export_report
node_demo_data -.->|"provides demo content"| node_landing

click node_landing "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/page.tsx"
click node_upload_controls "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/upload/DropZone.tsx"
click node_document_state "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/store/documentStore.ts"
click node_pdf_ingest "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/upload/route.ts"
click node_url_ingest "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/upload-url/route.ts"
click node_pdf_parser "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/pdf.ts"
click node_url_fetcher "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/urlFetcher.ts"
click node_document_cache "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/documentCache.ts"
click node_document_model "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/types.ts"
click node_extract_api "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/extract/route.ts"
click node_benefit_logic "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/benefits.ts"
click node_demo_data "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/demo.ts"
click node_chat_page "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/chat/page.tsx"
click node_chat_window "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/ChatWindow.tsx"
click node_chat_state "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/store/chatStore.ts"
click node_chat_api "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/chat/route.ts"
click node_ai_stream "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/gemini.ts"
click node_benefits_panel "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/BenefitsPanel.tsx"
click node_message_view "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/MessageBubble.tsx"
click node_followups "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/FollowUpSuggestions.tsx"
click node_citation_view "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/ui/CitationBadge.tsx"
click node_export_button "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/ExportButton.tsx"
click node_export_report "https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/exportReport.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_landing,node_upload_controls,node_document_state,node_user toneBlue
class node_pdf_ingest,node_url_ingest,node_pdf_parser,node_url_fetcher,node_document_cache,node_document_model,node_extract_api,node_benefit_logic,node_demo_data toneAmber
class node_chat_state,node_chat_api,node_ai_stream toneMint
class node_chat_page,node_chat_window,node_benefits_panel,node_message_view,node_followups,node_citation_view,node_export_button,node_export_report toneRose
```

## Components

### Entry and ingestion

- [Landing page](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Upload controls](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/upload/DropZone.tsx): `src/components/upload/DropZone.tsx`
- [Document state](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/store/documentStore.ts): `src/store/documentStore.ts`

### Document processing

- [PDF upload API](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/upload/route.ts): `src/app/api/upload/route.ts`
- [URL upload API](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/upload-url/route.ts): `src/app/api/upload-url/route.ts`
- [PDF parser](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/pdf.ts): `src/lib/pdf.ts`
- [URL processor](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/urlFetcher.ts): `src/lib/urlFetcher.ts`
- [Document cache](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/documentCache.ts): `src/lib/documentCache.ts`
- [Document model](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/types.ts): `src/lib/types.ts`
- [Benefit extraction API](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/extract/route.ts): `src/app/api/extract/route.ts`
- [Benefit logic](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/benefits.ts): `src/lib/benefits.ts`
- [Demo data](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/demo.ts): `src/lib/demo.ts`

### Chat and AI

- [Chat state](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/store/chatStore.ts): `src/store/chatStore.ts`
- [Streaming chat API](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [AI streaming](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/gemini.ts): `src/lib/gemini.ts`

### Results and export

- [Chat page](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/app/chat/page.tsx): `src/app/chat/page.tsx`
- [Chat window](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/ChatWindow.tsx): `src/components/chat/ChatWindow.tsx`
- [Benefits panel](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/BenefitsPanel.tsx): `src/components/chat/BenefitsPanel.tsx`
- [Message display](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/MessageBubble.tsx): `src/components/chat/MessageBubble.tsx`
- [Follow-up suggestions](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/FollowUpSuggestions.tsx): `src/components/chat/FollowUpSuggestions.tsx`
- [Citation badge](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/ui/CitationBadge.tsx): `src/components/ui/CitationBadge.tsx`
- [Export control](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/components/chat/ExportButton.tsx): `src/components/chat/ExportButton.tsx`
- [Report generation](https://github.com/hardikmangal-9024/benefits-chat-app/blob/main/src/lib/exportReport.ts): `src/lib/exportReport.ts`

### Other components

- **User**

## Connections

- User → Landing page: opens (evidence: `src/app/page.tsx`)
- Landing page → Upload controls: renders (evidence: `src/app/page.tsx`)
- Landing page → Document state: starts upload (evidence: `src/app/page.tsx`)
- Upload controls → Landing page: submits file or URL (evidence: `src/app/page.tsx`)
- Document state → PDF upload API: posts PDF
- Document state → URL upload API: posts URL
- PDF upload API → PDF parser: processes PDF (evidence: `src/app/api/upload/route.ts`)
- PDF upload API → Document cache: stores document (evidence: `src/app/api/upload/route.ts`)
- URL upload API → URL processor: processes URL (evidence: `src/app/api/upload-url/route.ts`)
- URL upload API → Document cache: stores document (evidence: `src/app/api/upload-url/route.ts`)
- PDF parser → Document model: produces (evidence: `src/lib/pdf.ts`)
- URL processor → Document model: produces (evidence: `src/lib/urlFetcher.ts`)
- PDF upload API → Document model: returns document (evidence: `src/app/api/upload/route.ts`)
- Landing page → Chat page: navigates after upload (evidence: `src/app/page.tsx`)
- Chat page → Chat window: renders (evidence: `src/app/chat/page.tsx`)
- Chat page → Document state: reads document (evidence: `src/app/chat/page.tsx`)
- Chat window → Chat state: reads and updates (evidence: `src/components/chat/ChatWindow.tsx`)
- Chat state → Streaming chat API: posts messages (evidence: `src/store/chatStore.ts`)
- Streaming chat API → Document cache: reads document (evidence: `src/app/api/chat/route.ts`)
- Streaming chat API → AI streaming: streams completion (evidence: `src/app/api/chat/route.ts`)
- Chat window → Message display: renders messages (evidence: `src/components/chat/ChatWindow.tsx`)
- Message display → Follow-up suggestions: renders suggestions (evidence: `src/components/chat/MessageBubble.tsx`)
- Message display → Chat state: sends follow-up (evidence: `src/components/chat/MessageBubble.tsx`)
- Chat page → Benefits panel: shows benefits
- Benefit extraction API → Document cache: reads document (evidence: `src/app/api/extract/route.ts`)
- Benefit logic → AI streaming: uses AI (evidence: `src/lib/benefits.ts`)
- Chat page → Export control: renders (evidence: `src/app/chat/page.tsx`)
- Export control → Chat state: reads messages (evidence: `src/components/chat/ExportButton.tsx`)
- Export control → Document state: reads document (evidence: `src/components/chat/ExportButton.tsx`)
- Export control → Report generation: generates and downloads (evidence: `src/components/chat/ExportButton.tsx`)
- Demo data → Landing page: provides demo content
