# sukumar5705/lexgraph architecture

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

- Interactive diagram: https://gitdiagram.com/sukumar5705/lexgraph
- Repository: https://github.com/sukumar5705/lexgraph

## Overview

This is a project skeleton for Indian legal-precedent research using authority- and temporal-aware GraphRAG. The intended user workflow is search in the React interface, backend search routing, retrieval and reranking, then grounded answer generation with citation/conflict checks; graph and case exploration are additional capabilities. The README also describes ingestion and evaluation branches. Many modules are TODOs or unsampled, so only documented flows and source-index-supported calls are connected; evaluation is represented as a capability, not a runtime stage.

Main entry points: [`backend/core/rag_pipeline.py`](https://github.com/sukumar5705/lexgraph/blob/main/backend/core/rag_pipeline.py) (RAG orchestration), [`retrieval/hybrid/hybrid_retriever.py`](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/hybrid/hybrid_retriever.py) (Hybrid retrieval), [`backend/main.py`](https://github.com/sukumar5705/lexgraph/blob/main/backend/main.py) (FastAPI application), [`backend/api/routes_search.py`](https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_search.py) (Search routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_web_ui["Search interface<br/>[Home.jsx]"]
  node_frontend_api["API client<br/>[api.js]"]
  node_case_explorer["Case explorer<br/>[CaseExplorer.jsx]"]
  node_graph_view["Knowledge graph view<br/>[KnowledgeGraph.jsx]"]
end

subgraph group_api["Backend API"]
  node_backend_app["FastAPI application<br/>[main.py]"]
  node_search_routes["Search routes<br/>[routes_search.py]"]
  node_graph_routes["Graph routes<br/>[routes_graph.py]"]
  node_case_routes["Case routes<br/>[routes_cases.py]"]
end

subgraph group_research["RAG pipeline"]
  node_rag_pipeline["RAG orchestration<br/>[rag_pipeline.py]"]
  node_cross_encoder["Cross-encoder reranking<br/>[cross_encoder.py]"]
  node_authority_ranker["Authority ranking"]
  node_temporal_check["Temporal validation"]
  node_conflict_check["Conflict detection"]
  node_citation_check["Citation verification"]
  node_answer_generation["Grounded answer generation<br/>[llm_service.py]"]
end

subgraph group_data["Ingestion and retrieval"]
  node_hybrid_retriever["Hybrid retrieval"]
  node_bm25["BM25 retrieval<br/>[bm25_retriever.py]"]
  node_embeddings["Embedding model<br/>[embedding_model.py]"]
  node_vector_store[("Vector store<br/>[vector_store.py]")]
  node_graph_retriever[("Citation graph retrieval<br/>[graph_retriever.py]")]
  node_ingestion["Legal document ingestion"]
  node_preprocessing["Case preprocessing"]
  node_chunking["Legal chunking"]
  node_graph_build["Citation graph building"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation_baselines["Retrieval baselines"]
  node_evaluation_metrics["Research metrics"]
  node_experiment_runners["Experiments"]
end

node_researcher(("Legal researcher"))

node_researcher -->|"searches"| node_web_ui
node_web_ui -.->|"submits query"| node_frontend_api
node_frontend_api -.->|"requests search"| node_search_routes
node_backend_app -->|"registers"| node_search_routes
node_backend_app -->|"registers"| node_graph_routes
node_backend_app -->|"registers"| node_case_routes
node_search_routes -->|"runs pipeline"| node_rag_pipeline
node_rag_pipeline -->|"retrieves candidates"| node_hybrid_retriever
node_hybrid_retriever -->|"embeds query"| node_embeddings
node_hybrid_retriever -->|"queries vectors"| node_vector_store
node_hybrid_retriever -->|"queries keywords"| node_bm25
node_rag_pipeline -->|"reranks candidates"| node_cross_encoder
node_rag_pipeline -->|"scores authority"| node_authority_ranker
node_authority_ranker -->|"reads case relations"| node_graph_retriever
node_rag_pipeline -->|"validates dates"| node_temporal_check
node_rag_pipeline -->|"checks conflicts"| node_conflict_check
node_rag_pipeline -->|"verifies citations"| node_citation_check
node_rag_pipeline -->|"generates answer"| node_answer_generation
node_graph_routes -.->|"serves graph data"| node_graph_view
node_researcher -->|"explores cases"| node_case_explorer
node_case_explorer -.->|"requests case details"| node_case_routes
node_ingestion -->|"processes documents"| node_preprocessing
node_preprocessing -->|"prepares case text"| node_chunking
node_chunking -.->|"supports graph building"| node_graph_build
node_graph_build -.->|"builds graph for retrieval"| node_graph_retriever
node_evaluation_baselines -.->|"compared in"| node_experiment_runners
node_experiment_runners -.->|"evaluated with"| node_evaluation_metrics

click node_web_ui "https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/pages/Home.jsx"
click node_frontend_api "https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/services/api.js"
click node_case_explorer "https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/pages/CaseExplorer.jsx"
click node_graph_view "https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/components/KnowledgeGraph.jsx"
click node_backend_app "https://github.com/sukumar5705/lexgraph/blob/main/backend/main.py"
click node_search_routes "https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_search.py"
click node_graph_routes "https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_graph.py"
click node_case_routes "https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_cases.py"
click node_rag_pipeline "https://github.com/sukumar5705/lexgraph/blob/main/backend/core/rag_pipeline.py"
click node_hybrid_retriever "https://github.com/sukumar5705/lexgraph/blob/main/retrieval/hybrid/hybrid_retriever.py"
click node_bm25 "https://github.com/sukumar5705/lexgraph/blob/main/retrieval/bm25/bm25_retriever.py"
click node_embeddings "https://github.com/sukumar5705/lexgraph/blob/main/retrieval/vector/embedding_model.py"
click node_vector_store "https://github.com/sukumar5705/lexgraph/blob/main/retrieval/vector/vector_store.py"
click node_cross_encoder "https://github.com/sukumar5705/lexgraph/blob/main/retrieval/reranking/cross_encoder.py"
click node_authority_ranker "https://github.com/sukumar5705/lexgraph/blob/main/retrieval/reranking/authority_ranker.py"
click node_graph_retriever "https://github.com/sukumar5705/lexgraph/blob/main/knowledge_graph/graph_retriever.py"
click node_temporal_check "https://github.com/sukumar5705/lexgraph/blob/main/backend/core/temporal_validator.py"
click node_conflict_check "https://github.com/sukumar5705/lexgraph/blob/main/backend/core/conflict_detector.py"
click node_citation_check "https://github.com/sukumar5705/lexgraph/blob/main/backend/core/citation_verifier.py"
click node_answer_generation "https://github.com/sukumar5705/lexgraph/blob/main/backend/core/llm_service.py"
click node_ingestion "https://github.com/sukumar5705/lexgraph/tree/main/ingestion/extraction"
click node_preprocessing "https://github.com/sukumar5705/lexgraph/tree/main/ingestion/preprocessing"
click node_chunking "https://github.com/sukumar5705/lexgraph/tree/main/ingestion/chunking"
click node_graph_build "https://github.com/sukumar5705/lexgraph/tree/main/ingestion/graph"
click node_evaluation_baselines "https://github.com/sukumar5705/lexgraph/tree/main/evaluation/baselines"
click node_evaluation_metrics "https://github.com/sukumar5705/lexgraph/tree/main/evaluation/metrics"
click node_experiment_runners "https://github.com/sukumar5705/lexgraph/tree/main/evaluation/experiments"

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_web_ui,node_frontend_api,node_case_explorer,node_graph_view toneBlue
class node_backend_app,node_search_routes,node_graph_routes,node_case_routes toneAmber
class node_rag_pipeline,node_cross_encoder,node_authority_ranker,node_temporal_check,node_conflict_check,node_citation_check,node_answer_generation toneMint
class node_hybrid_retriever,node_bm25,node_embeddings,node_vector_store,node_graph_retriever,node_ingestion,node_preprocessing,node_chunking,node_graph_build toneRose
class node_evaluation_baselines,node_evaluation_metrics,node_experiment_runners,node_researcher toneIndigo
```

## Components

### User interface

- [Search interface](https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [API client](https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`
- [Case explorer](https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/pages/CaseExplorer.jsx): `frontend/src/pages/CaseExplorer.jsx`
- [Knowledge graph view](https://github.com/sukumar5705/lexgraph/blob/main/frontend/src/components/KnowledgeGraph.jsx): `frontend/src/components/KnowledgeGraph.jsx`

### Backend API

- [FastAPI application](https://github.com/sukumar5705/lexgraph/blob/main/backend/main.py): `backend/main.py`
- [Search routes](https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_search.py): `backend/api/routes_search.py`
- [Graph routes](https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_graph.py): `backend/api/routes_graph.py`
- [Case routes](https://github.com/sukumar5705/lexgraph/blob/main/backend/api/routes_cases.py): `backend/api/routes_cases.py`

### RAG pipeline

- [RAG orchestration](https://github.com/sukumar5705/lexgraph/blob/main/backend/core/rag_pipeline.py): `backend/core/rag_pipeline.py`
- [Cross-encoder reranking](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/reranking/cross_encoder.py): `retrieval/reranking/cross_encoder.py`
- [Authority ranking](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/reranking/authority_ranker.py): `retrieval/reranking/authority_ranker.py`
- [Temporal validation](https://github.com/sukumar5705/lexgraph/blob/main/backend/core/temporal_validator.py): `backend/core/temporal_validator.py`
- [Conflict detection](https://github.com/sukumar5705/lexgraph/blob/main/backend/core/conflict_detector.py): `backend/core/conflict_detector.py`
- [Citation verification](https://github.com/sukumar5705/lexgraph/blob/main/backend/core/citation_verifier.py): `backend/core/citation_verifier.py`
- [Grounded answer generation](https://github.com/sukumar5705/lexgraph/blob/main/backend/core/llm_service.py): `backend/core/llm_service.py`

### Ingestion and retrieval

- [Hybrid retrieval](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/hybrid/hybrid_retriever.py): `retrieval/hybrid/hybrid_retriever.py`
- [BM25 retrieval](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/bm25/bm25_retriever.py): `retrieval/bm25/bm25_retriever.py`
- [Embedding model](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/vector/embedding_model.py): `retrieval/vector/embedding_model.py`
- [Vector store](https://github.com/sukumar5705/lexgraph/blob/main/retrieval/vector/vector_store.py): `retrieval/vector/vector_store.py`
- [Citation graph retrieval](https://github.com/sukumar5705/lexgraph/blob/main/knowledge_graph/graph_retriever.py): `knowledge_graph/graph_retriever.py`
- [Legal document ingestion](https://github.com/sukumar5705/lexgraph/tree/main/ingestion/extraction): `ingestion/extraction`
- [Case preprocessing](https://github.com/sukumar5705/lexgraph/tree/main/ingestion/preprocessing): `ingestion/preprocessing`
- [Legal chunking](https://github.com/sukumar5705/lexgraph/tree/main/ingestion/chunking): `ingestion/chunking`
- [Citation graph building](https://github.com/sukumar5705/lexgraph/tree/main/ingestion/graph): `ingestion/graph`

### Evaluation

- [Retrieval baselines](https://github.com/sukumar5705/lexgraph/tree/main/evaluation/baselines): `evaluation/baselines`
- [Research metrics](https://github.com/sukumar5705/lexgraph/tree/main/evaluation/metrics): `evaluation/metrics`
- [Experiments](https://github.com/sukumar5705/lexgraph/tree/main/evaluation/experiments): `evaluation/experiments`

### Other components

- **Legal researcher**

## Connections

- Legal researcher → Search interface: searches (evidence: `README.md`)
- Search interface → API client: submits query
- API client → Search routes: requests search
- FastAPI application → Search routes: registers (evidence: `backend/main.py`)
- FastAPI application → Graph routes: registers (evidence: `backend/main.py`)
- FastAPI application → Case routes: registers (evidence: `backend/main.py`)
- Search routes → RAG orchestration: runs pipeline (evidence: `backend/api/routes_search.py`)
- RAG orchestration → Hybrid retrieval: retrieves candidates (evidence: `backend/core/rag_pipeline.py`)
- Hybrid retrieval → Embedding model: embeds query (evidence: `retrieval/hybrid/hybrid_retriever.py`)
- Hybrid retrieval → Vector store: queries vectors (evidence: `retrieval/hybrid/hybrid_retriever.py`)
- Hybrid retrieval → BM25 retrieval: queries keywords (evidence: `retrieval/hybrid/hybrid_retriever.py`)
- RAG orchestration → Cross-encoder reranking: reranks candidates (evidence: `backend/core/rag_pipeline.py`)
- RAG orchestration → Authority ranking: scores authority (evidence: `backend/core/rag_pipeline.py`)
- Authority ranking → Citation graph retrieval: reads case relations (evidence: `retrieval/reranking/authority_ranker.py`)
- RAG orchestration → Temporal validation: validates dates (evidence: `backend/core/rag_pipeline.py`)
- RAG orchestration → Conflict detection: checks conflicts (evidence: `backend/core/rag_pipeline.py`)
- RAG orchestration → Citation verification: verifies citations (evidence: `backend/core/rag_pipeline.py`)
- RAG orchestration → Grounded answer generation: generates answer (evidence: `backend/core/rag_pipeline.py`)
- Graph routes → Knowledge graph view: serves graph data
- Legal researcher → Case explorer: explores cases (evidence: `README.md`)
- Case explorer → Case routes: requests case details
- Legal document ingestion → Case preprocessing: processes documents (evidence: `README.md`)
- Case preprocessing → Legal chunking: prepares case text (evidence: `README.md`)
- Legal chunking → Citation graph building: supports graph building
- Citation graph building → Citation graph retrieval: builds graph for retrieval
- Retrieval baselines → Experiments: compared in
- Experiments → Research metrics: evaluated with
