# svmayurkaarthic2005/internship_nic architecture

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

- Interactive diagram: https://gitdiagram.com/svmayurkaarthic2005/internship_nic
- Repository: https://github.com/svmayurkaarthic2005/internship_nic

## Overview

SIS is a bilingual Tamil/English/Tanglish assistant for survey officers. The main path is officer login, then a chat request routed through the chat API and chatbot orchestrator: intent handling retrieves structured application data or uses agent/RAG grounding, and the response streams to the browser. Separate capabilities cover application and survey APIs, uploaded-document evidence, and document embedding ingestion. The chatbot implementation and several domain services were not excerpted; edges involving them rely on README descriptions or SOURCE INDEX references, not inspection of their full source.

Main entry points: [`backend/services/chatbot.py`](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/chatbot.py) (Chat orchestrator), [`backend/database.py`](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/database.py) (Database sessions), [`backend/routers/chat.py`](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/chat.py) (Chat endpoints), [`backend/services/rag.py`](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/rag.py) (Intent and RAG)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Officer experience"]
  node_browser["Web chat client<br/>[chat.js]"]
  node_browser_auth["Browser authentication<br/>[auth.js]"]
end

subgraph group_api["API and identity"]
  node_chat_api["Chat endpoints<br/>[chat.py]"]
  node_auth_api["Auth endpoints<br/>[auth.py]"]
  node_application_api["Application endpoints<br/>[applications.py]"]
  node_survey_api["Survey endpoints<br/>[survey.py]"]
  node_auth_service["JWT and jurisdiction<br/>[auth_service.py]"]
  node_auth_dependency["Officer authentication<br/>[dependencies.py]"]
  node_attachment_api["Attachment routes<br/>[chat.py]"]
end

subgraph group_assistant["Chat intelligence"]
  node_chatbot["Chat orchestrator<br/>[chatbot.py]"]
  node_rag["Intent and RAG<br/>[rag.py]"]
  node_fuzzy["Token matching<br/>[fuzzy.py]"]
  node_agent["Tool-calling agent<br/>[agent.py]"]
  node_domain_tools["Authorized domain tools<br/>[agent_tools.py]"]
  node_query_handlers["Structured query handlers<br/>[postgres.py]"]
  node_followup["Follow-up context"]
end

subgraph group_knowledge["Knowledge and evidence"]
  node_doc_extract["Document extraction<br/>[doc_extract.py]"]
  node_attachment_store[("Attachment evidence store")]
  node_embedding_ingest["Document ingestion<br/>[ingest.py]"]
  node_vector_store[("Vector retrieval<br/>[pgvector_store.py]")]
  node_embeddings["Embedding generation<br/>[embeddings.py]"]
end

subgraph group_data["Persistence"]
  node_orm[("Application data models<br/>[models.py]")]
  node_db_session["Database sessions<br/>[database.py]"]
end

node_officer(("Survey officer"))
node_ollama["Ollama LLM"]

node_officer -->|"signs in"| node_browser_auth
node_browser_auth -->|"submits login"| node_auth_api
node_auth_api -->|"creates token"| node_auth_service
node_auth_api -->|"queries officer"| node_db_session
node_auth_service -->|"resolves jurisdiction"| node_orm
node_browser -->|"streams chat"| node_chat_api
node_chat_api -->|"routes request"| node_chatbot
node_chat_api -->|"extracts uploads"| node_doc_extract
node_chat_api -->|"stores evidence"| node_attachment_store
node_chatbot -->|"processes intent"| node_rag
node_rag -->|"matches tokens"| node_fuzzy
node_chatbot -->|"fetches domain data"| node_query_handlers
node_chatbot -->|"falls back to agent"| node_agent
node_agent -.->|"calls tools"| node_domain_tools
node_chatbot -.->|"uses follow-up context"| node_followup
node_rag -->|"retrieves context"| node_vector_store
node_rag -->|"generates response"| node_ollama
node_embedding_ingest -->|"ingests documents"| node_vector_store
node_vector_store -->|"requests vectors"| node_embeddings
node_attachment_store -->|"uses extraction"| node_doc_extract
node_attachment_store -->|"embeds evidence"| node_embeddings
node_auth_dependency -->|"validates token"| node_auth_service
node_auth_dependency -->|"loads officer"| node_db_session
node_application_api -->|"requires officer"| node_auth_dependency
node_survey_api -->|"requires officer"| node_auth_dependency
node_application_api -->|"uses session"| node_db_session
node_survey_api -->|"uses session"| node_db_session
node_db_session -->|"persists records"| node_orm

