# naveen-thomas-george/nlp architecture

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

- Interactive diagram: https://gitdiagram.com/naveen-thomas-george/nlp
- Repository: https://github.com/naveen-thomas-george/nlp

## Overview

SportMind AI answers questions about sports participation, department records, policies, and statistics. A user logs in, submits a query, and receives a routed answer; ambiguous queries can pause for clarification and resume. The supervisor normalizes and classifies the query, extracts entities, decomposes it, then dispatches to SQL, document, analytics, cross-agent, or safe-decline handling. Document and SQL agents use model services; document processing also supports OCR. The UI displays results and can export CSV. Some subsystem links reflect explicit documentation or the source index; unsampled API-client wiring is left unverified.

Main entry points: [`backend/app/graph/nodes.py`](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/nodes.py) (Pipeline and dispatch nodes), [`backend/app/llm/router.py`](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/llm/router.py) (Model router), [`backend/app/agents/sql_agent.py`](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/sql_agent.py) (SQL agent), [`backend/app/api/routes.py`](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/api/routes.py) (HTTP routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_app_ui["Query UI<br/>[App.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and access"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_http_routes["HTTP routes<br/>[routes.py]"]
  node_auth["Demo authentication<br/>[auth.py]"]
  node_reporting["CSV reporting<br/>[reporting_agent.py]"]
end

subgraph group_orchestration["Query orchestration"]
  node_graph_run["Query entry and resume<br/>[run.py]"]
  node_graph_builder["Supervisor graph"]
  node_graph_nodes["Pipeline and dispatch nodes<br/>[nodes.py]"]
  node_graph_state["Query state<br/>[state.py]"]
end

subgraph group_agents["Answer agents"]
  node_sql_agent["SQL agent<br/>[sql_agent.py]"]
  node_document_agent["Document agent<br/>[document_agent.py]"]
  node_analytics_agent["Analytics agent<br/>[analytics_agent.py]"]
  node_schema_context["Schema context<br/>[schema_context.py]"]
  node_ocr["OCR processing<br/>[ocr_agent.py]"]
  node_ocr_preprocess["OCR preprocessing<br/>[preprocess.py]"]
end

subgraph group_services["NLP, models and data"]
  node_intent["Intent classifier<br/>[predict.py]"]
  node_intent_labels["Intent labels<br/>[labels.py]"]
  node_ner["Entity extraction<br/>[extractor.py]"]
  node_normalization["Query normalization<br/>[normalization.py]"]
  node_llm_router["Model router<br/>[router.py]"]
  node_db_session["Database sessions<br/>[session.py]"]
  node_db_models["Database models<br/>[models.py]"]
  node_db_base["ORM base<br/>[base.py]"]
  node_logging["Structured logging<br/>[logging_config.py]"]
end

node_user(("User"))
node_groq["Groq"]
node_gemini["Gemini"]
node_ollama["Ollama"]
node_database[("PostgreSQL database")]

node_user -->|"submits query"| node_app_ui
node_app_ui -->|"calls"| node_api_client
node_api_client -.->|"HTTP requests"| node_fastapi
node_fastapi -->|"mounts routes"| node_http_routes
node_http_routes -->|"checks access"| node_auth
node_http_routes -->|"invokes query"| node_graph_run
node_http_routes -->|"exports CSV"| node_reporting
node_graph_run -->|"builds graph"| node_graph_builder
node_graph_builder -->|"registers and routes"| node_graph_nodes
node_graph_builder -->|"uses state"| node_graph_state
node_graph_nodes -->|"reads and updates"| node_graph_state
node_graph_nodes -->|"normalizes query"| node_normalization
node_graph_nodes -->|"classifies intent"| node_intent
node_graph_nodes -->|"extracts entities"| node_ner
node_graph_nodes -->|"dispatches to"| node_sql_agent
node_graph_nodes -->|"dispatches to"| node_document_agent
node_graph_nodes -->|"dispatches to"| node_analytics_agent
node_graph_nodes -->|"decomposes query"| node_llm_router
node_graph_nodes -->|"calls for cross-agent"| node_document_agent
node_graph_nodes -->|"calls for cross-agent"| node_sql_agent
node_sql_agent -->|"uses schema context"| node_schema_context
node_sql_agent -->|"queries through"| node_db_session
node_sql_agent -->|"generates SQL with"| node_llm_router
node_document_agent -->|"uses OCR"| node_ocr
node_document_agent -->|"uses model"| node_llm_router
node_ocr -->|"preprocesses with"| node_ocr_preprocess
node_analytics_agent -->|"reads database"| node_db_session
node_intent -->|"uses labels"| node_intent_labels
node_db_models -->|"extends"| node_db_base
node_db_session -->|"connects to"| node_database
node_llm_router -->|"calls provider"| node_groq
node_llm_router -->|"falls back to"| node_gemini
node_llm_router -->|"falls back to"| node_ollama
node_fastapi -->|"configures"| node_logging

click node_app_ui "https://github.com/naveen-thomas-george/nlp/blob/main/frontend/src/App.tsx"
click node_api_client "https://github.com/naveen-thomas-george/nlp/blob/main/frontend/src/api.ts"
click node_fastapi "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/main.py"
click node_http_routes "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/api/routes.py"
click node_auth "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/core/auth.py"
click node_reporting "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/reporting_agent.py"
click node_graph_run "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/run.py"
click node_graph_builder "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/supervisor_graph.py"
click node_graph_nodes "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/nodes.py"
click node_graph_state "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/state.py"
click node_sql_agent "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/sql_agent.py"
click node_document_agent "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/document_agent.py"
click node_analytics_agent "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/analytics_agent.py"
click node_schema_context "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/schema_context.py"
click node_ocr "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/ocr/ocr_agent.py"
click node_ocr_preprocess "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/ocr/preprocess.py"
click node_intent "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/intent/predict.py"
click node_intent_labels "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/intent/labels.py"
click node_ner "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/ner/extractor.py"
click node_normalization "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/normalization.py"
click node_llm_router "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/llm/router.py"
click node_db_session "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/db/session.py"
click node_db_models "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/db/models.py"
click node_db_base "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/db/base.py"
click node_logging "https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/core/logging_config.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_ui,node_api_client,node_user toneBlue
class node_fastapi,node_http_routes,node_auth,node_reporting,node_database toneAmber
class node_graph_run,node_graph_builder,node_graph_nodes,node_graph_state toneMint
class node_sql_agent,node_document_agent,node_analytics_agent,node_schema_context,node_ocr,node_ocr_preprocess toneRose
class node_intent,node_intent_labels,node_ner,node_normalization,node_llm_router,node_db_session,node_db_models,node_db_base,node_logging,node_groq,node_gemini,node_ollama toneIndigo
```

## Components

### User interface

- [Query UI](https://github.com/naveen-thomas-george/nlp/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [API client](https://github.com/naveen-thomas-george/nlp/blob/main/frontend/src/api.ts): `frontend/src/api.ts`

### API and access

- [FastAPI app](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/main.py): `backend/app/main.py`
- [HTTP routes](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Demo authentication](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/core/auth.py): `backend/app/core/auth.py`
- [CSV reporting](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/reporting_agent.py): `backend/app/agents/reporting_agent.py`

### Query orchestration

- [Query entry and resume](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/run.py): `backend/app/graph/run.py`
- [Supervisor graph](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/supervisor_graph.py): `backend/app/graph/supervisor_graph.py`
- [Pipeline and dispatch nodes](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/nodes.py): `backend/app/graph/nodes.py`
- [Query state](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/graph/state.py): `backend/app/graph/state.py`

### Answer agents

- [SQL agent](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/sql_agent.py): `backend/app/agents/sql_agent.py`
- [Document agent](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/document_agent.py): `backend/app/agents/document_agent.py`
- [Analytics agent](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/analytics_agent.py): `backend/app/agents/analytics_agent.py`
- [Schema context](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/agents/schema_context.py): `backend/app/agents/schema_context.py`
- [OCR processing](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/ocr/ocr_agent.py): `backend/app/ocr/ocr_agent.py`
- [OCR preprocessing](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/ocr/preprocess.py): `backend/app/ocr/preprocess.py`

### NLP, models and data

- [Intent classifier](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/intent/predict.py): `backend/app/nlp/intent/predict.py`
- [Intent labels](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/intent/labels.py): `backend/app/nlp/intent/labels.py`
- [Entity extraction](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/ner/extractor.py): `backend/app/nlp/ner/extractor.py`
- [Query normalization](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/nlp/normalization.py): `backend/app/nlp/normalization.py`
- [Model router](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/llm/router.py): `backend/app/llm/router.py`
- [Database sessions](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/db/session.py): `backend/app/db/session.py`
- [Database models](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/db/models.py): `backend/app/db/models.py`
- [ORM base](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/db/base.py): `backend/app/db/base.py`
- [Structured logging](https://github.com/naveen-thomas-george/nlp/blob/main/backend/app/core/logging_config.py): `backend/app/core/logging_config.py`

### Other components

- **User**
- **Groq**
- **Gemini**
- **Ollama**
- **PostgreSQL database**

## Connections

- User → Query UI: submits query (evidence: `frontend/src/App.tsx`)
- Query UI → API client: calls (evidence: `frontend/src/App.tsx`)
- API client → FastAPI app: HTTP requests
- FastAPI app → HTTP routes: mounts routes (evidence: `backend/app/main.py`)
- HTTP routes → Demo authentication: checks access (evidence: `backend/app/api/routes.py`)
- HTTP routes → Query entry and resume: invokes query (evidence: `backend/app/api/routes.py`)
- HTTP routes → CSV reporting: exports CSV (evidence: `backend/app/api/routes.py`)
- Query entry and resume → Supervisor graph: builds graph (evidence: `backend/app/graph/run.py`)
- Supervisor graph → Pipeline and dispatch nodes: registers and routes (evidence: `backend/app/graph/supervisor_graph.py`)
- Supervisor graph → Query state: uses state (evidence: `backend/app/graph/supervisor_graph.py`)
- Pipeline and dispatch nodes → Query state: reads and updates (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Query normalization: normalizes query (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Intent classifier: classifies intent (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Entity extraction: extracts entities (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → SQL agent: dispatches to (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Document agent: dispatches to (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Analytics agent: dispatches to (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Model router: decomposes query (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → Document agent: calls for cross-agent (evidence: `backend/app/graph/nodes.py`)
- Pipeline and dispatch nodes → SQL agent: calls for cross-agent (evidence: `backend/app/graph/nodes.py`)
- SQL agent → Schema context: uses schema context (evidence: `backend/app/agents/sql_agent.py`)
- SQL agent → Database sessions: queries through (evidence: `backend/app/agents/sql_agent.py`)
- SQL agent → Model router: generates SQL with (evidence: `backend/app/agents/sql_agent.py`)
- Document agent → OCR processing: uses OCR (evidence: `backend/app/agents/document_agent.py`)
- Document agent → Model router: uses model (evidence: `backend/app/agents/document_agent.py`)
- OCR processing → OCR preprocessing: preprocesses with (evidence: `backend/app/ocr/ocr_agent.py`)
- Analytics agent → Database sessions: reads database (evidence: `backend/app/agents/analytics_agent.py`)
- Intent classifier → Intent labels: uses labels (evidence: `backend/app/nlp/intent/predict.py`)
- Database models → ORM base: extends (evidence: `backend/app/db/models.py`)
- Database sessions → PostgreSQL database: connects to (evidence: `backend/app/db/session.py`)
- Model router → Groq: calls provider (evidence: `backend/app/llm/router.py`)
- Model router → Gemini: falls back to (evidence: `backend/app/llm/router.py`)
- Model router → Ollama: falls back to (evidence: `backend/app/llm/router.py`)
- FastAPI app → Structured logging: configures (evidence: `backend/app/main.py`)
