# darkm0nk/loanlens architecture

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

- Interactive diagram: https://gitdiagram.com/darkm0nk/loanlens
- Repository: https://github.com/darkm0nk/loanlens

## Overview

LoanLens helps Indian borrowers audit KFS, sanction letters, and loan agreements before signing. The main workflow is document intake and validation, server-side extraction, deterministic term comparison and regulatory review, then evidence review and lender clarification. The graph also includes demo scenarios, financial and unit calculations, and RBI guidance. Edges are limited to relationships shown in excerpts, the SOURCE INDEX, or README; some UI-to-server wiring is not shown in the sampled source.

Main entry points: [`src/App.tsx`](https://github.com/darkm0nk/loanlens/blob/main/src/App.tsx) (Workspace App), [`src/utils/comparator.ts`](https://github.com/darkm0nk/loanlens/blob/main/src/utils/comparator.ts) (Term Comparator), [`server.ts`](https://github.com/darkm0nk/loanlens/blob/main/server.ts) (Document Extraction API), [`src/components/ComparisonDashboard.tsx`](https://github.com/darkm0nk/loanlens/blob/main/src/components/ComparisonDashboard.tsx) (Comparison Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Document Intake"]
  node_app["Workspace App<br/>[App.tsx]"]
  node_upload["Document Upload"]
  node_extract["Document Extraction API<br/>[server.ts]"]
  node_validator["File and Text Validation"]
  node_demo["Demo Scenarios<br/>[demoData.ts]"]
end

subgraph group_analysis["Audit Analysis"]
  node_loanmodel["Loan Document Model<br/>[loan.ts]"]
  node_comparator["Term Comparator<br/>[comparator.ts]"]
  node_financial["Financial Impact Math<br/>[financialMath.ts]"]
  node_units["Unit Reconciliation<br/>[unitConverter.ts]"]
end

subgraph group_review["Borrower Review"]
  node_dashboard["Comparison Dashboard"]
  node_termcard["Term Comparison Card"]
  node_evidence["Side-by-Side Evidence"]
  node_viewer["Document Viewer"]
  node_layout["Dashboard Layout"]
  node_hero["Product Introduction<br/>[HeroBanner.tsx]"]
end

subgraph group_guidance["Guidance and Follow-up"]
  node_rules["Regulatory Rules<br/>[regulatoryRules.ts]"]
  node_rights["RBI Rights View<br/>[RbiRightsModal.tsx]"]
  node_letterui["Clarification Letter UI"]
  node_letterapi["Letter Generation API<br/>[server.ts]"]
end

node_borrower(("Borrower"))
node_gemini{{"Google Gemini"}}

node_borrower -->|"uses"| node_app
node_app -->|"renders"| node_upload
node_app -->|"renders"| node_dashboard
node_app -->|"renders"| node_layout
node_app -->|"renders"| node_hero
node_app -->|"opens"| node_letterui
node_app -->|"opens"| node_rights
node_app -->|"loads"| node_demo
node_upload -.->|"submits documents"| node_extract
node_extract -->|"validates"| node_validator
node_extract -->|"extracts with"| node_gemini
node_app -->|"compares documents"| node_comparator
node_comparator -->|"calculates impact"| node_financial
node_comparator -->|"normalizes units"| node_units
node_comparator -->|"checks guidance"| node_rules
node_app -->|"tracks documents"| node_loanmodel
node_dashboard -->|"renders terms"| node_termcard
node_dashboard -->|"opens evidence"| node_evidence
node_app -->|"opens document"| node_viewer
node_rights -->|"displays rules"| node_rules
node_letterui -.->|"requests draft"| node_letterapi
node_letterapi -->|"returns letter"| node_borrower

click node_app "https://github.com/darkm0nk/loanlens/blob/main/src/App.tsx"
click node_upload "https://github.com/darkm0nk/loanlens/blob/main/src/components/DocumentUploadCard.tsx"
click node_extract "https://github.com/darkm0nk/loanlens/blob/main/server.ts"
click node_validator "https://github.com/darkm0nk/loanlens/blob/main/src/utils/documentValidator.ts"
click node_loanmodel "https://github.com/darkm0nk/loanlens/blob/main/src/types/loan.ts"
click node_comparator "https://github.com/darkm0nk/loanlens/blob/main/src/utils/comparator.ts"
click node_financial "https://github.com/darkm0nk/loanlens/blob/main/src/utils/financialMath.ts"
click node_units "https://github.com/darkm0nk/loanlens/blob/main/src/utils/unitConverter.ts"
click node_rules "https://github.com/darkm0nk/loanlens/blob/main/src/utils/regulatoryRules.ts"
click node_demo "https://github.com/darkm0nk/loanlens/blob/main/src/data/demoData.ts"
click node_dashboard "https://github.com/darkm0nk/loanlens/blob/main/src/components/ComparisonDashboard.tsx"
click node_termcard "https://github.com/darkm0nk/loanlens/blob/main/src/components/TermComparisonCard.tsx"
click node_evidence "https://github.com/darkm0nk/loanlens/blob/main/src/components/SideBySideEvidenceModal.tsx"
click node_viewer "https://github.com/darkm0nk/loanlens/blob/main/src/components/DocumentViewerModal.tsx"
click node_layout "https://github.com/darkm0nk/loanlens/blob/main/src/components/DashboardLayout.tsx"
click node_hero "https://github.com/darkm0nk/loanlens/blob/main/src/components/HeroBanner.tsx"
click node_rights "https://github.com/darkm0nk/loanlens/blob/main/src/components/RbiRightsModal.tsx"
click node_letterui "https://github.com/darkm0nk/loanlens/blob/main/src/components/LenderDisputeModal.tsx"
click node_letterapi "https://github.com/darkm0nk/loanlens/blob/main/server.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_app,node_upload,node_extract,node_validator,node_demo toneBlue
class node_loanmodel,node_comparator,node_financial,node_units toneAmber
class node_dashboard,node_termcard,node_evidence,node_viewer,node_layout,node_hero toneMint
class node_rules,node_rights,node_letterui,node_letterapi toneRose
class node_borrower,node_gemini toneIndigo
```

## Components

### Document Intake

- [Workspace App](https://github.com/darkm0nk/loanlens/blob/main/src/App.tsx): `src/App.tsx`
- [Document Upload](https://github.com/darkm0nk/loanlens/blob/main/src/components/DocumentUploadCard.tsx): `src/components/DocumentUploadCard.tsx`
- [Document Extraction API](https://github.com/darkm0nk/loanlens/blob/main/server.ts): `server.ts`
- [File and Text Validation](https://github.com/darkm0nk/loanlens/blob/main/src/utils/documentValidator.ts): `src/utils/documentValidator.ts`
- [Demo Scenarios](https://github.com/darkm0nk/loanlens/blob/main/src/data/demoData.ts): `src/data/demoData.ts`

### Audit Analysis

- [Loan Document Model](https://github.com/darkm0nk/loanlens/blob/main/src/types/loan.ts): `src/types/loan.ts`
- [Term Comparator](https://github.com/darkm0nk/loanlens/blob/main/src/utils/comparator.ts): `src/utils/comparator.ts`
- [Financial Impact Math](https://github.com/darkm0nk/loanlens/blob/main/src/utils/financialMath.ts): `src/utils/financialMath.ts`
- [Unit Reconciliation](https://github.com/darkm0nk/loanlens/blob/main/src/utils/unitConverter.ts): `src/utils/unitConverter.ts`

### Borrower Review

- [Comparison Dashboard](https://github.com/darkm0nk/loanlens/blob/main/src/components/ComparisonDashboard.tsx): `src/components/ComparisonDashboard.tsx`
- [Term Comparison Card](https://github.com/darkm0nk/loanlens/blob/main/src/components/TermComparisonCard.tsx): `src/components/TermComparisonCard.tsx`
- [Side-by-Side Evidence](https://github.com/darkm0nk/loanlens/blob/main/src/components/SideBySideEvidenceModal.tsx): `src/components/SideBySideEvidenceModal.tsx`
- [Document Viewer](https://github.com/darkm0nk/loanlens/blob/main/src/components/DocumentViewerModal.tsx): `src/components/DocumentViewerModal.tsx`
- [Dashboard Layout](https://github.com/darkm0nk/loanlens/blob/main/src/components/DashboardLayout.tsx): `src/components/DashboardLayout.tsx`
- [Product Introduction](https://github.com/darkm0nk/loanlens/blob/main/src/components/HeroBanner.tsx): `src/components/HeroBanner.tsx`

### Guidance and Follow-up

- [Regulatory Rules](https://github.com/darkm0nk/loanlens/blob/main/src/utils/regulatoryRules.ts): `src/utils/regulatoryRules.ts`
- [RBI Rights View](https://github.com/darkm0nk/loanlens/blob/main/src/components/RbiRightsModal.tsx): `src/components/RbiRightsModal.tsx`
- [Clarification Letter UI](https://github.com/darkm0nk/loanlens/blob/main/src/components/LenderDisputeModal.tsx): `src/components/LenderDisputeModal.tsx`
- [Letter Generation API](https://github.com/darkm0nk/loanlens/blob/main/server.ts): `server.ts`

### Other components

- **Borrower**
- **Google Gemini**

## Connections

- Borrower → Workspace App: uses (evidence: `README.md`)
- Workspace App → Document Upload: renders (evidence: `src/App.tsx`)
- Workspace App → Comparison Dashboard: renders (evidence: `src/App.tsx`)
- Workspace App → Dashboard Layout: renders (evidence: `src/App.tsx`)
- Workspace App → Product Introduction: renders (evidence: `src/App.tsx`)
- Workspace App → Clarification Letter UI: opens (evidence: `src/App.tsx`)
- Workspace App → RBI Rights View: opens (evidence: `src/App.tsx`)
- Workspace App → Demo Scenarios: loads (evidence: `src/App.tsx`)
- Document Upload → Document Extraction API: submits documents
- Document Extraction API → File and Text Validation: validates (evidence: `server.ts`)
- Document Extraction API → Google Gemini: extracts with (evidence: `README.md`)
- Workspace App → Term Comparator: compares documents (evidence: `src/App.tsx`)
- Term Comparator → Financial Impact Math: calculates impact (evidence: `src/utils/comparator.ts`)
- Term Comparator → Unit Reconciliation: normalizes units (evidence: `src/utils/comparator.ts`)
- Term Comparator → Regulatory Rules: checks guidance (evidence: `src/utils/comparator.ts`)
- Workspace App → Loan Document Model: tracks documents (evidence: `src/App.tsx`)
- Comparison Dashboard → Term Comparison Card: renders terms (evidence: `src/components/ComparisonDashboard.tsx`)
- Comparison Dashboard → Side-by-Side Evidence: opens evidence (evidence: `src/components/ComparisonDashboard.tsx`)
- Workspace App → Document Viewer: opens document (evidence: `src/App.tsx`)
- RBI Rights View → Regulatory Rules: displays rules (evidence: `src/components/RbiRightsModal.tsx`)
- Clarification Letter UI → Letter Generation API: requests draft
- Letter Generation API → Borrower: returns letter (evidence: `README.md`)
