# prasanthkumarkb/ledgerlens architecture

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

- Interactive diagram: https://gitdiagram.com/prasanthkumarkb/ledgerlens
- Repository: https://github.com/prasanthkumarkb/ledgerlens

## Overview

InvoicePilot (LedgerLens) is a Streamlit invoice-management UI backed by a FastAPI service. Users upload invoice images, which the service stores as documents; extraction and watermarking populate processed invoice data for browsing, dashboard reporting, and manual review. The README describes processing as automatic after upload, while the sampled route code exposes extraction as a separate endpoint, so that distinction is retained. Source excerpts support the backend orchestration and review calls; several other UI-to-API details are documented only at the feature level.

Main entry points: [`backend/api/routes.py`](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/api/routes.py) (REST endpoints), [`backend/app.py`](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/app.py) (FastAPI setup), [`frontend/app.py`](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/app.py) (Page navigation), [`frontend/components/loader.py`](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/components/loader.py) (Loading indicator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Streamlit UI"]
  node_ui_app["Page navigation<br/>[app.py]"]
  node_upload_ui["Invoice upload<br/>[upload.py]"]
  node_documents_ui["Document browser<br/>[documents.py]"]
  node_review_ui["Manual review<br/>[review.py]"]
  node_dashboard_ui["Dashboard views<br/>[dashboard.py]"]
  node_loader["Loading indicator<br/>[loader.py]"]
  node_styles["UI styling<br/>[styles.py]"]
end

subgraph group_api["API workflows"]
  node_routes["REST endpoints<br/>[routes.py]"]
  node_schemas["Invoice schemas<br/>[invoice.py]"]
end

subgraph group_processing["Invoice processing"]
  node_vision["AI extraction<br/>[vision.py]"]
  node_watermark["Image watermarking<br/>[watermark.py]"]
end

subgraph group_storage["Document storage"]
  node_document_model["Document records<br/>[document.py]"]
  node_database[("SQLite database<br/>[database.py]")]
  node_uploads["Uploaded images"]
  node_processed["Processed images"]
end

subgraph group_platform["API platform"]
  node_app["FastAPI setup<br/>[app.py]"]
  node_handlers["Exception handlers<br/>[handlers.py]"]
  node_exceptions["Domain exceptions<br/>[exceptions.py]"]
  node_middleware["Request logging<br/>[middleware.py]"]
  node_logger["Application logger<br/>[logger.py]"]
end

node_user(("Invoice user"))

node_user -->|"uses"| node_ui_app
node_ui_app -->|"dispatches"| node_upload_ui
node_ui_app -->|"dispatches"| node_documents_ui
node_ui_app -->|"dispatches"| node_review_ui
node_ui_app -->|"dispatches"| node_dashboard_ui
node_ui_app -->|"loads"| node_styles
node_upload_ui -->|"uploads to"| node_routes
node_documents_ui -->|"lists from"| node_routes
node_review_ui -->|"reads and updates"| node_routes
node_dashboard_ui -->|"requests metrics"| node_routes
node_review_ui -->|"shows"| node_loader
node_dashboard_ui -->|"uses"| node_loader
node_upload_ui -->|"uses"| node_loader
node_documents_ui -->|"uses"| node_loader
node_routes -->|"queries and commits"| node_database
node_routes -->|"creates and updates"| node_document_model
node_routes -->|"validates responses"| node_schemas
node_routes -->|"extracts fields"| node_vision
node_routes -->|"generates watermark"| node_watermark
node_routes -->|"saves image"| node_uploads
node_routes -->|"records image path"| node_processed
node_document_model -->|"uses base"| node_database
node_app -->|"registers"| node_routes
node_app -->|"creates tables"| node_database
node_app -->|"registers handlers"| node_handlers
node_app -->|"handles type"| node_exceptions
node_app -->|"adds"| node_middleware
node_app -->|"logs startup"| node_logger
node_handlers -->|"formats errors"| node_exceptions
node_middleware -->|"uses"| node_logger
node_vision -->|"logs extraction"| node_logger

click node_ui_app "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/app.py"
click node_upload_ui "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/upload.py"
click node_documents_ui "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/documents.py"
click node_review_ui "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/review.py"
click node_dashboard_ui "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/dashboard.py"
click node_loader "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/components/loader.py"
click node_styles "https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/styles.py"
click node_routes "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/api/routes.py"
click node_schemas "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/schemas/invoice.py"
click node_vision "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/services/vision.py"
click node_watermark "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/services/watermark.py"
click node_document_model "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/models/document.py"
click node_database "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/database/database.py"
click node_uploads "https://github.com/prasanthkumarkb/ledgerlens/tree/main/backend/uploads"
click node_processed "https://github.com/prasanthkumarkb/ledgerlens/tree/main/backend/processed"
click node_app "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/app.py"
click node_handlers "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/handlers.py"
click node_exceptions "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/exceptions.py"
click node_middleware "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/middleware.py"
click node_logger "https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/logger.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_ui_app,node_upload_ui,node_documents_ui,node_review_ui,node_dashboard_ui,node_loader,node_styles,node_user toneBlue
class node_routes,node_schemas toneAmber
class node_vision,node_watermark toneMint
class node_document_model,node_database,node_uploads,node_processed toneRose
class node_app,node_handlers,node_exceptions,node_middleware,node_logger toneIndigo
```

## Components

### Streamlit UI

- [Page navigation](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/app.py): `frontend/app.py`
- [Invoice upload](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/upload.py): `frontend/upload.py`
- [Document browser](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/documents.py): `frontend/documents.py`
- [Manual review](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/review.py): `frontend/review.py`
- [Dashboard views](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/dashboard.py): `frontend/dashboard.py`
- [Loading indicator](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/components/loader.py): `frontend/components/loader.py`
- [UI styling](https://github.com/prasanthkumarkb/ledgerlens/blob/main/frontend/styles.py): `frontend/styles.py`

### API workflows

- [REST endpoints](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/api/routes.py): `backend/api/routes.py`
- [Invoice schemas](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/schemas/invoice.py): `backend/schemas/invoice.py`

### Invoice processing

- [AI extraction](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/services/vision.py): `backend/services/vision.py`
- [Image watermarking](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/services/watermark.py): `backend/services/watermark.py`

### Document storage

- [Document records](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/models/document.py): `backend/models/document.py`
- [SQLite database](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/database/database.py): `backend/database/database.py`
- [Uploaded images](https://github.com/prasanthkumarkb/ledgerlens/tree/main/backend/uploads): `backend/uploads`
- [Processed images](https://github.com/prasanthkumarkb/ledgerlens/tree/main/backend/processed): `backend/processed`

### API platform

- [FastAPI setup](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/app.py): `backend/app.py`
- [Exception handlers](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/handlers.py): `backend/core/handlers.py`
- [Domain exceptions](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/exceptions.py): `backend/core/exceptions.py`
- [Request logging](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/middleware.py): `backend/core/middleware.py`
- [Application logger](https://github.com/prasanthkumarkb/ledgerlens/blob/main/backend/core/logger.py): `backend/core/logger.py`

### Other components

- **Invoice user**

## Connections

- Invoice user → Page navigation: uses (evidence: `README.md`)
- Page navigation → Invoice upload: dispatches (evidence: `frontend/app.py`)
- Page navigation → Document browser: dispatches (evidence: `frontend/app.py`)
- Page navigation → Manual review: dispatches (evidence: `frontend/app.py`)
- Page navigation → Dashboard views: dispatches (evidence: `frontend/app.py`)
- Page navigation → UI styling: loads (evidence: `frontend/app.py`)
- Invoice upload → REST endpoints: uploads to (evidence: `README.md`)
- Document browser → REST endpoints: lists from (evidence: `README.md`)
- Manual review → REST endpoints: reads and updates (evidence: `frontend/review.py`)
- Dashboard views → REST endpoints: requests metrics (evidence: `README.md`)
- Manual review → Loading indicator: shows (evidence: `frontend/review.py`)
- Dashboard views → Loading indicator: uses (evidence: `frontend/dashboard.py`)
- Invoice upload → Loading indicator: uses (evidence: `frontend/upload.py`)
- Document browser → Loading indicator: uses (evidence: `frontend/documents.py`)
- REST endpoints → SQLite database: queries and commits (evidence: `backend/api/routes.py`)
- REST endpoints → Document records: creates and updates (evidence: `backend/api/routes.py`)
- REST endpoints → Invoice schemas: validates responses (evidence: `backend/api/routes.py`)
- REST endpoints → AI extraction: extracts fields (evidence: `backend/api/routes.py`)
- REST endpoints → Image watermarking: generates watermark (evidence: `backend/api/routes.py`)
- REST endpoints → Uploaded images: saves image (evidence: `backend/api/routes.py`)
- REST endpoints → Processed images: records image path (evidence: `backend/api/routes.py`)
- Document records → SQLite database: uses base (evidence: `backend/models/document.py`)
- FastAPI setup → REST endpoints: registers (evidence: `backend/app.py`)
- FastAPI setup → SQLite database: creates tables (evidence: `backend/app.py`)
- FastAPI setup → Exception handlers: registers handlers (evidence: `backend/app.py`)
- FastAPI setup → Domain exceptions: handles type (evidence: `backend/app.py`)
- FastAPI setup → Request logging: adds (evidence: `backend/app.py`)
- FastAPI setup → Application logger: logs startup (evidence: `backend/app.py`)
- Exception handlers → Domain exceptions: formats errors (evidence: `backend/core/handlers.py`)
- Request logging → Application logger: uses (evidence: `backend/core/middleware.py`)
- AI extraction → Application logger: logs extraction (evidence: `backend/services/vision.py`)
