# vishalm342/lumenfin architecture

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

- Interactive diagram: https://gitdiagram.com/vishalm342/lumenfin
- Repository: https://github.com/vishalm342/lumenfin

## Overview

LumenFin is a secured financial-document intelligence application. Analysts upload PDFs, which are parsed, chunked, embedded, and indexed; they then ask questions, retrieve user-scoped passages, and receive streamed, cited answers. Chat history and document management support that workflow. The README documents the ingestion stages and capabilities; sampled source confirms chat retrieval, generation, persistence, and UI behavior. Some ingestion and document-management internals were not sampled, so those relationships rely on README evidence.

Main entry points: [`src/app/api/chat/route.ts`](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chat/route.ts) (Chat endpoint), [`src/lib/vectorstore.ts`](https://github.com/vishalm342/lumenfin/blob/main/src/lib/vectorstore.ts) (Hybrid retrieval), [`src/app/dashboard/page.tsx`](https://github.com/vishalm342/lumenfin/blob/main/src/app/dashboard/page.tsx) (Dashboard), [`src/components/dashboard/DocumentVault.tsx`](https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/DocumentVault.tsx) (Document vault)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product_ui["Analyst experience"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_document_vault["Document vault<br/>[DocumentVault.tsx]"]
  node_chat_ui["Analysis chat"]
  node_sidebar["Chat sidebar<br/>[Sidebar.tsx]"]
  node_auth["Authentication<br/>[middleware.ts]"]
end

subgraph group_ingestion["Document ingestion"]
  node_ingest_api["Ingestion endpoint<br/>[route.ts]"]
  node_pdf_processing["PDF processing<br/>[route.ts]"]
  node_chunk_embedding["Chunk embedding<br/>[route.ts]"]
  node_vector_index[("Vector index<br/>[vectorstore.ts]")]
end

subgraph group_rag["Grounded analysis"]
  node_chat_api["Chat endpoint<br/>[route.ts]"]
  node_retrieval["Hybrid retrieval<br/>[vectorstore.ts]"]
  node_generation["Answer generation<br/>[route.ts]"]
end

subgraph group_persistence["Application data"]
  node_chat_api_routes["Chat management API<br/>[route.ts]"]
  node_chat_detail_api["Chat detail API<br/>[route.ts]"]
  node_chat_model[("Chat records<br/>[Chat.ts]")]
  node_mongoose_db["Mongoose connection<br/>[db.ts]"]
  node_mongo_connection["MongoDB connection<br/>[mongodb.ts]"]
  node_document_api["Document listing API<br/>[route.ts]"]
  node_documents[("Document records<br/>[Document.ts]")]
end

node_analyst(("Analyst"))
node_sambanova{{"SambaNova"}}
node_gemini{{"Gemini embeddings"}}

node_analyst -->|"uses"| node_dashboard
node_dashboard -->|"presents"| node_document_vault
node_dashboard -->|"presents"| node_chat_ui
node_analyst -->|"signs in"| node_auth
node_auth -->|"protects"| node_dashboard
node_document_vault -.->|"uploads PDFs"| node_ingest_api
node_ingest_api -->|"parses PDFs"| node_pdf_processing
node_pdf_processing -->|"segments text"| node_chunk_embedding
node_chunk_embedding -->|"creates vectors"| node_gemini
node_chunk_embedding -->|"stores chunks"| node_vector_index
node_chat_ui -->|"sends questions"| node_chat_api
node_chat_api -->|"calls search"| node_retrieval
node_retrieval -->|"embeds query"| node_gemini
node_retrieval -->|"searches vectors"| node_vector_index
node_chat_api -->|"formats context"| node_generation
node_generation -->|"streams answer"| node_sambanova
node_chat_ui -->|"shows history"| node_sidebar
node_sidebar -->|"loads and manages"| node_chat_api_routes
node_chat_api_routes -->|"connects through"| node_mongoose_db
node_chat_detail_api -->|"connects through"| node_mongoose_db
node_chat_api -->|"connects through"| node_mongoose_db
node_chat_api -->|"updates messages"| node_chat_model
node_chat_api_routes -->|"manages records"| node_chat_model
node_chat_detail_api -->|"manages records"| node_chat_model
node_retrieval -->|"connects through"| node_mongo_connection
node_document_vault -.->|"manages documents"| node_document_api
node_document_api -->|"connects through"| node_mongo_connection
node_document_api -.->|"reads records"| node_documents

click node_dashboard "https://github.com/vishalm342/lumenfin/blob/main/src/app/dashboard/page.tsx"
click node_document_vault "https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/DocumentVault.tsx"
click node_chat_ui "https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/FinancialAnalysisChat.tsx"
click node_sidebar "https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/Sidebar.tsx"
click node_auth "https://github.com/vishalm342/lumenfin/blob/main/src/middleware.ts"
click node_ingest_api "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/ingest/route.ts"
click node_pdf_processing "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/ingest/route.ts"
click node_chunk_embedding "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/ingest/route.ts"
click node_vector_index "https://github.com/vishalm342/lumenfin/blob/main/src/lib/vectorstore.ts"
click node_chat_api "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chat/route.ts"
click node_retrieval "https://github.com/vishalm342/lumenfin/blob/main/src/lib/vectorstore.ts"
click node_generation "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chat/route.ts"
click node_chat_api_routes "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chats/route.ts"
click node_chat_detail_api "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chats/%5Bid%5D/route.ts"
click node_chat_model "https://github.com/vishalm342/lumenfin/blob/main/src/models/Chat.ts"
click node_mongoose_db "https://github.com/vishalm342/lumenfin/blob/main/src/lib/db.ts"
click node_mongo_connection "https://github.com/vishalm342/lumenfin/blob/main/src/lib/mongodb.ts"
click node_document_api "https://github.com/vishalm342/lumenfin/blob/main/src/app/api/documents/route.ts"
click node_documents "https://github.com/vishalm342/lumenfin/blob/main/src/models/Document.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_dashboard,node_document_vault,node_chat_ui,node_sidebar,node_auth toneBlue
class node_ingest_api,node_pdf_processing,node_chunk_embedding,node_vector_index toneAmber
class node_chat_api,node_retrieval,node_generation toneMint
class node_chat_api_routes,node_chat_detail_api,node_chat_model,node_mongoose_db,node_mongo_connection,node_document_api,node_documents toneRose
class node_analyst,node_sambanova,node_gemini toneIndigo
```

## Components

### Analyst experience

- [Dashboard](https://github.com/vishalm342/lumenfin/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Document vault](https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/DocumentVault.tsx): `src/components/dashboard/DocumentVault.tsx`
- [Analysis chat](https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/FinancialAnalysisChat.tsx): `src/components/dashboard/FinancialAnalysisChat.tsx`
- [Chat sidebar](https://github.com/vishalm342/lumenfin/blob/main/src/components/dashboard/Sidebar.tsx): `src/components/dashboard/Sidebar.tsx`
- [Authentication](https://github.com/vishalm342/lumenfin/blob/main/src/middleware.ts): `src/middleware.ts`

### Document ingestion

- [Ingestion endpoint](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/ingest/route.ts): `src/app/api/ingest/route.ts`
- [PDF processing](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/ingest/route.ts): `src/app/api/ingest/route.ts`
- [Chunk embedding](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/ingest/route.ts): `src/app/api/ingest/route.ts`
- [Vector index](https://github.com/vishalm342/lumenfin/blob/main/src/lib/vectorstore.ts): `src/lib/vectorstore.ts`

### Grounded analysis

- [Chat endpoint](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`
- [Hybrid retrieval](https://github.com/vishalm342/lumenfin/blob/main/src/lib/vectorstore.ts): `src/lib/vectorstore.ts`
- [Answer generation](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chat/route.ts): `src/app/api/chat/route.ts`

### Application data

- [Chat management API](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chats/route.ts): `src/app/api/chats/route.ts`
- [Chat detail API](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/chats/%5Bid%5D/route.ts): `src/app/api/chats/[id]/route.ts`
- [Chat records](https://github.com/vishalm342/lumenfin/blob/main/src/models/Chat.ts): `src/models/Chat.ts`
- [Mongoose connection](https://github.com/vishalm342/lumenfin/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [MongoDB connection](https://github.com/vishalm342/lumenfin/blob/main/src/lib/mongodb.ts): `src/lib/mongodb.ts`
- [Document listing API](https://github.com/vishalm342/lumenfin/blob/main/src/app/api/documents/route.ts): `src/app/api/documents/route.ts`
- [Document records](https://github.com/vishalm342/lumenfin/blob/main/src/models/Document.ts): `src/models/Document.ts`

### Other components

- **Analyst**
- **SambaNova**
- **Gemini embeddings**

## Connections

- Analyst → Dashboard: uses (evidence: `README.md`)
- Dashboard → Document vault: presents (evidence: `src/app/dashboard/page.tsx`)
- Dashboard → Analysis chat: presents (evidence: `src/app/dashboard/page.tsx`)
- Analyst → Authentication: signs in (evidence: `README.md`)
- Authentication → Dashboard: protects (evidence: `README.md`)
- Document vault → Ingestion endpoint: uploads PDFs
- Ingestion endpoint → PDF processing: parses PDFs (evidence: `README.md`)
- PDF processing → Chunk embedding: segments text (evidence: `README.md`)
- Chunk embedding → Gemini embeddings: creates vectors (evidence: `README.md`)
- Chunk embedding → Vector index: stores chunks (evidence: `README.md`)
- Analysis chat → Chat endpoint: sends questions (evidence: `README.md`)
- Chat endpoint → Hybrid retrieval: calls search (evidence: `src/app/api/chat/route.ts`)
- Hybrid retrieval → Gemini embeddings: embeds query (evidence: `src/lib/vectorstore.ts`)
- Hybrid retrieval → Vector index: searches vectors (evidence: `src/lib/vectorstore.ts`)
- Chat endpoint → Answer generation: formats context (evidence: `src/app/api/chat/route.ts`)
- Answer generation → SambaNova: streams answer (evidence: `src/app/api/chat/route.ts`)
- Analysis chat → Chat sidebar: shows history (evidence: `src/components/dashboard/FinancialAnalysisChat.tsx`)
- Chat sidebar → Chat management API: loads and manages (evidence: `src/components/dashboard/Sidebar.tsx`)
- Chat management API → Mongoose connection: connects through (evidence: `src/app/api/chats/route.ts`)
- Chat detail API → Mongoose connection: connects through (evidence: `src/app/api/chats/[id]/route.ts`)
- Chat endpoint → Mongoose connection: connects through (evidence: `src/app/api/chat/route.ts`)
- Chat endpoint → Chat records: updates messages (evidence: `src/app/api/chat/route.ts`)
- Chat management API → Chat records: manages records (evidence: `src/app/api/chats/route.ts`)
- Chat detail API → Chat records: manages records (evidence: `src/app/api/chats/[id]/route.ts`)
- Hybrid retrieval → MongoDB connection: connects through (evidence: `src/lib/vectorstore.ts`)
- Document vault → Document listing API: manages documents
- Document listing API → MongoDB connection: connects through (evidence: `src/app/api/documents/route.ts`)
- Document listing API → Document records: reads records
