# udveetpatil/unified-legal-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/udveetpatil/unified-legal-assistant
- Repository: https://github.com/udveetpatil/unified-legal-assistant

## Overview

Unified Legal Assistant for India is an offline-first legal retrieval and verification system. The visible retrieval runtime classifies a query, gathers vector and BM25 candidates, fuses them, and reranks the results. Separately, graph-building code loads cases, statutes, and relationships into Neo4j; the verifier checks cited sections and legal connections. The README also documents local-model response generation, temporal lookup, and domain-partitioned retrieval, but API, UI, translation, and LLM implementations were not sampled. Edges for those documented capabilities rely on the README; the shown pipeline itself stops before generation and verification.

Main entry points: [`src/pipeline.py`](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/pipeline.py) (Retrieval pipeline), [`src/vector_db/hybrid.py`](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/hybrid.py) (Hybrid fusion), [`src/verifier/verifier_agent.py`](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/verifier/verifier_agent.py) (Graph retrieval), [`src/vector_db/retriever.py`](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/retriever.py) (Vector search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_query["Query retrieval"]
  node_pipeline["Retrieval pipeline<br/>[pipeline.py]"]
  node_classifier["Intent classifier<br/>[intent.py]"]
  node_vector["Vector search<br/>[retriever.py]"]
  node_bm25["BM25 search<br/>[bm25_retriever.py]"]
  node_hybrid["Hybrid fusion<br/>[hybrid.py]"]
  node_reranker["Cross-encoder reranker<br/>[reranker.py]"]
end

subgraph group_knowledge["Legal knowledge"]
  node_indexer["Index construction<br/>[build_index.py]"]
  node_vector_store[("Vector database")]
  node_graph_builder["Graph construction<br/>[build_graph.py]"]
  node_neo4j[("Neo4j graph")]
  node_temporal["Temporal law lookup"]
end

subgraph group_verification["Verification"]
  node_graph_retrieval["Graph retrieval<br/>[verifier_agent.py]"]
  node_verifier["Path verifier<br/>[verifier_agent.py]"]
end

subgraph group_response["Answer generation"]
  node_local_llm["Local LLM"]
  node_answer["Cited answer"]
end

node_user(("Legal user"))

node_user -->|"submits query"| node_pipeline
node_pipeline -->|"classifies"| node_classifier
node_pipeline -->|"retrieves candidates"| node_hybrid
node_hybrid -->|"searches vectors"| node_vector
node_hybrid -->|"searches keywords"| node_bm25
node_pipeline -->|"reranks candidates"| node_reranker
node_indexer -->|"writes documents"| node_vector_store
node_vector -->|"queries"| node_vector_store
node_bm25 -->|"loads documents"| node_vector_store
node_graph_builder -->|"loads legal graph"| node_neo4j
node_graph_retrieval -->|"queries graph"| node_neo4j
node_temporal -.->|"tracks legal dates"| node_neo4j
node_pipeline -.->|"retrieves graph context"| node_graph_retrieval
node_graph_retrieval -->|"supplies legal paths"| node_verifier
node_verifier -.->|"grounds response"| node_local_llm
node_local_llm -.->|"generates citations"| node_answer

click node_pipeline "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/pipeline.py"
click node_classifier "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/classifier/intent.py"
click node_vector "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/retriever.py"
click node_bm25 "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/bm25_retriever.py"
click node_hybrid "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/hybrid.py"
click node_reranker "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/reranker.py"
click node_indexer "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/build_index.py"
click node_graph_builder "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/graph_db/build_graph.py"
click node_temporal "https://github.com/udveetpatil/unified-legal-assistant/tree/master/src/graph_db"
click node_graph_retrieval "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/verifier/verifier_agent.py"
click node_verifier "https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/verifier/verifier_agent.py"
click node_local_llm "https://github.com/udveetpatil/unified-legal-assistant/tree/master/src/llm"

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_pipeline,node_classifier,node_vector,node_bm25,node_hybrid,node_reranker,node_user toneBlue
class node_indexer,node_vector_store,node_graph_builder,node_neo4j,node_temporal toneAmber
class node_graph_retrieval,node_verifier toneMint
class node_local_llm,node_answer toneRose
```

## Components

### Query retrieval

- [Retrieval pipeline](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/pipeline.py): `src/pipeline.py`
- [Intent classifier](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/classifier/intent.py): `src/classifier/intent.py`
- [Vector search](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/retriever.py): `src/vector_db/retriever.py`
- [BM25 search](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/bm25_retriever.py): `src/vector_db/bm25_retriever.py`
- [Hybrid fusion](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/hybrid.py): `src/vector_db/hybrid.py`
- [Cross-encoder reranker](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/reranker.py): `src/vector_db/reranker.py`

### Legal knowledge

- [Index construction](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/vector_db/build_index.py): `src/vector_db/build_index.py`
- **Vector database**
- [Graph construction](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/graph_db/build_graph.py): `src/graph_db/build_graph.py`
- **Neo4j graph**
- [Temporal law lookup](https://github.com/udveetpatil/unified-legal-assistant/tree/master/src/graph_db): `src/graph_db`

### Verification

- [Graph retrieval](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/verifier/verifier_agent.py): `src/verifier/verifier_agent.py`
- [Path verifier](https://github.com/udveetpatil/unified-legal-assistant/blob/master/src/verifier/verifier_agent.py): `src/verifier/verifier_agent.py`

### Answer generation

- [Local LLM](https://github.com/udveetpatil/unified-legal-assistant/tree/master/src/llm): `src/llm`
- **Cited answer**

### Other components

- **Legal user**

## Connections

- Legal user → Retrieval pipeline: submits query (evidence: `README.md`)
- Retrieval pipeline → Intent classifier: classifies (evidence: `src/pipeline.py`)
- Retrieval pipeline → Hybrid fusion: retrieves candidates (evidence: `src/pipeline.py`)
- Hybrid fusion → Vector search: searches vectors (evidence: `src/vector_db/hybrid.py`)
- Hybrid fusion → BM25 search: searches keywords (evidence: `src/vector_db/hybrid.py`)
- Retrieval pipeline → Cross-encoder reranker: reranks candidates (evidence: `src/pipeline.py`)
- Index construction → Vector database: writes documents (evidence: `src/vector_db/build_index.py`)
- Vector search → Vector database: queries (evidence: `src/vector_db/retriever.py`)
- BM25 search → Vector database: loads documents (evidence: `src/vector_db/bm25_retriever.py`)
- Graph construction → Neo4j graph: loads legal graph (evidence: `src/graph_db/build_graph.py`)
- Graph retrieval → Neo4j graph: queries graph (evidence: `src/verifier/verifier_agent.py`)
- Temporal law lookup → Neo4j graph: tracks legal dates (evidence: `README.md`)
- Retrieval pipeline → Graph retrieval: retrieves graph context (evidence: `README.md`)
- Graph retrieval → Path verifier: supplies legal paths (evidence: `src/verifier/verifier_agent.py`)
- Path verifier → Local LLM: grounds response (evidence: `README.md`)
- Local LLM → Cited answer: generates citations (evidence: `README.md`)
