# pankaj-2708/self-rag-on-indian-constitution architecture

> Architecture diagram of the GitHub repository pankaj-2708/self-rag-on-indian-constitution, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pankaj-2708/self-rag-on-indian-constitution
- Repository: https://github.com/pankaj-2708/self-rag-on-indian-constitution

## Overview

This repository is a legal-question answering product for the Indian Constitution and IPC. A user submits a question in the web app; the API streams progress from a LangGraph workflow, which routes among local retrieval, web search, and direct generation, then validates and may correct its answer before returning it. The workflow also maintains conversational memory. The README documents a separate three-tier evaluation capability. Some backend and workflow source is excerpted, so uncertain runtime links are omitted or marked unverified.

Main entry points: [`src/workflow/__init__.py`](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/__init__.py) (Workflow orchestrator), [`frontend/src/App.jsx`](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/App.jsx) (Chat app), [`src/workflow/nodes.py`](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py) (Retrieve passages), [`frontend/src/components/Exchange.jsx`](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Exchange.jsx) (Answer exchange)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["Chat app<br/>[App.jsx]"]
  node_threadrail["Thread list<br/>[ThreadRail.jsx]"]
  node_composer["Question composer<br/>[Composer.jsx]"]
  node_opening["Prompt suggestions<br/>[Opening.jsx]"]
  node_exchange["Answer exchange<br/>[Exchange.jsx]"]
  node_ledger["Progress ledger<br/>[MarginLedger.jsx]"]
  node_passages["Passage display<br/>[Passages.jsx]"]
  node_api["Streaming API client<br/>[api.js]"]
  node_sse["Event stream reader<br/>[sse.js]"]
end

subgraph group_service["API and agents"]
  node_backend["HTTP API<br/>[main.py]"]
  node_a2a["A2A agent<br/>[agent.py]"]
end

subgraph group_rag["Answer workflow"]
  node_graph["Workflow orchestrator<br/>[__init__.py]"]
  node_routing["Route and query<br/>[nodes.py]"]
  node_retrieval["Retrieve passages<br/>[nodes.py]"]
  node_relevance["Filter relevance<br/>[nodes.py]"]
  node_generation["Generate answer<br/>[nodes.py]"]
  node_validation["Ground and correct<br/>[nodes.py]"]
  node_memory["Conversation memory<br/>[nodes.py]"]
  node_state["Workflow state<br/>[state.py]"]
end

subgraph group_knowledge["Legal knowledge"]
  node_vector[("Chroma legal index")]
  node_web["Web search service"]
end

subgraph group_evaluation["Evaluation"]
  node_dataset["Dataset generation"]
  node_component_eval["Component evaluation"]
  node_pipeline_eval["Pipeline evaluation<br/>[eval.py]"]
end

node_user(("Questioner"))

node_user -->|"asks"| node_app
node_app -->|"renders"| node_threadrail
node_app -->|"renders"| node_composer
node_app -->|"renders"| node_opening
node_app -->|"renders"| node_exchange
node_exchange -->|"renders"| node_ledger
node_exchange -->|"renders"| node_passages
node_app -->|"requests answers"| node_api
node_api -->|"reads events"| node_sse
node_api -.->|"calls HTTP API"| node_backend
node_backend -->|"loads workflow"| node_graph
node_a2a -->|"runs workflow"| node_graph
node_graph -->|"dispatches stages"| node_routing
node_graph -->|"dispatches"| node_retrieval
node_graph -->|"dispatches"| node_relevance
node_graph -->|"dispatches"| node_generation
node_graph -->|"dispatches"| node_validation
node_graph -->|"dispatches"| node_memory
node_routing -->|"routes retrieval"| node_retrieval
node_retrieval -->|"searches"| node_vector
node_retrieval -->|"supplies passages"| node_relevance
node_relevance -->|"passes relevant context"| node_generation
node_relevance -->|"falls back to search"| node_web
node_routing -.->|"routes web search"| node_web
node_generation -->|"checks grounding"| node_validation
node_validation -->|"revises answer"| node_generation
node_validation -->|"passes accepted answer"| node_memory
node_memory -.->|"updates conversation"| node_state
node_graph -->|"uses shared state"| node_state
node_dataset -->|"prepares test set"| node_component_eval
node_component_eval -->|"extends evaluation"| node_pipeline_eval
node_pipeline_eval -->|"evaluates workflow"| node_graph

