# shashikumar-ezhilarasu/talktoyourdata architecture

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

- Interactive diagram: https://gitdiagram.com/shashikumar-ezhilarasu/talktoyourdata
- Repository: https://github.com/shashikumar-ezhilarasu/talktoyourdata

## Overview

#### Purpose and Entry Points
DataLens is a full-stack natural-language analytics system: users upload CSV/JSON datasets, then receive Gemini-generated insights, chart data, confidence, and persistent chat context. The backend process starts at `backend/src/index.ts`; the browser application uses Next.js App Router from `frontend/app/layout.tsx` and `frontend/app/page.tsx`. Dataset-specific analysis is served at `frontend/app/dashboard/[datasetId]/page.tsx`.

#### Frontend Application Boundary
The Next.js frontend owns authentication presentation, upload/dashboard navigation, query submission, SSE-driven progress, and chart rendering. API calls and client-side state are centralized in `frontend/lib/api.ts` and `frontend/lib/store.ts`. The dataset workspace composes dashboard and chat-facing UI from `frontend/components/dashboard/DashboardClient.tsx`, `frontend/components/chat/ChatInput.tsx`, and `frontend/components/answer/AnswerCard.tsx`; chart payloads are rendered through `frontend/components/answer/ChartModule.tsx` and `frontend/components/charts/BreakdownBarChart.tsx`.

#### HTTP API, Identity, and Persistence
Express routes separate auth, chat, dataset, query, and streaming concerns: `backend/src/routes/auth.routes.ts`, `backend/src/routes/query.routes.ts`, and `backend/src/routes/stream.routes.ts`. Controllers implement request-level orchestration, notably `backend/src/controllers/auth.controller.ts`, `backend/src/controllers/chat.controller.ts`, and `backend/src/controllers/query.controller.ts`. Authentication is enforced at the backend boundary by `backend/src/middleware/auth.ts`; the frontend includes Clerk integration components at `frontend/components/ClerkTokenSync.tsx` and `frontend/components/ClerkShow.tsx`.

MongoDB is the system of record, connected through `backend/src/config/db.ts`. Core persisted entities are datasets/chunks, queries, chat sessions, schema embeddings, and users: `backend/src/models/Dataset.model.ts`, `backend/src/models/DataChunk.model.ts`, `backend/src/models/Query.model.ts`, `backend/src/models/ChatSession.model.ts`, `backend/src/models/SchemaEmbedding.model.ts`, and `backend/src/models/User.model.ts`.

#### Dataset Ingestion and Embedding
Dataset processing is asynchronous when Redis/BullMQ is available, with fallback behavior implied by the Redis configuration boundary at `backend/src/config/redis.ts`. The ingestion worker is `backend/src/workers/ingestion.worker.ts`; it coordinates validation, PII removal, type inference, statistical profiling, and persisted chunks. Those stages are explicitly modularized in `backend/src/pipeline/ingestion/Validator.ts`, `backend/src/pipeline/ingestion/PIIScrubber.ts`, `backend/src/pipeline/ingestion/TypeInferencer.ts`, and `backend/src/pipeline/ingestion/StatProfiler.ts`.

Embedding generation is handled by `backend/src/workers/embedding.worker.ts` using Gemini configuration from `backend/src/config/gemini.ts`; schema embedding responsibilities reside in `backend/src/pipeline/ingestion/SchemaEmbedder.ts`. The resulting vectors and row chunks support later semantic retrieval.

#### Query Intelligence and Result Lifecycle
A submitted query enters `backend/src/controllers/query.controller.ts`, then is routed through an agent pipeline. `backend/src/pipeline/query/IntentClassifier.ts` derives analytical intent; `backend/src/pipeline/query/SchemaResolverAgent.ts` maps user language to dataset schema; and `backend/src/pipeline/query/OrchestratorAgent.ts` selects/control-flows specialized analysis. `backend/src/pipeline/query/StatisticalEngine.ts` is the deterministic analytical boundary, while intent-specific implementations live in `backend/src/pipeline/query/subagents/CompareSubAgent.ts`, `BreakdownSubAgent.ts`, `AnomalySubAgent.ts`, `SummarySubAgent.ts`, and `GeneralAgent.ts`.

