How huntisonn/datapilot works
Purpose and Entry Points
DataPilot is a natural-language analytics system: users connect data, ask questions, and receive validated, PII-redacted narrative and chart responses. The backend FastAPI entry point is datapilot/api/main.py; primary HTTP surfaces are dataset connection/upload and query execution in datapilot/api/routes/dataset_routes.py and datapilot/api/routes/query_routes.py. The React/Vite client starts at frontend/src/main.tsx and composes the product in frontend/src/App.tsx.
API, Session, and Dataset Boundary
The API is the boundary between browser requests and the agent/data pipeline. Dataset routes establish access to CSV, SQL, or NoSQL sources; query routes submit analytical questions. Request throttling is centralized in datapilot/api/middleware/rate_limiter.py. Conversation-scoped context is retained separately from data access in datapilot/foundation/memory/conversation_memory.py, enabling follow-up questions without exposing raw database mechanics to the UI.
Data Connectivity and Execution
A connector abstraction selects source-specific implementations through datapilot/foundation/connectors/connector_factory.py, with SQL/PostgreSQL, MongoDB, and CSV/DuckDB paths in datapilot/foundation/connectors/sql_connector.py, datapilot/foundation/connectors/nosql_connector.py, and datapilot/foundation/connectors/csv_connector.py. This is a read-oriented execution boundary: agents generate SQL or Mongo aggregation, while connectors execute against the configured source and return results.
Semantic Layer and Reuse
Before query generation, business language is mapped to physical schemas and derived metrics. The semantic model, metric registry, and automatic profiling live in datapilot/foundation/semantic_layer/models.py, datapilot/foundation/semantic_layer/metric_registry.py, and datapilot/foundation/semantic_layer/auto_profiler.py. Local embedding/synonym matching supports semantic resolution; caches reduce repeated semantic and query work via datapilot/foundation/cache/embedding_cache.py and datapilot/foundation/cache/query_cache.py.
Agent Pipeline and Orchestration
CrewAI-based orchestration is centered on datapilot/crews/orchestrator.py and datapilot/crews/crew_factory.py. Fast execution uses the compact phase pipeline in datapilot/crews/phase1_crew.py; deep analysis uses the broader financial crew in datapilot/crews/financial_crew.py. Core stages are routing, schema resolution, query building, optional change/comparison/breakdown/summary analysis, validation, privacy filtering, and narration. Agent responsibilities are concretely defined under datapilot/agents/definitions/router_agent.py, datapilot/agents/definitions/query_builder_agent.py, and datapilot/agents/definitions/validator_agent.py.
Trust and Presentation Boundary
Agents invoke bounded capabilities rather than directly owning infrastructure: semantic lookup, SQL execution, validation/statistics, PII detection, and visualization are in datapilot/agents/tools/semantic_tools.py, datapilot/agents/tools/sql_tools.py, and datapilot/agents/tools/privacy_tools.py. Validation precedes final redaction and narration; response contracts and formatting are produced through datapilot/output/response_models.py and datapilot/output/formatters.py. The UI renders conversational responses, source transparency, and charts through frontend/src/components/chat/ChatInterface.tsx, frontend/src/components/chat/SourceTransparency.tsx, and frontend/src/components/chat/InsightTemplates.tsx.
Runtime and External Services
Backend runtime is Python 3.11/FastAPI/Uvicorn, packaged by datapilot/Dockerfile; frontend is React 19, TypeScript, and Vite. External dependencies include OpenAI GPT-4o/GPT-4o-mini for agent reasoning and narration, PostgreSQL via Psycopg2, MongoDB via PyMongo, and local DuckDB/Pandas for uploaded files. Sentence Transformers provides local embeddings, limiting semantic matching’s dependence on external APIs.
Main entry points: query_routes.py Query execution · router_agent.py Routing, build, validate · rate_limiter.py Request throttling · crew_factory.py Crew selection
Components 19
React client
- Product shell
frontend/src/App.tsx - Chat and insights · Renders answers, sources, and charts.
frontend/src/components/chat/ChatInterface.tsx
FastAPI boundary
- API runtime
datapilot/api/main.py - Request throttling
datapilot/api/middleware/rate_limiter.py - Dataset access · Connects uploaded and configured data sources.
datapilot/api/routes/dataset_routes.py - Query execution
datapilot/api/routes/query_routes.py - Conversation context
datapilot/foundation/memory/conversation_memory.py
Analytics pipeline
- Crew orchestrator · Selects fast or deep analytical execution.
datapilot/crews/orchestrator.py - Crew selection
datapilot/crews/crew_factory.py - Fast analysis crew · Runs compact routing-to-narration flow.
datapilot/crews/phase1_crew.py - Deep analysis crew · Supports broader comparison and breakdown analysis.
datapilot/crews/financial_crew.py - Routing, build, validate · Routes questions, builds queries, and validates results.
datapilot/agents/definitions/router_agent.py - Semantic model and metrics · Maps business language to schemas and derived metrics.
datapilot/foundation/semantic_layer/models.py - Semantic and query cache
datapilot/foundation/cache/embedding_cache.py - Bounded agent tools · Provides semantic lookup, execution, validation, and PII detection.
datapilot/agents/tools/semantic_tools.py - Validated response · Formats redacted narratives and chart responses.
datapilot/output/response_models.py
Data and services
- Connector selection · Chooses SQL, MongoDB, or CSV execution path.
datapilot/foundation/connectors/connector_factory.py - Connected data sources · Read-oriented source systems and uploaded-file execution.
datapilot/foundation/connectors/sql_connector.py - OpenAI reasoning · GPT-4o and GPT-4o-mini reasoning and narration.
Connections 22
- Product shell → Chat and insights: composes
- Chat and insights → API runtime: HTTP requests
- API runtime → Request throttling: applies
- Request throttling → Dataset access: dataset requests
- Request throttling → Query execution: question requests
- Dataset access → Connector selection: connects source
- Query execution → Conversation context: loads and stores context
- Query execution → Crew orchestrator: submits question
- Crew orchestrator → Crew selection: selects execution mode
- Crew selection → Fast analysis crew: fast path
- Crew selection → Deep analysis crew: deep path
- Fast analysis crew → Routing, build, validate: runs stages
- Deep analysis crew → Routing, build, validate: runs stages
- Routing, build, validate → Semantic model and metrics: resolves business terms
- Semantic model and metrics → Semantic and query cache: reuses embeddings and queries
- Routing, build, validate → Bounded agent tools: invokes capabilities
- Bounded agent tools → Connector selection: executes generated query
- Connector selection → Connected data sources: reads
- Routing, build, validate → OpenAI reasoning: reasoning and narration
- Bounded agent tools → Validated response: validate then redact
- Validated response → Query execution: returns response
- Query execution → Chat and insights: answer, sources, charts