How antonymittul/data_analysis_agent works
Purpose and Runtime Shape
DataSense AI is a split analytics and document-intelligence application. A React/Vite SPA accepts spreadsheet and document uploads; a FastAPI service analyzes datasets, runs Gemini-backed agents, and provides document RAG with persistent chat metadata. Entrypoints are backend/app/main.py and frontend/src/main.tsx; client routing begins at frontend/src/app/routes.ts.
Frontend Application Boundary
The SPA exposes two principal workflows: dashboard analytics and document extraction/chat. Pages coordinate API calls and render results, while shared API configuration isolates the backend URL.
• frontend/src/app/pages/DataDashboard.tsx
• frontend/src/app/pages/DocumentExtraction.tsx
• frontend/src/app/lib/api.ts
Dashboard interactions include chart filtering/drill-down and browser-only PDF export; export avoids another backend data transfer.
• frontend/src/app/lib/exportPdf.ts
• frontend/src/app/components/dashboard/DashboardLayout.tsx
FastAPI API Composition
main.py assembles route modules for upload, datasets, data chat, document chat, dashboard analysis, and evaluation. Routes form the public boundary between the SPA and backend workflows, with request contracts in schemas.
• backend/app/main.py
• backend/app/routes/dataset_routes.py
• backend/app/routes/document_routes.py
• backend/app/schemas/request_models.py
Dataset Analytics Pipeline
CSV/Excel uploads pass through validation and loading, then profiling produces metadata and semantic column understanding. Visualization planning/engine stages pre-aggregate and produce dashboard charts; insight generation uses Gemini for executive interpretation and the predictor supports forecast-oriented analysis.
• backend/app/services/file_validator.py
• backend/app/services/dataset_loader.py
• backend/app/services/data_profiler.py
• backend/app/services/visualization_planner.py
• backend/app/services/visualization_engine.py
• backend/app/services/insight_generator.py
Agent-Orchestrated Querying
Agent routing distinguishes structured dataset questions from unstructured document questions. A preprocessing/query-rewrite layer normalizes user intent before specialized agents execute retrieval or data analysis; chat routing coordinates the response path.
• backend/app/agents/router_agent.py
• backend/app/agents/preprocessing_agent.py
• backend/app/agents/structured_agent.py
• backend/app/agents/unstructured_agent.py
• backend/app/agents/data_assistant_agent.py
Document RAG and Citation Flow
Document ingestion loads supported formats, chunks content, embeds it, and creates a per-document FAISS index. Retrieval combines vector similarity with BM25/rank fusion, then generation produces grounded answers and citations from retrieved chunks.
• backend/app/rag/ingestion.py
• backend/app/rag/loaders.py
• backend/app/rag/chunking.py
• backend/app/rag/vector_store.py
• backend/app/rag/retriever.py
• backend/app/rag/pipeline.py
State, AI, and Deployment Dependencies
Gemini is the shared external AI dependency for chat and embeddings, centralized by configuration. SQLite stores chat sessions/messages and document metadata; FAISS indexes and uploaded files are runtime disk artifacts. The backend runs as Uvicorn/FastAPI on Render, while the SPA deploys independently to Vercel; Render’s ephemeral disk means indexes and local state can reset without persistent storage.
• backend/app/config/llm.py
• backend/app/config/settings.py
• backend/app/memory/db.py
• backend/app/memory/chat_memory.py
• render.yaml
• frontend/vercel.json
Main entry points: main.py FastAPI composition · llm.py Gemini · router_agent.py Chat routing · ingestion.py Document ingestion and indexing
Components 22
React SPA
- SPA entry and routes
frontend/src/main.tsx - Analytics dashboard · Filters, drill-down, and browser-side PDF export.
frontend/src/app/pages/DataDashboard.tsx - Document extraction and chat
frontend/src/app/pages/DocumentExtraction.tsx - Backend API client
frontend/src/app/lib/api.ts
FastAPI service
- FastAPI composition · Assembles upload, dataset, chat, document, dashboard, and evaluation routes.
backend/app/main.py - Dataset API routes
backend/app/routes/dataset_routes.py - Document API routes
backend/app/routes/document_routes.py - Request contracts
backend/app/schemas/request_models.py - Dataset validation and loading
backend/app/services/dataset_loader.py - Dataset profiling · Produces metadata and semantic column understanding.
backend/app/services/data_profiler.py - Visualization planning and engine · Pre-aggregates data and produces charts.
backend/app/services/visualization_engine.py - Gemini insights
backend/app/services/insight_generator.py - Chat routing · Routes normalized questions to structured or unstructured analysis.
backend/app/agents/router_agent.py - Intent preprocessing
backend/app/agents/preprocessing_agent.py - Structured data agent
backend/app/agents/structured_agent.py
Document RAG
- Document ingestion and indexing · Loads, chunks, embeds, and creates a per-document FAISS index.
backend/app/rag/ingestion.py - Hybrid retrieval
backend/app/rag/retriever.py - Grounded answer pipeline · Generates answers and citations from retrieved chunks.
backend/app/rag/pipeline.py
AI and persistence
- Gemini · Shared model dependency for chat, insights, and embeddings.
backend/app/config/llm.py - SQLite chat and document metadata
backend/app/memory/db.py - Uploads and FAISS indexes · Can reset on Render's ephemeral disk.
render.yaml - Independent deployments
frontend/vercel.json
Connections 26
- SPA entry and routes → Analytics dashboard: renders
- SPA entry and routes → Document extraction and chat: renders
- Analytics dashboard → Backend API client: uses
- Document extraction and chat → Backend API client: uses
- Backend API client → FastAPI composition: HTTP API
- FastAPI composition → Dataset API routes: mounts
- FastAPI composition → Document API routes: mounts
- FastAPI composition → Request contracts: validates with
- Dataset API routes → Dataset validation and loading: uploads
- Dataset validation and loading → Dataset profiling: loaded dataset
- Dataset profiling → Visualization planning and engine: metadata
- Visualization planning and engine → Gemini insights: chart context
- Gemini insights → Gemini: interprets with
- FastAPI composition → Chat routing: chat requests
- Chat routing → Intent preprocessing: normalizes
- Intent preprocessing → Structured data agent: dataset question
- Structured data agent → Gemini: analyzes with
- Document API routes → Document ingestion and indexing: document upload
- Document ingestion and indexing → Uploads and FAISS indexes: writes indexes and files
- Document ingestion and indexing → Gemini: embeds with
- Chat routing → Hybrid retrieval: document question
- Hybrid retrieval → Grounded answer pipeline: retrieved chunks
- Grounded answer pipeline → Gemini: grounded generation
- FastAPI composition → SQLite chat and document metadata: chat and document metadata
- Independent deployments → SPA entry and routes: Vercel serves
- Independent deployments → FastAPI composition: Render runs