# sanjay-sahoo-0804/legal-ease-ai architecture

> Architecture diagram of the GitHub repository sanjay-sahoo-0804/legal-ease-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sanjay-sahoo-0804/legal-ease-ai
- Repository: https://github.com/sanjay-sahoo-0804/legal-ease-ai

## Overview

Legal-Ease AI is a document-grounded question-answering app: users upload PDFs for indexing, then ask questions and receive answers with retrieved context. The frontend calls a FastAPI backend, which orchestrates PDF preprocessing, vector storage and retrieval, and local language-model generation. A separate script demonstrates QLoRA fine-tuning. The README is empty, so the map relies on the sampled source; fine-tuning is shown as a separate capability, not as part of the serving workflow.

Main entry points: [`backend/app.py`](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/app.py) (FastAPI endpoints), [`backend/vector_store.py`](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/vector_store.py) (Vector store access), [`backend/config.py`](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/config.py) (Answer generation), [`frontend/main.py`](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/frontend/main.py) (Streamlit dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_frontend["Streamlit dashboard<br/>[main.py]"]
end

subgraph group_api["API orchestration"]
  node_api_app["FastAPI endpoints<br/>[app.py]"]
end

subgraph group_ingest["Document ingestion"]
  node_pdf_extract["PDF extraction<br/>[preprocess.py]"]
  node_text_clean["Text cleaning<br/>[preprocess.py]"]
  node_text_chunk["Text chunking<br/>[preprocess.py]"]
end

subgraph group_rag["Retrieval and generation"]
  node_vector_store["Vector store access<br/>[vector_store.py]"]
  node_chroma[("Persistent ChromaDB<br/>[vector_store.py]")]
  node_llm_generation["Answer generation<br/>[config.py]"]
  node_qwen["Qwen model<br/>[config.py]"]
end

subgraph group_training["Model fine-tuning"]
  node_finetune["QLoRA training<br/>[finetune.py]"]
end

node_user(("User"))
node_model_hub["Hugging Face models"]
node_adapter_output[("Saved adapter weights")]

node_user -->|"uploads and asks"| node_frontend
node_frontend -->|"sends API requests"| node_api_app
node_api_app -->|"returns answers"| node_frontend
node_api_app -->|"calls extraction"| node_pdf_extract
node_api_app -->|"calls cleaning"| node_text_clean
node_api_app -->|"calls chunking"| node_text_chunk
node_api_app -->|"stores chunks"| node_vector_store
node_api_app -->|"requests retrieval"| node_vector_store
node_vector_store -->|"adds and queries"| node_chroma
node_chroma -->|"returns matches"| node_vector_store
node_api_app -->|"requests answer"| node_llm_generation
node_llm_generation -->|"returns answer"| node_api_app
node_llm_generation -->|"runs inference"| node_qwen
node_finetune -->|"loads base model"| node_model_hub
node_finetune -->|"saves adapters"| node_adapter_output

click node_frontend "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/frontend/main.py"
click node_api_app "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/app.py"
click node_pdf_extract "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/preprocess.py"
click node_text_clean "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/preprocess.py"
click node_text_chunk "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/preprocess.py"
click node_vector_store "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/vector_store.py"
click node_chroma "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/vector_store.py"
click node_llm_generation "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/config.py"
click node_qwen "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/config.py"
click node_finetune "https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/finetune.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_frontend,node_user toneBlue
class node_api_app,node_adapter_output toneAmber
class node_pdf_extract,node_text_clean,node_text_chunk toneMint
class node_vector_store,node_chroma,node_llm_generation,node_qwen toneRose
class node_finetune,node_model_hub toneIndigo
```

## Components

### User interface

- [Streamlit dashboard](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/frontend/main.py): `frontend/main.py`

### API orchestration

- [FastAPI endpoints](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/app.py): `backend/app.py`

### Document ingestion

- [PDF extraction](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/preprocess.py): `data_pipeline/preprocess.py`
- [Text cleaning](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/preprocess.py): `data_pipeline/preprocess.py`
- [Text chunking](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/preprocess.py): `data_pipeline/preprocess.py`

### Retrieval and generation

- [Vector store access](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/vector_store.py): `backend/vector_store.py`
- [Persistent ChromaDB](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/vector_store.py): `backend/vector_store.py`
- [Answer generation](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/config.py): `backend/config.py`
- [Qwen model](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/backend/config.py): `backend/config.py`

### Model fine-tuning

- [QLoRA training](https://github.com/sanjay-sahoo-0804/legal-ease-ai/blob/main/data_pipeline/finetune.py): `data_pipeline/finetune.py`

### Other components

- **User**
- **Hugging Face models**
- **Saved adapter weights**

## Connections

- User → Streamlit dashboard: uploads and asks
- Streamlit dashboard → FastAPI endpoints: sends API requests
- FastAPI endpoints → Streamlit dashboard: returns answers
- FastAPI endpoints → PDF extraction: calls extraction
- FastAPI endpoints → Text cleaning: calls cleaning
- FastAPI endpoints → Text chunking: calls chunking
- FastAPI endpoints → Vector store access: stores chunks
- FastAPI endpoints → Vector store access: requests retrieval
- Vector store access → Persistent ChromaDB: adds and queries
- Persistent ChromaDB → Vector store access: returns matches
- FastAPI endpoints → Answer generation: requests answer
- Answer generation → FastAPI endpoints: returns answer
- Answer generation → Qwen model: runs inference
- QLoRA training → Hugging Face models: loads base model
- QLoRA training → Saved adapter weights: saves adapters