The query pipeline combines stored dataset metadata/chunks, session history, Gemini model responses, and computed statistics into persisted `Query` and `ChatSession` state. It emits progress and final results through the event mechanism in `backend/src/utils/eventBus.ts`, exposed to clients via `backend/src/routes/stream.routes.ts`.

#### Runtime and External Services
The material runtime is Node.js/TypeScript across an Express backend and Next.js frontend. MongoDB stores application and analytical state; Redis supports queueing and worker execution; Google Gemini provides embeddings and natural-language generation. Environment templates are `backend/.env.example` and `frontend/.env.local.example`. Included sample inputs in `backend/samples/ml_dataset.csv` and `backend/samples/sales_demo.csv` support demonstration flows.

Main entry points: [`backend/src/pipeline/query/OrchestratorAgent.ts`](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/query/OrchestratorAgent.ts) (Intent, schema, orchestration), [`backend/src/index.ts`](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/index.ts) (Express server), [`backend/src/workers/ingestion.worker.ts`](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/workers/ingestion.worker.ts) (Ingestion worker), [`backend/src/config/db.ts`](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/db.ts) (MongoDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js frontend"]
  node_next_app["App Router<br/>Next.js entry<br/>[layout.tsx]"]
  node_dataset_workspace["Dataset workspace<br/>dashboard page<br/>[page.tsx]"]
  node_client_state_api["Client API and state<br/>client boundary<br/>[api.ts]"]
  node_chat_dashboard_ui["Chat and dashboard UI<br/>workspace UI"]
  node_chart_renderer["Chart renderer<br/>visualization<br/>[ChartModule.tsx]"]
  node_clerk_sync["Clerk token sync<br/>identity client<br/>[ClerkTokenSync.tsx]"]
end

subgraph group_api["Express API"]
  node_express_server["Express server<br/>backend entry<br/>[index.ts]"]
  node_auth_boundary["Auth routes and middleware<br/>identity boundary<br/>[auth.ts]"]
  node_query_controller["Query controller<br/>request orchestrator"]
  node_chat_controller["Chat controller<br/>session controller<br/>[chat.controller.ts]"]
  node_sse_stream["SSE stream route<br/>event delivery<br/>[stream.routes.ts]"]
end

subgraph group_ingestion["Dataset pipeline"]
  node_ingestion_worker["Ingestion worker<br/>BullMQ worker"]
  node_ingestion_stages["Validation and profiling<br/>ingestion stages<br/>[Validator.ts]"]
  node_embedding_worker["Embedding worker<br/>BullMQ worker"]
  node_schema_embedder["Schema embedder<br/>vectorization stage<br/>[SchemaEmbedder.ts]"]
end

subgraph group_query["Query intelligence"]
  node_query_agents["Intent, schema, orchestration<br/>agent pipeline"]
  node_statistical_engine["Statistical engine<br/>deterministic analysis"]
  node_event_bus["Event bus<br/>progress events<br/>[eventBus.ts]"]
end

subgraph group_data["State and services"]
  node_mongodb[("MongoDB<br/>system of record<br/>[db.ts]")]
  node_redis["Redis and BullMQ<br/>queue backend<br/>[redis.ts]"]
  node_gemini{{"Google Gemini<br/>AI provider<br/>[gemini.ts]"}}
end

node_next_app -->|"routes to"| node_dataset_workspace
node_dataset_workspace -->|"composes"| node_chat_dashboard_ui
node_chat_dashboard_ui -->|"renders chart payloads"| node_chart_renderer
node_chat_dashboard_ui -->|"uses"| node_client_state_api
node_clerk_sync -->|"supplies token"| node_client_state_api
node_client_state_api -->|"HTTP and SSE"| node_express_server
node_express_server -->|"protects routes"| node_auth_boundary
node_auth_boundary -->|"authorizes query"| node_query_controller
node_auth_boundary -->|"authorizes chat"| node_chat_controller
node_express_server -.->|"queues dataset work"| node_ingestion_worker
node_express_server -->|"serves events"| node_sse_stream
node_ingestion_worker -->|"runs"| node_ingestion_stages
node_ingestion_stages -->|"persists datasets and chunks"| node_mongodb
node_ingestion_worker -->|"consumes jobs"| node_redis
node_ingestion_worker -.->|"triggers indexing"| node_embedding_worker
node_embedding_worker -->|"runs"| node_schema_embedder
node_embedding_worker -->|"generates vectors"| node_gemini
node_schema_embedder -->|"stores embeddings"| node_mongodb
node_query_controller -->|"submits question"| node_query_agents
node_chat_controller -->|"loads session history"| node_mongodb
node_query_agents -->|"executes analysis"| node_statistical_engine
node_query_agents -->|"retrieves context and persists query"| node_mongodb
node_query_agents -->|"generates response"| node_gemini
node_query_agents -->|"emits progress and result"| node_event_bus
node_event_bus -->|"streams events"| node_sse_stream

click node_next_app "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/app/layout.tsx"
click node_dataset_workspace "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/app/dashboard/%5BdatasetId%5D/page.tsx"
click node_client_state_api "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/lib/api.ts"
click node_chat_dashboard_ui "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/components/dashboard/DashboardClient.tsx"
click node_chart_renderer "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/components/answer/ChartModule.tsx"
click node_clerk_sync "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/components/ClerkTokenSync.tsx"
click node_express_server "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/index.ts"
click node_auth_boundary "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/middleware/auth.ts"
click node_query_controller "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/controllers/query.controller.ts"
click node_chat_controller "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/controllers/chat.controller.ts"
click node_sse_stream "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/routes/stream.routes.ts"
click node_ingestion_worker "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/workers/ingestion.worker.ts"
click node_ingestion_stages "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/ingestion/Validator.ts"
click node_embedding_worker "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/workers/embedding.worker.ts"
click node_schema_embedder "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/ingestion/SchemaEmbedder.ts"
click node_query_agents "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/query/OrchestratorAgent.ts"
click node_statistical_engine "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/query/StatisticalEngine.ts"
click node_event_bus "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/utils/eventBus.ts"
click node_mongodb "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/db.ts"
click node_redis "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/redis.ts"
click node_gemini "https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/gemini.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_next_app,node_dataset_workspace,node_client_state_api,node_chat_dashboard_ui,node_chart_renderer,node_clerk_sync toneBlue
class node_express_server,node_auth_boundary,node_query_controller,node_chat_controller,node_sse_stream toneAmber
class node_ingestion_worker,node_ingestion_stages,node_embedding_worker,node_schema_embedder toneMint
class node_query_agents,node_statistical_engine,node_event_bus toneRose
class node_mongodb,node_redis,node_gemini toneIndigo
```

## Components

### Next.js frontend

Browser UI and client state.

- [App Router](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/app/layout.tsx): Next.js entry · `frontend/app/layout.tsx`
- [Dataset workspace](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/app/dashboard/%5BdatasetId%5D/page.tsx): dashboard page · Hosts dataset-specific analysis. · `frontend/app/dashboard/[datasetId]/page.tsx`
- [Client API and state](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/lib/api.ts): client boundary · `frontend/lib/api.ts`
- [Chat and dashboard UI](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/components/dashboard/DashboardClient.tsx): workspace UI · Submits questions and presents answers. · `frontend/components/dashboard/DashboardClient.tsx`
- [Chart renderer](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/components/answer/ChartModule.tsx): visualization · `frontend/components/answer/ChartModule.tsx`
- [Clerk token sync](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/frontend/components/ClerkTokenSync.tsx): identity client · `frontend/components/ClerkTokenSync.tsx`

### Express API

Authenticated HTTP and event-stream boundary.

- [Express server](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/index.ts): backend entry · `backend/src/index.ts`
- [Auth routes and middleware](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/middleware/auth.ts): identity boundary · Validates client identity before protected operations. · `backend/src/middleware/auth.ts`
- [Query controller](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/controllers/query.controller.ts): request orchestrator · `backend/src/controllers/query.controller.ts`
- [Chat controller](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/controllers/chat.controller.ts): session controller · `backend/src/controllers/chat.controller.ts`
- [SSE stream route](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/routes/stream.routes.ts): event delivery · `backend/src/routes/stream.routes.ts`

### Dataset pipeline

Asynchronous preparation and semantic indexing.

- [Ingestion worker](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/workers/ingestion.worker.ts): BullMQ worker · Processes uploaded datasets asynchronously. · `backend/src/workers/ingestion.worker.ts`
- [Validation and profiling](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/ingestion/Validator.ts): ingestion stages · Validates, scrubs PII, infers types, and profiles data. · `backend/src/pipeline/ingestion/Validator.ts`
- [Embedding worker](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/workers/embedding.worker.ts): BullMQ worker · `backend/src/workers/embedding.worker.ts`
- [Schema embedder](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/ingestion/SchemaEmbedder.ts): vectorization stage · `backend/src/pipeline/ingestion/SchemaEmbedder.ts`

### Query intelligence

Intent-driven analysis and response production.

- [Intent, schema, orchestration](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/query/OrchestratorAgent.ts): agent pipeline · Classifies intent, resolves schema, and selects analysis flow. · `backend/src/pipeline/query/OrchestratorAgent.ts`
- [Statistical engine](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/pipeline/query/StatisticalEngine.ts): deterministic analysis · `backend/src/pipeline/query/StatisticalEngine.ts`
- [Event bus](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/utils/eventBus.ts): progress events · `backend/src/utils/eventBus.ts`

### State and services

Persistent state, queueing, and model providers.

- [MongoDB](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/db.ts): system of record · Stores datasets, chunks, queries, sessions, embeddings, and users. · `backend/src/config/db.ts`
- [Redis and BullMQ](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/redis.ts): queue backend · Queues ingestion and embedding work. · `backend/src/config/redis.ts`
- [Google Gemini](https://github.com/shashikumar-ezhilarasu/talktoyourdata/blob/main/backend/src/config/gemini.ts): AI provider · Provides embeddings and natural-language generation. · `backend/src/config/gemini.ts`

## Connections

- App Router → Dataset workspace: routes to
- Dataset workspace → Chat and dashboard UI: composes
- Chat and dashboard UI → Chart renderer: renders chart payloads
- Chat and dashboard UI → Client API and state: uses
- Clerk token sync → Client API and state: supplies token
- Client API and state → Express server: HTTP and SSE
- Express server → Auth routes and middleware: protects routes
- Auth routes and middleware → Query controller: authorizes query
- Auth routes and middleware → Chat controller: authorizes chat
- Express server → Ingestion worker: queues dataset work
- Express server → SSE stream route: serves events
- Ingestion worker → Validation and profiling: runs
- Validation and profiling → MongoDB: persists datasets and chunks
- Ingestion worker → Redis and BullMQ: consumes jobs
- Ingestion worker → Embedding worker: triggers indexing
- Embedding worker → Schema embedder: runs
- Embedding worker → Google Gemini: generates vectors
- Schema embedder → MongoDB: stores embeddings
- Query controller → Intent, schema, orchestration: submits question
- Chat controller → MongoDB: loads session history
- Intent, schema, orchestration → Statistical engine: executes analysis
- Intent, schema, orchestration → MongoDB: retrieves context and persists query
- Intent, schema, orchestration → Google Gemini: generates response
- Intent, schema, orchestration → Event bus: emits progress and result
- Event bus → SSE stream route: streams events
