A full-stack application that provides an interactive interface for data analysis and visualization, powered by AI. Generates charts and textual insights in few seconds for even the most complicated queries!
This application combines a modern React frontend with a Python backend to create an intelligent data analysis platform. It features real-time data visualization, interactive charts, and AI-powered insights.
- Interactive data visualization with multiple chart types:
- Line charts (single and multiple series)
- Bar charts (vertical and horizontal)
- Stacked bar charts with tooltips
- Area charts with gradients
- Real-time data analysis
- AI-powered insights and recommendations
- Responsive and modern UI
- Redux state management
- RESTful API integration
- React.js
- Redux Toolkit for state management
- Recharts for data visualization
- Tailwind CSS for styling
- Shadcn UI components
- OpenAI.API
- FastAPI
- DuckDB
- Docker
ai_data_analyst/
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── components/
│ │ │ │ ├── BarChart.jsx
│ │ │ │ ├── LineChart.jsx
│ │ │ │ ├── LineChartMultiple.jsx
│ │ │ │ ├── Tooltip.jsx
│ │ │ │ ├── Message.jsx
│ │ │ │ ├── InputBox.jsx
│ │ │ │ ├── ChatArea.jsx
│ │ │ │ └── ...
│ │ │ └── ...
│ │ ├── store/
│ │ │ └── store.js
│ │ ├── http/
│ │ │ └── http.js
│ │ └── ...
│ └── ...
├── backend/
│ ├── app/
│ │ ├── main.py
│ │ ├── agents/
│ │ │ ├── orchestrator.py
│ │ │ ├── sql_agent.py
│ │ │ ├── formatter_agent.py
│ │ │ └── analyst_agent.py
│ │ ├── models/
│ │ ├── routes/
│ │ └── services/
│ └── ...
└── docker-compose.yaml
- Handles all HTTP communication with the backend
- Provides functions for sending user input and receiving responses
- Manages API endpoints for data analysis requests
- Integrates with Redux store for state management
- Provides the user input interface
- Manages text input state
- Handles message submission
- Integrates with Redux for message dispatch
- Maintains conversation context
- Displays the conversation history
- Renders different types of messages (text, charts, tables)
- Manages message layout and styling
- Integrates with Redux for message state
- Manages application state
- Handles message history
- Provides selectors for message access
- Manages chart and visualization data
- Implements message dispatch actions
- FastAPI application entry point
- Handles CORS configuration
- Manages API endpoints
- Routes requests to appropriate agents
- Processes user input and returns responses
- Coordinates the flow between different agents
- Manages the conversation pipeline
- Handles database connections
- Routes queries to appropriate agents
- Formats and returns final responses
- Generates SQL queries from natural language
- Interacts with the database
- Handles query execution
- Manages error handling and retries
- Validates query results
- Evaluates user questions
- Formats responses for better understanding
- Manages conversation context
- Analyzes query results
- Generates visualizations
- Creates natural language explanations
- Determines appropriate chart types
- Formats data for frontend display
- Docker and Docker Compose
- Clone the repository:
git clone git@github.com:Danielwohlr/ai_data_analyst.git
cd ai_data_analyst
- Start the application using Docker Compose (will take few minutes):
docker-compose build
docker-compose up
Or run frontend and backend separately:
cd frontend
npm install
npm run dev
cd backend
uv venv
uv sync
source .venv/bin/activate
uvicorn app.main:app --reload
-
Open your browser and navigate to
http://localhost:3000
-
The application will present a chat-like interface where you can:
- Ask questions about your data
- View visualizations
- Get AI-powered insights
-
Stop the app
docker compose down
GET /
: Health check endpointPOST /input
: Process user input and return analysis- Additional endpoints for specific data operations
[!Note] Question For a customer with the highest amount of orders, show me a lineplot across all months available of how many orders they have made in each month
[!Caution] Answer The line plot below shows the number of orders made each month by the customer with the highest number of total orders. The data spans from October 2013 to May 2015, with the highest monthly order count being 5 in October 2014.
-
If you want a chart to be plotted, mention it in the prompt.
-
The model has memory, so it can connect the dots across multiple prompts.
-
If you have your own valid query, you can execute it via the agent and collect the result. (UPDATE, DELETE or INSERT do not work)
The AI Data Analyst application is built as a modular full-stack system, combining a modern React frontend with a Python backend powered by FastAPI and DuckDB. The architecture is designed for extensibility, real-time data analysis, and seamless AI integration.
-
Frontend:
- Built with React.js and Redux Toolkit for state management.
- Uses Recharts for interactive data visualization.
- Communicates with the backend via HTTP API endpoints.
- Components such as
InputBox.jsx
,ChatArea.jsx
, and chart components handle user interaction and display results.
-
Backend:
- Implemented with FastAPI for high-performance asynchronous APIs.
- Utilizes DuckDB as the analytical database engine.
- Integrates with OpenAI’s API for natural language understanding and data analysis.
- Organized into modular agents:
- Orchestrator Agent: Coordinates the flow between agents and manages the conversation pipeline.
- Formatter Agent: Evaluates and reformulates user questions for clarity and context.
- SQL Agent: Translates natural language queries into SQL, executes them, and handles errors.
- Analyst Agent: Analyzes SQL results, generates insights, and suggests visualizations.
-
Database:
- DuckDB database stores analytical data.
- Schema is introspected dynamically to inform the AI agents.
-
Communication Flow:
- User Input: User submits a question via the frontend.
- Formatter Agent: Backend evaluates the question, reformulates or asks for clarification if needed.
- SQL Agent: Generates and executes SQL queries based on the user’s intent.
- Analyst Agent: Interprets query results, generates explanations, and suggests visualizations.
- Response: The orchestrator compiles the answer and sends it back to the frontend for display.
-
Deployment:
- Can be run locally with Docker Compose or as separate frontend/backend services.
- Easily deployable to cloud platforms.
A[User] -->|Question| B[Frontend (React)]
B -->|API Request| C[Backend (FastAPI)]
C --> D[Formatter Agent]
D --> E[SQL Agent]
E --> F[DuckDB Database]
E --> G[Analyst Agent]
G --> C
C -->|Response| B
B -->|Visualization| A
- Extensible agent-based backend for robust, modular data analysis.
- Real-time, interactive frontend for seamless user experience.
- AI-powered insights leveraging OpenAI’s models for both query understanding and result interpretation.
- Support for multiple chart types and natural language explanations.