click node_app "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/App.jsx"
click node_threadrail "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/ThreadRail.jsx"
click node_composer "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Composer.jsx"
click node_opening "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Opening.jsx"
click node_exchange "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Exchange.jsx"
click node_ledger "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/MarginLedger.jsx"
click node_passages "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Passages.jsx"
click node_api "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/lib/api.js"
click node_sse "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/lib/sse.js"
click node_backend "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/Backend/main.py"
click node_a2a "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/A2A/agent.py"
click node_graph "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/__init__.py"
click node_routing "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py"
click node_retrieval "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py"
click node_relevance "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py"
click node_generation "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py"
click node_validation "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py"
click node_memory "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py"
click node_state "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/state.py"
click node_vector "https://github.com/pankaj-2708/self-rag-on-indian-constitution/tree/main/data/constitution_and_ipc.chroma"
click node_dataset "https://github.com/pankaj-2708/self-rag-on-indian-constitution/tree/main/evals/DatasetGeneration"
click node_component_eval "https://github.com/pankaj-2708/self-rag-on-indian-constitution/tree/main/evals/Component_level"
click node_pipeline_eval "https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/evals/PipelineLevel/eval.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,node_threadrail,node_composer,node_opening,node_exchange,node_ledger,node_passages,node_api,node_sse toneBlue
class node_backend,node_a2a toneAmber
class node_graph,node_routing,node_retrieval,node_relevance,node_generation,node_validation,node_memory,node_state toneMint
class node_vector,node_web toneRose
class node_dataset,node_component_eval,node_pipeline_eval,node_user toneIndigo
```

## Components

### Web client

- [Chat app](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Thread list](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/ThreadRail.jsx): `frontend/src/components/ThreadRail.jsx`
- [Question composer](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Composer.jsx): `frontend/src/components/Composer.jsx`
- [Prompt suggestions](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Opening.jsx): `frontend/src/components/Opening.jsx`
- [Answer exchange](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Exchange.jsx): `frontend/src/components/Exchange.jsx`
- [Progress ledger](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/MarginLedger.jsx): `frontend/src/components/MarginLedger.jsx`
- [Passage display](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/components/Passages.jsx): `frontend/src/components/Passages.jsx`
- [Streaming API client](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/lib/api.js): `frontend/src/lib/api.js`
- [Event stream reader](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/frontend/src/lib/sse.js): `frontend/src/lib/sse.js`

### API and agents

- [HTTP API](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/Backend/main.py): `Backend/main.py`
- [A2A agent](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/A2A/agent.py): `A2A/agent.py`

### Answer workflow

- [Workflow orchestrator](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/__init__.py): `src/workflow/__init__.py`
- [Route and query](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py): `src/workflow/nodes.py`
- [Retrieve passages](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py): `src/workflow/nodes.py`
- [Filter relevance](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py): `src/workflow/nodes.py`
- [Generate answer](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py): `src/workflow/nodes.py`
- [Ground and correct](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py): `src/workflow/nodes.py`
- [Conversation memory](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/nodes.py): `src/workflow/nodes.py`
- [Workflow state](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/src/workflow/state.py): `src/workflow/state.py`

### Legal knowledge

- [Chroma legal index](https://github.com/pankaj-2708/self-rag-on-indian-constitution/tree/main/data/constitution_and_ipc.chroma): `data/constitution_and_ipc.chroma`
- **Web search service**

### Evaluation

- [Dataset generation](https://github.com/pankaj-2708/self-rag-on-indian-constitution/tree/main/evals/DatasetGeneration): `evals/DatasetGeneration`
- [Component evaluation](https://github.com/pankaj-2708/self-rag-on-indian-constitution/tree/main/evals/Component_level): `evals/Component_level`
- [Pipeline evaluation](https://github.com/pankaj-2708/self-rag-on-indian-constitution/blob/main/evals/PipelineLevel/eval.py): `evals/PipelineLevel/eval.py`

### Other components

- **Questioner**

## Connections

- Questioner → Chat app: asks
- Chat app → Thread list: renders (evidence: `frontend/src/App.jsx`)
- Chat app → Question composer: renders (evidence: `frontend/src/App.jsx`)
- Chat app → Prompt suggestions: renders (evidence: `frontend/src/App.jsx`)
- Chat app → Answer exchange: renders (evidence: `frontend/src/App.jsx`)
- Answer exchange → Progress ledger: renders (evidence: `frontend/src/components/Exchange.jsx`)
- Answer exchange → Passage display: renders (evidence: `frontend/src/components/Exchange.jsx`)
- Chat app → Streaming API client: requests answers (evidence: `frontend/src/App.jsx`)
- Streaming API client → Event stream reader: reads events (evidence: `frontend/src/lib/api.js`)
- Streaming API client → HTTP API: calls HTTP API
- HTTP API → Workflow orchestrator: loads workflow (evidence: `Backend/main.py`)
- A2A agent → Workflow orchestrator: runs workflow (evidence: `A2A/agent.py`)
- Workflow orchestrator → Route and query: dispatches stages (evidence: `src/workflow/__init__.py`)
- Workflow orchestrator → Retrieve passages: dispatches (evidence: `src/workflow/__init__.py`)
- Workflow orchestrator → Filter relevance: dispatches (evidence: `src/workflow/__init__.py`)
- Workflow orchestrator → Generate answer: dispatches (evidence: `src/workflow/__init__.py`)
- Workflow orchestrator → Ground and correct: dispatches (evidence: `src/workflow/__init__.py`)
- Workflow orchestrator → Conversation memory: dispatches (evidence: `src/workflow/__init__.py`)
- Route and query → Retrieve passages: routes retrieval (evidence: `src/workflow/__init__.py`)
- Retrieve passages → Chroma legal index: searches (evidence: `src/workflow/nodes.py`)
- Retrieve passages → Filter relevance: supplies passages (evidence: `src/workflow/__init__.py`)
- Filter relevance → Generate answer: passes relevant context (evidence: `src/workflow/__init__.py`)
- Filter relevance → Web search service: falls back to search
- Route and query → Web search service: routes web search
- Generate answer → Ground and correct: checks grounding (evidence: `src/workflow/__init__.py`)
- Ground and correct → Generate answer: revises answer (evidence: `src/workflow/__init__.py`)
- Ground and correct → Conversation memory: passes accepted answer (evidence: `src/workflow/__init__.py`)
- Conversation memory → Workflow state: updates conversation (evidence: `src/workflow/nodes.py`)
- Workflow orchestrator → Workflow state: uses shared state (evidence: `src/workflow/__init__.py`)
- Dataset generation → Component evaluation: prepares test set (evidence: `README.md`)
- Component evaluation → Pipeline evaluation: extends evaluation (evidence: `README.md`)
- Pipeline evaluation → Workflow orchestrator: evaluates workflow (evidence: `evals/PipelineLevel/eval.py`)
