# akshatjoshi-afk/nyayachain architecture

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

- Interactive diagram: https://gitdiagram.com/akshatjoshi-afk/nyayachain
- Repository: https://github.com/akshatjoshi-afk/nyayachain

## Overview

NyayaChain is a legal-investigation case and evidence management prototype. Users authenticate, browse only cases they are authorized to access, and manage case documents; uploads are checked for duplicates or tampering, hash-chained, and may be enriched with OCR and AI-derived intelligence. Investigators can search and explore document text, entity relationships, timelines, and cited RAG answers; administrators manage access and audit ledger integrity. The graph includes documented integrations whose implementation was not sampled; those edges cite the README, and uncertain service wiring is omitted or marked optional.

Main entry points: [`backend/src/cases/cases.service.ts`](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/cases/cases.service.ts) (Case access), [`frontend/src/pages/DocumentsPage.tsx`](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/DocumentsPage.tsx) (Evidence workspace), [`backend/src/documents/documents.service.ts`](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/documents/documents.service.ts) (Document handling), [`backend/src/prisma/prisma.service.ts`](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/prisma/prisma.service.ts) (Application database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["Route shell<br/>[App.tsx]"]
  node_session["Tab session<br/>[AuthContext.tsx]"]
  node_login["Login screen<br/>[LoginPage.tsx]"]
  node_cases_ui["Case workspace<br/>[CasesPage.tsx]"]
  node_docs_ui["Evidence workspace<br/>[DocumentsPage.tsx]"]
  node_text_view["Document text"]
  node_graph_view["Relationship graph<br/>[CaseGraphView.tsx]"]
  node_timeline_view["Event timeline"]
  node_ask_ai["Case Q&amp;A<br/>[AskAiPanel.tsx]"]
end

subgraph group_api["Backend API"]
  node_auth_api["Authentication<br/>[auth.service.ts]"]
  node_cases_api["Case access<br/>[cases.service.ts]"]
  node_documents_api["Document handling"]
  node_audit_api["Audit verification<br/>[audit.service.ts]"]
  node_certificate["Statutory certificates"]
  node_database[("Application database<br/>[prisma.service.ts]")]
end

subgraph group_intelligence["Document intelligence"]
  node_ocr["OCR extraction<br/>[main.py]"]
  node_ai_entry["AI service API<br/>[main.py]"]
  node_rag[("Case document retrieval<br/>[rag_engine.py]")]
  node_llm["LLM processing<br/>[llm.py]"]
end

subgraph group_integrity["Evidence integrity"]
  node_ledger["Case hash chain"]
  node_blockchain["Root anchoring"]
end

node_investigator(("Investigator / admin"))
node_chain[("Local blockchain")]

node_investigator -->|"uses"| node_app
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_cases_ui
node_app -->|"routes to"| node_docs_ui
node_app -->|"checks session"| node_session
node_login -->|"sets session"| node_session
node_session -.->|"authenticates"| node_auth_api
node_cases_ui -.->|"loads cases"| node_cases_api
node_docs_ui -->|"checks case access"| node_cases_api
node_docs_ui -.->|"uploads and searches"| node_documents_api
node_docs_ui -->|"renders text"| node_text_view
node_docs_ui -->|"renders graph"| node_graph_view
node_docs_ui -->|"renders timeline"| node_timeline_view
node_docs_ui -->|"renders Q&amp;A"| node_ask_ai
node_auth_api -->|"reads and writes"| node_database
node_cases_api -->|"checks assignments"| node_database
node_cases_api -->|"loads entities"| node_database
node_documents_api -->|"stores evidence"| node_database
node_documents_api -->|"validates access"| node_cases_api
node_documents_api -.->|"requests extraction"| node_ocr
node_ocr -.->|"returns extracted text"| node_documents_api
node_documents_api -->|"chains document hashes"| node_ledger
node_documents_api -->|"anchors root"| node_blockchain
node_blockchain -.->|"records root"| node_chain
node_audit_api -->|"verifies ledger"| node_database
node_certificate -->|"reads evidence"| node_database
node_certificate -->|"checks case access"| node_cases_api
node_ai_entry -->|"queries documents"| node_rag
node_rag -->|"returns passages"| node_ai_entry
node_ai_entry -->|"processes questions"| node_llm
node_ask_ai -.->|"asks case questions"| node_ai_entry
node_graph_view -.->|"loads case graph"| node_cases_api
node_timeline_view -.->|"loads event timeline"| node_cases_api

click node_app "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/App.tsx"
click node_session "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/context/AuthContext.tsx"
click node_login "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/LoginPage.tsx"
click node_cases_ui "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/CasesPage.tsx"
click node_docs_ui "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/DocumentsPage.tsx"
click node_text_view "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/DocumentTextPanel.tsx"
click node_graph_view "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/CaseGraphView.tsx"
click node_timeline_view "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/CaseTimelineView.tsx"
click node_ask_ai "https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/AskAiPanel.tsx"
click node_auth_api "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/auth/auth.service.ts"
click node_cases_api "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/cases/cases.service.ts"
click node_documents_api "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/documents/documents.service.ts"
click node_audit_api "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/audit/audit.service.ts"
click node_certificate "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/certificate/certificate.service.ts"
click node_database "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/prisma/prisma.service.ts"
click node_ocr "https://github.com/akshatjoshi-afk/nyayachain/blob/main/ocr-service/main.py"
click node_ai_entry "https://github.com/akshatjoshi-afk/nyayachain/blob/main/ai-service/main.py"
click node_rag "https://github.com/akshatjoshi-afk/nyayachain/blob/main/ai-service/rag_engine.py"
click node_llm "https://github.com/akshatjoshi-afk/nyayachain/blob/main/ai-service/llm.py"
click node_ledger "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/documents/documents.service.ts"
click node_blockchain "https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/blockchain/blockchain.service.ts"

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_session,node_login,node_cases_ui,node_docs_ui,node_text_view,node_graph_view,node_timeline_view,node_ask_ai toneBlue
class node_auth_api,node_cases_api,node_documents_api,node_audit_api,node_certificate,node_database,node_chain toneAmber
class node_ocr,node_ai_entry,node_rag,node_llm toneMint
class node_ledger,node_blockchain toneRose
class node_investigator toneIndigo
```

## Components

### Web application

- [Route shell](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Tab session](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Login screen](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/LoginPage.tsx): `frontend/src/pages/LoginPage.tsx`
- [Case workspace](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/CasesPage.tsx): `frontend/src/pages/CasesPage.tsx`
- [Evidence workspace](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/pages/DocumentsPage.tsx): `frontend/src/pages/DocumentsPage.tsx`
- [Document text](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/DocumentTextPanel.tsx): `frontend/src/components/DocumentTextPanel.tsx`
- [Relationship graph](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/CaseGraphView.tsx): `frontend/src/components/CaseGraphView.tsx`
- [Event timeline](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/CaseTimelineView.tsx): `frontend/src/components/CaseTimelineView.tsx`
- [Case Q&A](https://github.com/akshatjoshi-afk/nyayachain/blob/main/frontend/src/components/AskAiPanel.tsx): `frontend/src/components/AskAiPanel.tsx`

### Backend API

- [Authentication](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/auth/auth.service.ts): `backend/src/auth/auth.service.ts`
- [Case access](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/cases/cases.service.ts): `backend/src/cases/cases.service.ts`
- [Document handling](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/documents/documents.service.ts): `backend/src/documents/documents.service.ts`
- [Audit verification](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/audit/audit.service.ts): `backend/src/audit/audit.service.ts`
- [Statutory certificates](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/certificate/certificate.service.ts): `backend/src/certificate/certificate.service.ts`
- [Application database](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/prisma/prisma.service.ts): `backend/src/prisma/prisma.service.ts`

### Document intelligence

- [OCR extraction](https://github.com/akshatjoshi-afk/nyayachain/blob/main/ocr-service/main.py): `ocr-service/main.py`
- [AI service API](https://github.com/akshatjoshi-afk/nyayachain/blob/main/ai-service/main.py): `ai-service/main.py`
- [Case document retrieval](https://github.com/akshatjoshi-afk/nyayachain/blob/main/ai-service/rag_engine.py): `ai-service/rag_engine.py`
- [LLM processing](https://github.com/akshatjoshi-afk/nyayachain/blob/main/ai-service/llm.py): `ai-service/llm.py`

### Evidence integrity

- [Case hash chain](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/documents/documents.service.ts): `backend/src/documents/documents.service.ts`
- [Root anchoring](https://github.com/akshatjoshi-afk/nyayachain/blob/main/backend/src/blockchain/blockchain.service.ts): `backend/src/blockchain/blockchain.service.ts`

### Other components

- **Investigator / admin**
- **Local blockchain**

## Connections

- Investigator / admin → Route shell: uses (evidence: `frontend/src/App.tsx`)
- Route shell → Login screen: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Case workspace: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Evidence workspace: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Tab session: checks session (evidence: `frontend/src/App.tsx`)
- Login screen → Tab session: sets session (evidence: `frontend/src/pages/LoginPage.tsx`)
- Tab session → Authentication: authenticates
- Case workspace → Case access: loads cases
- Evidence workspace → Case access: checks case access (evidence: `frontend/src/pages/DocumentsPage.tsx`)
- Evidence workspace → Document handling: uploads and searches
- Evidence workspace → Document text: renders text (evidence: `frontend/src/pages/DocumentsPage.tsx`)
- Evidence workspace → Relationship graph: renders graph (evidence: `frontend/src/pages/DocumentsPage.tsx`)
- Evidence workspace → Event timeline: renders timeline (evidence: `frontend/src/pages/DocumentsPage.tsx`)
- Evidence workspace → Case Q&A: renders Q&A (evidence: `frontend/src/pages/DocumentsPage.tsx`)
- Authentication → Application database: reads and writes (evidence: `backend/src/auth/auth.service.ts`)
- Case access → Application database: checks assignments (evidence: `backend/src/cases/cases.service.ts`)
- Case access → Application database: loads entities (evidence: `backend/src/cases/cases.service.ts`)
- Document handling → Application database: stores evidence (evidence: `backend/src/documents/documents.service.ts`)
- Document handling → Case access: validates access (evidence: `backend/src/documents/documents.service.ts`)
- Document handling → OCR extraction: requests extraction
- OCR extraction → Document handling: returns extracted text
- Document handling → Case hash chain: chains document hashes (evidence: `backend/src/documents/documents.service.ts`)
- Document handling → Root anchoring: anchors root (evidence: `backend/src/documents/documents.service.ts`)
- Root anchoring → Local blockchain: records root
- Audit verification → Application database: verifies ledger (evidence: `backend/src/audit/audit.service.ts`)
- Statutory certificates → Application database: reads evidence (evidence: `backend/src/certificate/certificate.service.ts`)
- Statutory certificates → Case access: checks case access (evidence: `backend/src/certificate/certificate.service.ts`)
- AI service API → Case document retrieval: queries documents (evidence: `ai-service/main.py`)
- Case document retrieval → AI service API: returns passages (evidence: `ai-service/main.py`)
- AI service API → LLM processing: processes questions (evidence: `ai-service/main.py`)
- Case Q&A → AI service API: asks case questions
- Relationship graph → Case access: loads case graph
- Event timeline → Case access: loads event timeline
