# rishi-is-cool/leaselens-india architecture

> Architecture diagram of the GitHub repository rishi-is-cool/leaselens-india, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rishi-is-cool/leaselens-india
- Repository: https://github.com/rishi-is-cool/leaselens-india

## Overview

LeaseLens accepts lease files and currently returns extracted, segmented clauses; the sampled frontend identifies itself as a Phase 1 segmentation check. The backend also contains a document-explanation pipeline for risk labels, jurisdiction/topic-scoped statute retrieval, grounded explanations, and cross-clause connections. The README describes Postgres-backed document and statute storage. The graph follows calls visible in sampled source and documented capabilities; unsampled frontend API wiring and analysis internals are represented only where their paths and responsibilities are supported.

Main entry points: [`backend/app/routers/documents.py`](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/routers/documents.py) (Document endpoints), [`backend/app/explain/pipeline.py`](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/pipeline.py) (Explanation orchestration), [`frontend/src/App.tsx`](https://github.com/rishi-is-cool/leaselens-india/blob/master/frontend/src/App.tsx) (Upload and results UI), [`backend/app/classifier/api.py`](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/api.py) (Risk classification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["LeaseLens frontend"]
  node_app_ui["Upload and results UI<br/>[App.tsx]"]
  node_api_client["Frontend API client<br/>[api.ts]"]
end

subgraph group_api_ingestion["API and ingestion"]
  node_fastapi["API application<br/>[main.py]"]
  node_documents["Document endpoints<br/>[documents.py]"]
  node_extract["Text extraction<br/>[extract.py]"]
  node_segment["Clause segmentation<br/>[segment.py]"]
  node_retention["Upload retention<br/>[retention.py]"]
end

subgraph group_analysis["Clause analysis"]
  node_explain_pipeline["Explanation orchestration<br/>[pipeline.py]"]
  node_classifier["Risk classification<br/>[api.py]"]
  node_trained_classifier["Trained fallback<br/>[trained.py]"]
  node_llm_classifier["LLM classifier<br/>[llm.py]"]
  node_topic_tags["Topic tagging<br/>[topics.py]"]
  node_statute_retrieval["Statute retrieval<br/>[retrieval.py]"]
  node_explanation["Explanation generation<br/>[generate.py]"]
  node_grounding["Citation grounding<br/>[grounding.py]"]
  node_cross_clause["Cross-clause analysis<br/>[cross_clause.py]"]
  node_shared_llm["Shared LLM client<br/>[llm_client.py]"]
end

subgraph group_persistence["Persistence and providers"]
  node_db_access["Database access<br/>[db.py]"]
  node_models["Document and clause models<br/>[models.py]"]
  node_postgres[("Postgres")]
end

node_tenant(("Lease uploader"))
node_llm_provider(("LLM provider"))

node_tenant -->|"uploads lease"| node_app_ui
node_app_ui -->|"sends file"| node_api_client
node_api_client -->|"calls upload API"| node_documents
node_fastapi -->|"registers routes"| node_documents
node_documents -->|"purges expired"| node_retention
node_documents -->|"extracts text"| node_extract
node_documents -->|"segments paragraphs"| node_segment
node_documents -->|"opens session"| node_db_access
node_documents -->|"creates records"| node_models
node_db_access -->|"reads and writes"| node_postgres
node_app_ui -->|"checks health"| node_api_client
node_explain_pipeline -->|"classifies clauses"| node_classifier
node_explain_pipeline -->|"tags topics"| node_topic_tags
node_explain_pipeline -->|"retrieves statutes"| node_statute_retrieval
node_explain_pipeline -->|"generates explanations"| node_explanation
node_explain_pipeline -->|"checks grounding"| node_grounding
node_explain_pipeline -->|"checks clause pairs"| node_cross_clause
node_classifier -.->|"uses fallback"| node_trained_classifier
node_classifier -.->|"uses LLM"| node_llm_classifier
node_explanation -->|"requests completion"| node_shared_llm
node_cross_clause -->|"requests completion"| node_shared_llm
node_shared_llm -->|"sends chat request"| node_llm_provider
node_llm_classifier -->|"sends chat request"| node_llm_provider

click node_app_ui "https://github.com/rishi-is-cool/leaselens-india/blob/master/frontend/src/App.tsx"
click node_api_client "https://github.com/rishi-is-cool/leaselens-india/blob/master/frontend/src/api.ts"
click node_fastapi "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/main.py"
click node_documents "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/routers/documents.py"
click node_extract "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/ingestion/extract.py"
click node_segment "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/ingestion/segment.py"
click node_retention "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/retention.py"
click node_explain_pipeline "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/pipeline.py"
click node_classifier "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/api.py"
click node_trained_classifier "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/trained.py"
click node_llm_classifier "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/llm.py"
click node_topic_tags "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/topics.py"
click node_statute_retrieval "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/statute_kb/retrieval.py"
click node_explanation "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/generate.py"
click node_grounding "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/grounding.py"
click node_cross_clause "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/cross_clause.py"
click node_shared_llm "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/llm_client.py"
click node_db_access "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/db.py"
click node_models "https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/models.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_app_ui,node_api_client toneBlue
class node_fastapi,node_documents,node_extract,node_segment,node_retention toneAmber
class node_explain_pipeline,node_classifier,node_trained_classifier,node_llm_classifier,node_topic_tags,node_statute_retrieval,node_explanation,node_grounding,node_cross_clause,node_shared_llm toneMint
class node_db_access,node_models,node_postgres toneRose
class node_tenant,node_llm_provider toneIndigo
```

## Components

### LeaseLens frontend

- [Upload and results UI](https://github.com/rishi-is-cool/leaselens-india/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Frontend API client](https://github.com/rishi-is-cool/leaselens-india/blob/master/frontend/src/api.ts): `frontend/src/api.ts`

### API and ingestion

- [API application](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/main.py): `backend/app/main.py`
- [Document endpoints](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/routers/documents.py): `backend/app/routers/documents.py`
- [Text extraction](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/ingestion/extract.py): `backend/app/ingestion/extract.py`
- [Clause segmentation](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/ingestion/segment.py): `backend/app/ingestion/segment.py`
- [Upload retention](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/retention.py): `backend/app/retention.py`

### Clause analysis

- [Explanation orchestration](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/pipeline.py): `backend/app/explain/pipeline.py`
- [Risk classification](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/api.py): `backend/app/classifier/api.py`
- [Trained fallback](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/trained.py): `backend/app/classifier/trained.py`
- [LLM classifier](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/classifier/llm.py): `backend/app/classifier/llm.py`
- [Topic tagging](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/topics.py): `backend/app/explain/topics.py`
- [Statute retrieval](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/statute_kb/retrieval.py): `backend/app/statute_kb/retrieval.py`
- [Explanation generation](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/generate.py): `backend/app/explain/generate.py`
- [Citation grounding](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/grounding.py): `backend/app/explain/grounding.py`
- [Cross-clause analysis](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/explain/cross_clause.py): `backend/app/explain/cross_clause.py`
- [Shared LLM client](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/llm_client.py): `backend/app/llm_client.py`

### Persistence and providers

- [Database access](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/db.py): `backend/app/db.py`
- [Document and clause models](https://github.com/rishi-is-cool/leaselens-india/blob/master/backend/app/models.py): `backend/app/models.py`
- **Postgres**

### Other components

- **Lease uploader**
- **LLM provider**

## Connections

- Lease uploader → Upload and results UI: uploads lease
- Upload and results UI → Frontend API client: sends file
- Frontend API client → Document endpoints: calls upload API
- API application → Document endpoints: registers routes
- Document endpoints → Upload retention: purges expired
- Document endpoints → Text extraction: extracts text
- Document endpoints → Clause segmentation: segments paragraphs
- Document endpoints → Database access: opens session
- Document endpoints → Document and clause models: creates records
- Database access → Postgres: reads and writes
- Upload and results UI → Frontend API client: checks health
- Explanation orchestration → Risk classification: classifies clauses
- Explanation orchestration → Topic tagging: tags topics
- Explanation orchestration → Statute retrieval: retrieves statutes
- Explanation orchestration → Explanation generation: generates explanations
- Explanation orchestration → Citation grounding: checks grounding
- Explanation orchestration → Cross-clause analysis: checks clause pairs
- Risk classification → Trained fallback: uses fallback
- Risk classification → LLM classifier: uses LLM
- Explanation generation → Shared LLM client: requests completion
- Cross-clause analysis → Shared LLM client: requests completion
- Shared LLM client → LLM provider: sends chat request
- LLM classifier → LLM provider: sends chat request
