# mohanreddy-11/legalresearch2 architecture

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

- Interactive diagram: https://gitdiagram.com/mohanreddy-11/legalresearch2
- Repository: https://github.com/mohanreddy-11/legalresearch2

## Overview

LegalResearch2 is a Streamlit assistant for researching Indian law. A user submits a question; the app invokes the RAG workflow, which retrieves relevant indexed passages, looks up related cases, builds a grounded prompt, and streams a model response with source and case references back to the interface. The graph separates retrieval, case metadata, and response generation. The repository includes law PDFs and an existing FAISS index, but the README and sampled source do not establish how the PDFs were used to build that index.

Main entry points: [`rag.py`](https://github.com/mohanreddy-11/legalresearch2/blob/main/rag.py) (RAG workflow), [`app.py`](https://github.com/mohanreddy-11/legalresearch2/blob/main/app.py) (Chat interface), [`case_lookup.py`](https://github.com/mohanreddy-11/legalresearch2/blob/main/case_lookup.py) (Case matching), [`config.py`](https://github.com/mohanreddy-11/legalresearch2/blob/main/config.py) (Runtime settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Chat interface<br/>[app.py]"]
end

subgraph group_retrieval["Legal retrieval"]
  node_rag["RAG workflow<br/>[rag.py]"]
  node_config["Runtime settings<br/>[config.py]"]
  node_index[("FAISS index<br/>[index.faiss]")]
  node_embeddings["Text embeddings<br/>[rag.py]"]
end

subgraph group_case_data["Case metadata"]
  node_case_lookup["Case matching<br/>[case_lookup.py]"]
  node_metadata["Legal metadata"]
end

subgraph group_generation["Answer generation"]
  node_prompt["Legal prompt<br/>[prompts.py]"]
  node_llm["NVIDIA model API"]
end

node_user(("Legal researcher"))

node_user -->|"asks question"| node_app
node_app -->|"submits question"| node_rag
node_app -->|"reads model name"| node_config
node_rag -->|"returns answer and sources"| node_app
node_rag -->|"reads settings"| node_config
node_rag -->|"creates embeddings"| node_embeddings
node_rag -->|"loads and queries"| node_index
node_rag -->|"matches cases and laws"| node_case_lookup
node_case_lookup -->|"reads CSV metadata"| node_metadata
node_rag -->|"formats prompt"| node_prompt
node_rag -->|"streams completion"| node_llm

click node_app "https://github.com/mohanreddy-11/legalresearch2/blob/main/app.py"
click node_rag "https://github.com/mohanreddy-11/legalresearch2/blob/main/rag.py"
click node_config "https://github.com/mohanreddy-11/legalresearch2/blob/main/config.py"
click node_index "https://github.com/mohanreddy-11/legalresearch2/blob/main/vectorstore/index.faiss"
click node_embeddings "https://github.com/mohanreddy-11/legalresearch2/blob/main/rag.py"
click node_case_lookup "https://github.com/mohanreddy-11/legalresearch2/blob/main/case_lookup.py"
click node_metadata "https://github.com/mohanreddy-11/legalresearch2/tree/main/data/metadata"
click node_prompt "https://github.com/mohanreddy-11/legalresearch2/blob/main/prompts.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 toneBlue
class node_rag,node_config,node_index,node_embeddings toneAmber
class node_case_lookup,node_metadata toneMint
class node_prompt,node_llm toneRose
class node_user toneIndigo
```

## Components

### User interface

- [Chat interface](https://github.com/mohanreddy-11/legalresearch2/blob/main/app.py): `app.py`

### Legal retrieval

- [RAG workflow](https://github.com/mohanreddy-11/legalresearch2/blob/main/rag.py): `rag.py`
- [Runtime settings](https://github.com/mohanreddy-11/legalresearch2/blob/main/config.py): `config.py`
- [FAISS index](https://github.com/mohanreddy-11/legalresearch2/blob/main/vectorstore/index.faiss): `vectorstore/index.faiss`
- [Text embeddings](https://github.com/mohanreddy-11/legalresearch2/blob/main/rag.py): `rag.py`

### Case metadata

- [Case matching](https://github.com/mohanreddy-11/legalresearch2/blob/main/case_lookup.py): `case_lookup.py`
- [Legal metadata](https://github.com/mohanreddy-11/legalresearch2/tree/main/data/metadata): `data/metadata`

### Answer generation

- [Legal prompt](https://github.com/mohanreddy-11/legalresearch2/blob/main/prompts.py): `prompts.py`
- **NVIDIA model API**

### Other components

- **Legal researcher**

## Connections

- Legal researcher → Chat interface: asks question (evidence: `app.py`)
- Chat interface → RAG workflow: submits question (evidence: `app.py`)
- Chat interface → Runtime settings: reads model name (evidence: `app.py`)
- RAG workflow → Chat interface: returns answer and sources (evidence: `app.py`)
- RAG workflow → Runtime settings: reads settings (evidence: `rag.py`)
- RAG workflow → Text embeddings: creates embeddings (evidence: `rag.py`)
- RAG workflow → FAISS index: loads and queries (evidence: `rag.py`)
- RAG workflow → Case matching: matches cases and laws (evidence: `rag.py`)
- Case matching → Legal metadata: reads CSV metadata (evidence: `case_lookup.py`)
- RAG workflow → Legal prompt: formats prompt (evidence: `rag.py`)
- RAG workflow → NVIDIA model API: streams completion (evidence: `rag.py`)
