# sunil8521/nyayaai architecture

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

- Interactive diagram: https://gitdiagram.com/sunil8521/nyayaai
- Repository: https://github.com/sunil8521/nyayaai

## Overview

NyayaAI is a legal research assistant for Indian legal materials, with chat-based research and a separate legal-document ingestion hub. Users ask questions through the chat UI; the backend chat controller invokes a LangGraph workflow, with chat history and agent checkpoints managed alongside MongoDB-backed chat records. For the knowledge base, users can preview and sync Drive PDFs or upload files; ingestion queues processing and indexes document chunks for retrieval. The README also describes legal drafting and Indian case-law/statute access. Workflow and processor internals are represented from the documented architecture and tree; their wiring was not sampled.

Main entry points: [`backend/src/langgraph/langgraph.controller.ts`](https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/langgraph.controller.ts) (Chat controller), [`backend/src/ingestion/ingestion.controller.ts`](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.controller.ts) (Ingestion controller), [`backend/src/ingestion/ingestion.processor.ts`](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.processor.ts) (Document processor), [`backend/src/qdrant/qdrant.service.ts`](https://github.com/sunil8521/nyayaai/blob/main/backend/src/qdrant/qdrant.service.ts) (Vector search service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User Experience"]
  node_chat_pages["Chat pages<br/>[page.tsx]"]
  node_chat_ui["Chat interface<br/>[AskContainer.tsx]"]
  node_chat_api["Chat API client<br/>[chat.ts]"]
  node_ingestion_ui["Ingestion dashboard"]
  node_ingestion_api["Ingestion API client<br/>[ingestion.ts]"]
end

subgraph group_chat["Legal Research"]
  node_chat_controller["Chat controller"]
  node_workflow["Agent workflow"]
  node_legal_tools["Legal tools<br/>[tools.service.ts]"]
  node_chat_store["Chat records<br/>[chat.schema.ts]"]
  node_message_store["Message records<br/>[message.schema.ts]"]
end

subgraph group_ingest["Knowledge Ingestion"]
  node_ingestion_controller["Ingestion controller"]
  node_drive_service["Drive connector"]
  node_ingestion_queue["Processing queue"]
  node_processor["Document processor"]
  node_chunking["Chunking<br/>[chunking.util.ts]"]
  node_embedding["Embedding service"]
  node_ingested_docs["Ingestion records"]
end

subgraph group_data["Persistence and Retrieval"]
  node_qdrant_service["Vector search service<br/>[qdrant.service.ts]"]
  node_mongo[("MongoDB")]
  node_qdrant[("Qdrant")]
end

node_legal_user(("Legal user"))
node_drive["Google Drive"]
node_embedding_server["Embedding server"]

node_legal_user -->|"asks questions"| node_chat_pages
node_chat_pages -->|"renders"| node_chat_ui
node_chat_ui -->|"sends messages"| node_chat_api
node_chat_api -->|"calls chat routes"| node_chat_controller
node_chat_controller -->|"executes workflow"| node_workflow
node_chat_controller -->|"reads and creates"| node_chat_store
node_chat_controller -->|"reads history"| node_message_store
node_workflow -->|"uses tools"| node_legal_tools
node_chat_controller -->|"persists chat records"| node_mongo
node_legal_user -->|"manages documents"| node_ingestion_ui
node_ingestion_ui -->|"requests ingestion"| node_ingestion_api
node_ingestion_api -->|"calls ingestion routes"| node_ingestion_controller
node_ingestion_controller -->|"lists Drive PDFs"| node_drive_service
node_drive_service -->|"fetches files"| node_drive
node_ingestion_controller -->|"tracks status"| node_ingested_docs
node_ingestion_controller -->|"reads and writes records"| node_mongo
node_ingestion_controller -->|"queues documents"| node_ingestion_queue
node_ingestion_queue -->|"dispatches jobs"| node_processor
node_processor -->|"chunks documents"| node_chunking
node_processor -->|"requests vectors"| node_embedding
node_embedding -->|"requests embeddings"| node_embedding_server
node_processor -->|"indexes chunks"| node_qdrant_service
node_qdrant_service -->|"stores and searches vectors"| node_qdrant
node_legal_tools -->|"retrieves legal chunks"| node_qdrant_service
node_qdrant_service -.->|"reranks results"| node_embedding

click node_chat_pages "https://github.com/sunil8521/nyayaai/blob/main/client/app/ask/page.tsx"
click node_chat_ui "https://github.com/sunil8521/nyayaai/blob/main/client/components/chat/AskContainer.tsx"
click node_chat_api "https://github.com/sunil8521/nyayaai/blob/main/client/lib/api/chat.ts"
click node_ingestion_ui "https://github.com/sunil8521/nyayaai/blob/main/client/components/ingestion/IngestionDashboard.tsx"
click node_ingestion_api "https://github.com/sunil8521/nyayaai/blob/main/client/lib/api/ingestion.ts"
click node_chat_controller "https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/langgraph.controller.ts"
click node_workflow "https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/workflow.service.ts"
click node_legal_tools "https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/tools.service.ts"
click node_chat_store "https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/schemas/chat.schema.ts"
click node_message_store "https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/schemas/message.schema.ts"
click node_ingestion_controller "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.controller.ts"
click node_drive_service "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/google-drive.service.ts"
click node_ingestion_queue "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.module.ts"
click node_processor "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.processor.ts"
click node_chunking "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/chunking.util.ts"
click node_embedding "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/embedding.service.ts"
click node_ingested_docs "https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/schemas/ingested-document.schema.ts"
click node_qdrant_service "https://github.com/sunil8521/nyayaai/blob/main/backend/src/qdrant/qdrant.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_chat_pages,node_chat_ui,node_chat_api,node_ingestion_ui,node_ingestion_api,node_legal_user toneBlue
class node_chat_controller,node_workflow,node_legal_tools,node_chat_store,node_message_store toneAmber
class node_ingestion_controller,node_drive_service,node_ingestion_queue,node_processor,node_chunking,node_embedding,node_ingested_docs,node_embedding_server toneMint
class node_qdrant_service,node_mongo,node_qdrant toneRose
class node_drive toneIndigo
```

## Components

### User Experience

- [Chat pages](https://github.com/sunil8521/nyayaai/blob/main/client/app/ask/page.tsx): `client/app/ask/page.tsx`
- [Chat interface](https://github.com/sunil8521/nyayaai/blob/main/client/components/chat/AskContainer.tsx): `client/components/chat/AskContainer.tsx`
- [Chat API client](https://github.com/sunil8521/nyayaai/blob/main/client/lib/api/chat.ts): `client/lib/api/chat.ts`
- [Ingestion dashboard](https://github.com/sunil8521/nyayaai/blob/main/client/components/ingestion/IngestionDashboard.tsx): `client/components/ingestion/IngestionDashboard.tsx`
- [Ingestion API client](https://github.com/sunil8521/nyayaai/blob/main/client/lib/api/ingestion.ts): `client/lib/api/ingestion.ts`

### Legal Research

- [Chat controller](https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/langgraph.controller.ts): `backend/src/langgraph/langgraph.controller.ts`
- [Agent workflow](https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/workflow.service.ts): `backend/src/langgraph/workflow.service.ts`
- [Legal tools](https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/tools.service.ts): `backend/src/langgraph/tools.service.ts`
- [Chat records](https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/schemas/chat.schema.ts): `backend/src/langgraph/schemas/chat.schema.ts`
- [Message records](https://github.com/sunil8521/nyayaai/blob/main/backend/src/langgraph/schemas/message.schema.ts): `backend/src/langgraph/schemas/message.schema.ts`

### Knowledge Ingestion

- [Ingestion controller](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.controller.ts): `backend/src/ingestion/ingestion.controller.ts`
- [Drive connector](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/google-drive.service.ts): `backend/src/ingestion/google-drive.service.ts`
- [Processing queue](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.module.ts): `backend/src/ingestion/ingestion.module.ts`
- [Document processor](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/ingestion.processor.ts): `backend/src/ingestion/ingestion.processor.ts`
- [Chunking](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/chunking.util.ts): `backend/src/ingestion/chunking.util.ts`
- [Embedding service](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/embedding.service.ts): `backend/src/ingestion/embedding.service.ts`
- [Ingestion records](https://github.com/sunil8521/nyayaai/blob/main/backend/src/ingestion/schemas/ingested-document.schema.ts): `backend/src/ingestion/schemas/ingested-document.schema.ts`

### Persistence and Retrieval

- [Vector search service](https://github.com/sunil8521/nyayaai/blob/main/backend/src/qdrant/qdrant.service.ts): `backend/src/qdrant/qdrant.service.ts`
- **MongoDB**
- **Qdrant**

### Other components

- **Legal user**
- **Google Drive**
- **Embedding server**

## Connections

- Legal user → Chat pages: asks questions
- Chat pages → Chat interface: renders
- Chat interface → Chat API client: sends messages
- Chat API client → Chat controller: calls chat routes
- Chat controller → Agent workflow: executes workflow
- Chat controller → Chat records: reads and creates
- Chat controller → Message records: reads history
- Agent workflow → Legal tools: uses tools
- Chat controller → MongoDB: persists chat records
- Legal user → Ingestion dashboard: manages documents
- Ingestion dashboard → Ingestion API client: requests ingestion
- Ingestion API client → Ingestion controller: calls ingestion routes
- Ingestion controller → Drive connector: lists Drive PDFs
- Drive connector → Google Drive: fetches files
- Ingestion controller → Ingestion records: tracks status
- Ingestion controller → MongoDB: reads and writes records
- Ingestion controller → Processing queue: queues documents
- Processing queue → Document processor: dispatches jobs
- Document processor → Chunking: chunks documents
- Document processor → Embedding service: requests vectors
- Embedding service → Embedding server: requests embeddings
- Document processor → Vector search service: indexes chunks
- Vector search service → Qdrant: stores and searches vectors
- Legal tools → Vector search service: retrieves legal chunks
- Vector search service → Embedding service: reranks results
