How shashikumar-ezhilarasu/talktoyourdata works
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: OrchestratorAgent.ts Intent, schema, orchestration · index.ts Express server · ingestion.worker.ts Ingestion worker · db.ts MongoDB
Components 21
Next.js frontend
Browser UI and client state.
- App Router
frontend/app/layout.tsx - Dataset workspace · Hosts dataset-specific analysis.
frontend/app/dashboard/[datasetId]/page.tsx - Client API and state
frontend/lib/api.ts - Chat and dashboard UI · Submits questions and presents answers.
frontend/components/dashboard/DashboardClient.tsx - Chart renderer
frontend/components/answer/ChartModule.tsx - Clerk token sync
frontend/components/ClerkTokenSync.tsx
Express API
Authenticated HTTP and event-stream boundary.
- Express server
backend/src/index.ts - Auth routes and middleware · Validates client identity before protected operations.
backend/src/middleware/auth.ts - Query controller
backend/src/controllers/query.controller.ts - Chat controller
backend/src/controllers/chat.controller.ts - SSE stream route
backend/src/routes/stream.routes.ts
Dataset pipeline
Asynchronous preparation and semantic indexing.
- Ingestion worker · Processes uploaded datasets asynchronously.
backend/src/workers/ingestion.worker.ts - Validation and profiling · Validates, scrubs PII, infers types, and profiles data.
backend/src/pipeline/ingestion/Validator.ts - Embedding worker
backend/src/workers/embedding.worker.ts - Schema embedder
backend/src/pipeline/ingestion/SchemaEmbedder.ts
Query intelligence
Intent-driven analysis and response production.
- Intent, schema, orchestration · Classifies intent, resolves schema, and selects analysis flow.
backend/src/pipeline/query/OrchestratorAgent.ts - Statistical engine
backend/src/pipeline/query/StatisticalEngine.ts - Event bus
backend/src/utils/eventBus.ts
State and services
Persistent state, queueing, and model providers.
- MongoDB · Stores datasets, chunks, queries, sessions, embeddings, and users.
backend/src/config/db.ts - Redis and BullMQ · Queues ingestion and embedding work.
backend/src/config/redis.ts - Google Gemini · Provides embeddings and natural-language generation.
backend/src/config/gemini.ts
Connections 25
- 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