# antonymittul/data_analysis_agent architecture

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

- Interactive diagram: https://gitdiagram.com/antonymittul/data_analysis_agent
- Repository: https://github.com/antonymittul/data_analysis_agent

## Overview

#### 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: [`backend/app/main.py`](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/main.py) (FastAPI composition), [`backend/app/config/llm.py`](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/config/llm.py) (Gemini), [`backend/app/agents/router_agent.py`](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/router_agent.py) (Chat routing), [`backend/app/rag/ingestion.py`](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/ingestion.py) (Document ingestion and indexing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_entry["SPA entry and routes<br/>React/Vite<br/>[main.tsx]"]
  node_dashboard["Analytics dashboard<br/>page<br/>[DataDashboard.tsx]"]
  node_document_page["Document extraction and chat<br/>page"]
  node_api_client["Backend API client<br/>shared API config<br/>[api.ts]"]
end

subgraph group_backend["FastAPI service"]
  node_fastapi["FastAPI composition<br/>API entrypoint<br/>[main.py]"]
  node_dataset_routes["Dataset API routes<br/>route module<br/>[dataset_routes.py]"]
  node_document_routes["Document API routes<br/>route module<br/>[document_routes.py]"]
  node_request_schemas["Request contracts<br/>schemas<br/>[request_models.py]"]
  node_dataset_ingestion["Dataset validation and loading<br/>ingestion pipeline<br/>[dataset_loader.py]"]
  node_profiling["Dataset profiling<br/>metadata analysis<br/>[data_profiler.py]"]
  node_dashboard_engine["Visualization planning and engine<br/>dashboard generation"]
  node_insights["Gemini insights<br/>executive interpretation"]
  node_chat_orchestrator["Chat routing<br/>agent coordinator<br/>[router_agent.py]"]
  node_preprocessing["Intent preprocessing<br/>query rewrite"]
  node_structured_agent["Structured data agent<br/>analytics agent"]
end

subgraph group_rag["Document RAG"]
  node_rag_ingestion["Document ingestion and indexing<br/>RAG ingestion<br/>[ingestion.py]"]
  node_retrieval["Hybrid retrieval<br/>vector + BM25 fusion<br/>[retriever.py]"]
  node_rag_pipeline["Grounded answer pipeline<br/>RAG generation<br/>[pipeline.py]"]
end

subgraph group_runtime["AI and persistence"]
  node_gemini{{"Gemini<br/>external AI and embeddings<br/>[llm.py]"}}
  node_sqlite[("SQLite chat and document metadata<br/>persistent metadata<br/>[db.py]")]
  node_local_artifacts[("Uploads and FAISS indexes<br/>runtime disk artifacts<br/>[render.yaml]")]
  node_deployments["Independent deployments<br/>[vercel.json]"]
end

node_spa_entry -->|"renders"| node_dashboard
node_spa_entry -->|"renders"| node_document_page
node_dashboard -->|"uses"| node_api_client
node_document_page -->|"uses"| node_api_client
node_api_client -->|"HTTP API"| node_fastapi
node_fastapi -->|"mounts"| node_dataset_routes
node_fastapi -->|"mounts"| node_document_routes
node_fastapi -->|"validates with"| node_request_schemas
node_dataset_routes -->|"uploads"| node_dataset_ingestion
node_dataset_ingestion -->|"loaded dataset"| node_profiling
node_profiling -->|"metadata"| node_dashboard_engine
node_dashboard_engine -->|"chart context"| node_insights
node_insights -->|"interprets with"| node_gemini
node_fastapi -->|"chat requests"| node_chat_orchestrator
node_chat_orchestrator -->|"normalizes"| node_preprocessing
node_preprocessing -->|"dataset question"| node_structured_agent
node_structured_agent -->|"analyzes with"| node_gemini
node_document_routes -->|"document upload"| node_rag_ingestion
node_rag_ingestion -->|"writes indexes and files"| node_local_artifacts
node_rag_ingestion -->|"embeds with"| node_gemini
node_chat_orchestrator -->|"document question"| node_retrieval
node_retrieval -->|"retrieved chunks"| node_rag_pipeline
node_rag_pipeline -->|"grounded generation"| node_gemini
node_fastapi -->|"chat and document metadata"| node_sqlite
node_deployments -.->|"Vercel serves"| node_spa_entry
node_deployments -.->|"Render runs"| node_fastapi