click node_browser "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/frontend/js/chat.js"
click node_browser_auth "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/frontend/js/auth.js"
click node_chat_api "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/chat.py"
click node_auth_api "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/auth.py"
click node_application_api "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/applications.py"
click node_survey_api "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/survey.py"
click node_auth_service "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/auth_service.py"
click node_auth_dependency "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/dependencies.py"
click node_chatbot "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/chatbot.py"
click node_rag "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/rag.py"
click node_fuzzy "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/utils/fuzzy.py"
click node_agent "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/agent.py"
click node_domain_tools "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/agent_tools.py"
click node_query_handlers "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/postgres.py"
click node_followup "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/followup_context.py"
click node_attachment_api "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/chat.py"
click node_doc_extract "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/doc_extract.py"
click node_attachment_store "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/attachment_store.py"
click node_embedding_ingest "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/ingest.py"
click node_vector_store "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/pgvector_store.py"
click node_embeddings "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/embeddings.py"
click node_orm "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/models.py"
click node_db_session "https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/database.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_browser,node_browser_auth toneBlue
class node_chat_api,node_auth_api,node_application_api,node_survey_api,node_auth_service,node_auth_dependency,node_attachment_api toneAmber
class node_chatbot,node_rag,node_fuzzy,node_agent,node_domain_tools,node_query_handlers,node_followup toneMint
class node_doc_extract,node_attachment_store,node_embedding_ingest,node_vector_store,node_embeddings toneRose
class node_orm,node_db_session,node_officer,node_ollama toneIndigo
```

## Components

### Officer experience

- [Web chat client](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/frontend/js/chat.js): `frontend/js/chat.js`
- [Browser authentication](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/frontend/js/auth.js): `frontend/js/auth.js`

### API and identity

- [Chat endpoints](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/chat.py): `backend/routers/chat.py`
- [Auth endpoints](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/auth.py): `backend/routers/auth.py`
- [Application endpoints](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/applications.py): `backend/routers/applications.py`
- [Survey endpoints](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/survey.py): `backend/routers/survey.py`
- [JWT and jurisdiction](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/auth_service.py): `backend/services/auth_service.py`
- [Officer authentication](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/dependencies.py): `backend/dependencies.py`
- [Attachment routes](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/routers/chat.py): `backend/routers/chat.py`

### Chat intelligence

- [Chat orchestrator](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/chatbot.py): `backend/services/chatbot.py`
- [Intent and RAG](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/rag.py): `backend/services/rag.py`
- [Token matching](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/utils/fuzzy.py): `backend/utils/fuzzy.py`
- [Tool-calling agent](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/agent.py): `backend/services/agent.py`
- [Authorized domain tools](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/agent_tools.py): `backend/services/agent_tools.py`
- [Structured query handlers](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/postgres.py): `backend/services/postgres.py`
- [Follow-up context](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/followup_context.py): `backend/services/followup_context.py`

### Knowledge and evidence

- [Document extraction](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/doc_extract.py): `backend/services/doc_extract.py`
- [Attachment evidence store](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/attachment_store.py): `backend/services/attachment_store.py`
- [Document ingestion](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/ingest.py): `backend/ingest.py`
- [Vector retrieval](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/pgvector_store.py): `backend/services/pgvector_store.py`
- [Embedding generation](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/services/embeddings.py): `backend/services/embeddings.py`

### Persistence

- [Application data models](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/models.py): `backend/models.py`
- [Database sessions](https://github.com/svmayurkaarthic2005/internship_nic/blob/main/backend/database.py): `backend/database.py`

### Other components

- **Survey officer**
- **Ollama LLM**

## Connections

- Survey officer → Browser authentication: signs in (evidence: `README.md`)
- Browser authentication → Auth endpoints: submits login (evidence: `README.md`)
- Auth endpoints → JWT and jurisdiction: creates token (evidence: `backend/routers/auth.py`)
- Auth endpoints → Database sessions: queries officer (evidence: `backend/routers/auth.py`)
- JWT and jurisdiction → Application data models: resolves jurisdiction (evidence: `backend/services/auth_service.py`)
- Web chat client → Chat endpoints: streams chat (evidence: `README.md`)
- Chat endpoints → Chat orchestrator: routes request (evidence: `README.md`)
- Chat endpoints → Document extraction: extracts uploads (evidence: `backend/routers/chat.py`)
- Chat endpoints → Attachment evidence store: stores evidence (evidence: `backend/routers/chat.py`)
- Chat orchestrator → Intent and RAG: processes intent (evidence: `README.md`)
- Intent and RAG → Token matching: matches tokens (evidence: `backend/services/rag.py`)
- Chat orchestrator → Structured query handlers: fetches domain data (evidence: `README.md`)
- Chat orchestrator → Tool-calling agent: falls back to agent (evidence: `README.md`)
- Tool-calling agent → Authorized domain tools: calls tools
- Chat orchestrator → Follow-up context: uses follow-up context
- Intent and RAG → Vector retrieval: retrieves context (evidence: `backend/services/rag.py`)
- Intent and RAG → Ollama LLM: generates response (evidence: `README.md`)
- Document ingestion → Vector retrieval: ingests documents (evidence: `backend/ingest.py`)
- Vector retrieval → Embedding generation: requests vectors (evidence: `backend/services/pgvector_store.py`)
- Attachment evidence store → Document extraction: uses extraction (evidence: `backend/services/attachment_store.py`)
- Attachment evidence store → Embedding generation: embeds evidence (evidence: `backend/services/attachment_store.py`)
- Officer authentication → JWT and jurisdiction: validates token (evidence: `backend/dependencies.py`)
- Officer authentication → Database sessions: loads officer (evidence: `backend/dependencies.py`)
- Application endpoints → Officer authentication: requires officer (evidence: `backend/routers/applications.py`)
- Survey endpoints → Officer authentication: requires officer (evidence: `backend/routers/survey.py`)
- Application endpoints → Database sessions: uses session (evidence: `backend/routers/applications.py`)
- Survey endpoints → Database sessions: uses session (evidence: `backend/routers/survey.py`)
- Database sessions → Application data models: persists records (evidence: `backend/database.py`)
