# shaurya703/lawline-ai architecture

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

- Interactive diagram: https://gitdiagram.com/shaurya703/lawline-ai
- Repository: https://github.com/shaurya703/lawline-ai

## Overview

LawLine AI is an Indian-law information assistant. Its principal workflow takes a legal question through hybrid retrieval, prompt construction and LLM or extractive answering, then returns cited passages. The repository also includes corpus preparation, evaluation, a Streamlit interface and a documented 22-route React application. Retrieval internals are shown in sampled source; links from individual unsampled frontend pages to backend services are not asserted.

Main entry points: [`lawline/retrieval/hybrid.py`](https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/hybrid.py) (Hybrid retriever), [`lawline/engine.py`](https://github.com/shaurya703/lawline-ai/blob/main/lawline/engine.py) (Query engine), [`scripts/build_indices.py`](https://github.com/shaurya703/lawline-ai/blob/main/scripts/build_indices.py) (Search index build), [`lawline/index/knowledge_graph.py`](https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/knowledge_graph.py) (Legal knowledge graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_streamlit["Streamlit command center<br/>[app.py]"]
  node_react["React application<br/>[App.tsx]"]
  node_feature_pages["Legal workspaces"]
  node_api["FastAPI service<br/>[api.py]"]
end

subgraph group_corpus["Legal corpus"]
  node_corpus_ingest["Corpus ingestion<br/>[ingest.py]"]
  node_corpus_schema["Document schema<br/>[schema.py]"]
  node_chunking["Passage chunking<br/>[chunking.py]"]
end

subgraph group_retrieval["Retrieval engine"]
  node_index_build["Search index build<br/>[build_indices.py]"]
  node_embedder["Semantic embeddings<br/>[embedder.py]"]
  node_faiss[("FAISS index<br/>[faiss_index.py]")]
  node_bm25[("BM25 index<br/>[bm25_index.py]")]
  node_concept_map["Legal concept map<br/>[concepts.py]"]
  node_knowledge_graph[("Legal knowledge graph<br/>[knowledge_graph.py]")]
  node_fusion["Rank fusion<br/>[fusion.py]"]
  node_reranker["Cross-encoder reranking<br/>[reranker.py]"]
  node_hybrid["Hybrid retriever<br/>[hybrid.py]"]
end

subgraph group_answers["Answer generation"]
  node_engine["Query engine<br/>[engine.py]"]
  node_prompts["Grounding prompts<br/>[prompts.py]"]
  node_llm["LLM and fallback<br/>[llm.py]"]
end

subgraph group_insight["Evaluation and training"]
  node_analytics["Retrieval analytics<br/>[analytics.py]"]
  node_ablation["Retrieval evaluation<br/>[run_ablation.py]"]
  node_biencoder["Bi-encoder training<br/>[train_biencoder.py]"]
end

node_user(("Legal information seeker"))

node_user -->|"asks question"| node_streamlit
node_user -->|"uses workspaces"| node_react
node_streamlit -.->|"submits question"| node_engine
node_corpus_ingest -->|"creates documents"| node_corpus_schema
node_corpus_ingest -.->|"feeds corpus"| node_chunking
node_index_build -.->|"builds indexes"| node_embedder
node_index_build -.->|"builds index"| node_faiss
node_index_build -.->|"builds index"| node_bm25
node_index_build -.->|"builds graph"| node_knowledge_graph
node_knowledge_graph -->|"seeds concepts"| node_concept_map
node_hybrid -->|"encodes queries"| node_embedder
node_hybrid -->|"searches vectors"| node_faiss
node_hybrid -->|"searches terms"| node_bm25
node_hybrid -->|"retrieves entities"| node_knowledge_graph
node_hybrid -->|"fuses rankings"| node_fusion
node_hybrid -->|"reranks candidates"| node_reranker
node_engine -->|"retrieves passages"| node_hybrid
node_engine -->|"formats context"| node_prompts
node_engine -->|"generates answer"| node_llm
node_engine -.->|"returns citations"| node_user
node_react -->|"routes requests"| node_feature_pages
node_react -.->|"calls service"| node_api
node_ablation -->|"evaluates retrieval"| node_faiss
node_ablation -->|"evaluates retrieval"| node_bm25
node_ablation -->|"evaluates retrieval"| node_knowledge_graph
node_biencoder -->|"trains encoder"| node_embedder

click node_streamlit "https://github.com/shaurya703/lawline-ai/blob/main/app.py"
click node_react "https://github.com/shaurya703/lawline-ai/blob/main/frontend/src/App.tsx"
click node_feature_pages "https://github.com/shaurya703/lawline-ai/tree/main/frontend/src/pages"
click node_corpus_ingest "https://github.com/shaurya703/lawline-ai/blob/main/lawline/data/ingest.py"
click node_corpus_schema "https://github.com/shaurya703/lawline-ai/blob/main/lawline/data/schema.py"
click node_chunking "https://github.com/shaurya703/lawline-ai/blob/main/lawline/data/chunking.py"
click node_index_build "https://github.com/shaurya703/lawline-ai/blob/main/scripts/build_indices.py"
click node_embedder "https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/embedder.py"
click node_faiss "https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/faiss_index.py"
click node_bm25 "https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/bm25_index.py"
click node_concept_map "https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/concepts.py"
click node_knowledge_graph "https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/knowledge_graph.py"
click node_fusion "https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/fusion.py"
click node_reranker "https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/reranker.py"
click node_hybrid "https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/hybrid.py"
click node_engine "https://github.com/shaurya703/lawline-ai/blob/main/lawline/engine.py"
click node_prompts "https://github.com/shaurya703/lawline-ai/blob/main/lawline/generation/prompts.py"
click node_llm "https://github.com/shaurya703/lawline-ai/blob/main/lawline/generation/llm.py"
click node_api "https://github.com/shaurya703/lawline-ai/blob/main/lawline/api.py"
click node_analytics "https://github.com/shaurya703/lawline-ai/blob/main/lawline/ui/pages/analytics.py"
click node_ablation "https://github.com/shaurya703/lawline-ai/blob/main/lawline/eval/run_ablation.py"
click node_biencoder "https://github.com/shaurya703/lawline-ai/blob/main/lawline/training/train_biencoder.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_streamlit,node_react,node_feature_pages,node_api toneBlue
class node_corpus_ingest,node_corpus_schema,node_chunking toneAmber
class node_index_build,node_embedder,node_faiss,node_bm25,node_concept_map,node_knowledge_graph,node_fusion,node_reranker,node_hybrid toneMint
class node_engine,node_prompts,node_llm toneRose
class node_analytics,node_ablation,node_biencoder,node_user toneIndigo
```

## Components

### User interfaces

- [Streamlit command center](https://github.com/shaurya703/lawline-ai/blob/main/app.py): `app.py`
- [React application](https://github.com/shaurya703/lawline-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Legal workspaces](https://github.com/shaurya703/lawline-ai/tree/main/frontend/src/pages): `frontend/src/pages`
- [FastAPI service](https://github.com/shaurya703/lawline-ai/blob/main/lawline/api.py): `lawline/api.py`

### Legal corpus

- [Corpus ingestion](https://github.com/shaurya703/lawline-ai/blob/main/lawline/data/ingest.py): `lawline/data/ingest.py`
- [Document schema](https://github.com/shaurya703/lawline-ai/blob/main/lawline/data/schema.py): `lawline/data/schema.py`
- [Passage chunking](https://github.com/shaurya703/lawline-ai/blob/main/lawline/data/chunking.py): `lawline/data/chunking.py`

### Retrieval engine

- [Search index build](https://github.com/shaurya703/lawline-ai/blob/main/scripts/build_indices.py): `scripts/build_indices.py`
- [Semantic embeddings](https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/embedder.py): `lawline/index/embedder.py`
- [FAISS index](https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/faiss_index.py): `lawline/index/faiss_index.py`
- [BM25 index](https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/bm25_index.py): `lawline/index/bm25_index.py`
- [Legal concept map](https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/concepts.py): `lawline/index/concepts.py`
- [Legal knowledge graph](https://github.com/shaurya703/lawline-ai/blob/main/lawline/index/knowledge_graph.py): `lawline/index/knowledge_graph.py`
- [Rank fusion](https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/fusion.py): `lawline/retrieval/fusion.py`
- [Cross-encoder reranking](https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/reranker.py): `lawline/retrieval/reranker.py`
- [Hybrid retriever](https://github.com/shaurya703/lawline-ai/blob/main/lawline/retrieval/hybrid.py): `lawline/retrieval/hybrid.py`

### Answer generation

- [Query engine](https://github.com/shaurya703/lawline-ai/blob/main/lawline/engine.py): `lawline/engine.py`
- [Grounding prompts](https://github.com/shaurya703/lawline-ai/blob/main/lawline/generation/prompts.py): `lawline/generation/prompts.py`
- [LLM and fallback](https://github.com/shaurya703/lawline-ai/blob/main/lawline/generation/llm.py): `lawline/generation/llm.py`

### Evaluation and training

- [Retrieval analytics](https://github.com/shaurya703/lawline-ai/blob/main/lawline/ui/pages/analytics.py): `lawline/ui/pages/analytics.py`
- [Retrieval evaluation](https://github.com/shaurya703/lawline-ai/blob/main/lawline/eval/run_ablation.py): `lawline/eval/run_ablation.py`
- [Bi-encoder training](https://github.com/shaurya703/lawline-ai/blob/main/lawline/training/train_biencoder.py): `lawline/training/train_biencoder.py`

### Other components

- **Legal information seeker**

## Connections

- Legal information seeker → Streamlit command center: asks question
- Legal information seeker → React application: uses workspaces (evidence: `frontend/src/App.tsx`)
- Streamlit command center → Query engine: submits question
- Corpus ingestion → Document schema: creates documents (evidence: `lawline/data/ingest.py`)
- Corpus ingestion → Passage chunking: feeds corpus (evidence: `README.md`)
- Search index build → Semantic embeddings: builds indexes (evidence: `README.md`)
- Search index build → FAISS index: builds index (evidence: `README.md`)
- Search index build → BM25 index: builds index (evidence: `README.md`)
- Search index build → Legal knowledge graph: builds graph (evidence: `README.md`)
- Legal knowledge graph → Legal concept map: seeds concepts (evidence: `lawline/index/knowledge_graph.py`)
- Hybrid retriever → Semantic embeddings: encodes queries (evidence: `lawline/retrieval/hybrid.py`)
- Hybrid retriever → FAISS index: searches vectors (evidence: `lawline/retrieval/hybrid.py`)
- Hybrid retriever → BM25 index: searches terms (evidence: `lawline/retrieval/hybrid.py`)
- Hybrid retriever → Legal knowledge graph: retrieves entities (evidence: `lawline/retrieval/hybrid.py`)
- Hybrid retriever → Rank fusion: fuses rankings (evidence: `lawline/retrieval/hybrid.py`)
- Hybrid retriever → Cross-encoder reranking: reranks candidates (evidence: `lawline/retrieval/hybrid.py`)
- Query engine → Hybrid retriever: retrieves passages (evidence: `lawline/engine.py`)
- Query engine → Grounding prompts: formats context (evidence: `lawline/engine.py`)
- Query engine → LLM and fallback: generates answer (evidence: `lawline/engine.py`)
- Query engine → Legal information seeker: returns citations
- React application → Legal workspaces: routes requests (evidence: `frontend/src/App.tsx`)
- React application → FastAPI service: calls service
- Retrieval evaluation → FAISS index: evaluates retrieval (evidence: `lawline/eval/run_ablation.py`)
- Retrieval evaluation → BM25 index: evaluates retrieval (evidence: `lawline/eval/run_ablation.py`)
- Retrieval evaluation → Legal knowledge graph: evaluates retrieval (evidence: `lawline/eval/run_ablation.py`)
- Bi-encoder training → Semantic embeddings: trains encoder (evidence: `lawline/training/train_biencoder.py`)