click node_spa_entry "https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/main.tsx"
click node_dashboard "https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/app/pages/DataDashboard.tsx"
click node_document_page "https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/app/pages/DocumentExtraction.tsx"
click node_api_client "https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/app/lib/api.ts"
click node_fastapi "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/main.py"
click node_dataset_routes "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/routes/dataset_routes.py"
click node_document_routes "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/routes/document_routes.py"
click node_request_schemas "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/schemas/request_models.py"
click node_dataset_ingestion "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/dataset_loader.py"
click node_profiling "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/data_profiler.py"
click node_dashboard_engine "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/visualization_engine.py"
click node_insights "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/insight_generator.py"
click node_chat_orchestrator "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/router_agent.py"
click node_preprocessing "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/preprocessing_agent.py"
click node_structured_agent "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/structured_agent.py"
click node_rag_ingestion "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/ingestion.py"
click node_retrieval "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/retriever.py"
click node_rag_pipeline "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/pipeline.py"
click node_gemini "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/config/llm.py"
click node_sqlite "https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/memory/db.py"
click node_local_artifacts "https://github.com/antonymittul/data_analysis_agent/blob/main/render.yaml"
click node_deployments "https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/vercel.json"

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_spa_entry,node_dashboard,node_document_page,node_api_client toneBlue
class node_fastapi,node_dataset_routes,node_document_routes,node_request_schemas,node_dataset_ingestion,node_profiling,node_dashboard_engine,node_insights,node_chat_orchestrator,node_preprocessing,node_structured_agent toneAmber
class node_rag_ingestion,node_retrieval,node_rag_pipeline toneMint
class node_gemini,node_sqlite,node_local_artifacts,node_deployments toneRose
```

## Components

### React SPA

- [SPA entry and routes](https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/main.tsx): React/Vite · `frontend/src/main.tsx`
- [Analytics dashboard](https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/app/pages/DataDashboard.tsx): page · Filters, drill-down, and browser-side PDF export. · `frontend/src/app/pages/DataDashboard.tsx`
- [Document extraction and chat](https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/app/pages/DocumentExtraction.tsx): page · `frontend/src/app/pages/DocumentExtraction.tsx`
- [Backend API client](https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/src/app/lib/api.ts): shared API config · `frontend/src/app/lib/api.ts`

### FastAPI service

- [FastAPI composition](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/main.py): API entrypoint · Assembles upload, dataset, chat, document, dashboard, and evaluation routes. · `backend/app/main.py`
- [Dataset API routes](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/routes/dataset_routes.py): route module · `backend/app/routes/dataset_routes.py`
- [Document API routes](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/routes/document_routes.py): route module · `backend/app/routes/document_routes.py`
- [Request contracts](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/schemas/request_models.py): schemas · `backend/app/schemas/request_models.py`
- [Dataset validation and loading](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/dataset_loader.py): ingestion pipeline · `backend/app/services/dataset_loader.py`
- [Dataset profiling](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/data_profiler.py): metadata analysis · Produces metadata and semantic column understanding. · `backend/app/services/data_profiler.py`
- [Visualization planning and engine](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/visualization_engine.py): dashboard generation · Pre-aggregates data and produces charts. · `backend/app/services/visualization_engine.py`
- [Gemini insights](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/services/insight_generator.py): executive interpretation · `backend/app/services/insight_generator.py`
- [Chat routing](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/router_agent.py): agent coordinator · Routes normalized questions to structured or unstructured analysis. · `backend/app/agents/router_agent.py`
- [Intent preprocessing](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/preprocessing_agent.py): query rewrite · `backend/app/agents/preprocessing_agent.py`
- [Structured data agent](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/agents/structured_agent.py): analytics agent · `backend/app/agents/structured_agent.py`

### Document RAG

- [Document ingestion and indexing](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/ingestion.py): RAG ingestion · Loads, chunks, embeds, and creates a per-document FAISS index. · `backend/app/rag/ingestion.py`
- [Hybrid retrieval](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/retriever.py): vector + BM25 fusion · `backend/app/rag/retriever.py`
- [Grounded answer pipeline](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/rag/pipeline.py): RAG generation · Generates answers and citations from retrieved chunks. · `backend/app/rag/pipeline.py`

### AI and persistence

- [Gemini](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/config/llm.py): external AI and embeddings · Shared model dependency for chat, insights, and embeddings. · `backend/app/config/llm.py`
- [SQLite chat and document metadata](https://github.com/antonymittul/data_analysis_agent/blob/main/backend/app/memory/db.py): persistent metadata · `backend/app/memory/db.py`
- [Uploads and FAISS indexes](https://github.com/antonymittul/data_analysis_agent/blob/main/render.yaml): runtime disk artifacts · Can reset on Render's ephemeral disk. · `render.yaml`
- [Independent deployments](https://github.com/antonymittul/data_analysis_agent/blob/main/frontend/vercel.json): Vercel SPA + Render API · `frontend/vercel.json`

## Connections

- 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
