Restaurant Analytics Multi-Agent System
AI-powered natural language restaurant analytics platform with multi-agent architecture
A production-oriented intelligent analytics system that transforms natural language questions into accurate SQL queries using a multi-agent workflow powered by LangGraph, validated through deterministic guardrails, and optimized for complex schema navigation.
🎯 What Is This?
This system enables natural language analytics over restaurant data from multiple POS systems (Toast,DoorDash, Square). Instead of writing SQL manually, users ask questions like:
- "What were total sales on January 2nd?"
- "Compare delivery vs dine-in revenue"
- "Show me the top 5 selling products"
The system automatically:
- Understands intent and identifies relevant data
- Generates safe SQL using schema-aware agents
- Validates queries through deterministic guardrails
- Returns insights with visualizations and streaming responses
🏗️ System Architecture

Core Components
| Component | Technology | Purpose |
|---|---|---|
| Data Pipeline | Python ETL | Cleans, normalizes & unifies multi-source data |
| Database | PostgreSQL (Supabase) | Stores unified schema + materialized views |
| Backend | FastAPI + LangGraph | Multi-agent orchestration & API |
| Dashboard Service | FastAPI + PostgreSQL | Persistent query visualizations & widget management |
| Frontend | Next.js 15 | Streaming UI with charts, tables & dashboards |
| LLM Layer | Multi-provider | Supports NVIDIA, OpenAI, Grok, Gemini |
✨ Key Features
🤖 Multi-Agent Workflow
- Intent & Schema Agent: Classifies queries, selects relevant tables (rule-based + LLM fallback, ~40% fewer LLM calls)
- SQL Generator: Creates PostgreSQL queries with schema-aware prompt engineering
- SQL Validator: Deterministic safety guardrails (blocks destructive ops, SQL injection, schema violations)
- Result Processor: Validates and formats results for presentation
📊 Dashboard Service (New!)
- Persistent Visualizations: Save query results as widgets to custom dashboards
- Optimized Performance:
- Widget addition: 3-5s → <100ms (97% faster)
- Database indexes for 40-50% faster dashboard loads
- Optimistic UI updates for instant feedback
- Organization: Up to 12 widgets per dashboard with customizable sizing
- Query History: All queries automatically persisted for dashboard reuse
⚡ Performance Optimizations
- Materialized Views: Pre-computed aggregations for 10-50x faster analytics queries
- Streaming Responses: Progressive UI updates reduce perceived latency by 40-50%
- Smart Caching: Rule-based intent detection for common queries
- Database Indexes: Optimized queries for dashboards and widgets
🔗 Multi-LLM Support
Configure provider via environment variable:
- NVIDIA (default): Nemotron models
- OpenAI: GPT-4 and variants
- Grok: xAI API
- Gemini: Google's latest models
🛡️ Production-Ready Design
- Zero unsafe queries (100% deterministic validation)
- <5-10% hallucination rate through multi-agent validation
- Comprehensive error handling and retry logic
- Modular architecture for easy debugging
🚀 Quick Start
Prerequisites
- Python 3.11+
- Node.js 18+
- Supabase account (free tier)
- API key for your chosen LLM provider
Installation
# 1. Clone and navigate
cd Restaurant-Analytics-Multi-Agent-System
# 2. Run ETL pipeline (see etl/README.md)
cd etl
# Configure .env with DATABASE_URL
python etl_pipeline.py
# 3. Start backend
cd ../restaurant-analytics-agent
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# Configure .env (see .env.example)
uvicorn backend.main:app --reload
# 4. Start frontend
cd ../frontend
npm install
# Configure .env.local with NEXT_PUBLIC_API_URL
npm run dev
📘 Detailed Setup: See QUICK_START.md for step-by-step instructions
📚 Documentation
| Document | Description |
|---|---|
| QUICK_START.md | Complete setup guide with environment configuration |
| DATA_PIPELINE_DOCUMENTATION.md | ETL pipeline, schema design, data cleaning strategies |
| restaurant-analytics-agent/README.md | Backend architecture, agent details, API reference |
| frontend/README.md | Frontend setup and component documentation |
| docs/PROJECT_STRUCTURE.md | Directory layout and codebase organization |
| docs/EXAMPLE_QUERIES.md | Sample queries to test system capabilities |
🎨 Design Decisions
Multi-Agent Architecture
Why not a single LLM call?
- Complex schemas require decomposed reasoning
- Early error detection through validation layers
- Focused context per agent = higher accuracy
- Debuggable, maintainable components
Materialized Views
Why pre-compute aggregations?
- Scalability: Complex joins don't scale with data volume
- Predictable latency: Sub-second query times
- Production-ready: Can be refreshed on schedules (cron, Airflow)
Trade-off: Accuracy over Raw Speed
- Total latency: ~10-15 seconds (multi-agent validation)
- Perceived latency: ~6-8 seconds (streaming responses)
- Hallucination rate: <5-10% (vs 30-40% single-pass)
Result: Reliable, production-grade analytics with acceptable UX
🛠️ Tech Stack
| Layer | Technologies |
|---|---|
| Frontend | Next.js 15, React, TailwindCSS, Recharts |
| Backend | FastAPI, LangGraph, LangChain, Pydantic |
| Database | PostgreSQL (Supabase), Materialized Views |
| LLM Providers | NVIDIA NIM, OpenAI, Grok (xAI), Gemini |
| ETL | Python, pandas, psycopg2 |
| Infrastructure | Docker, uvicorn (ASGI) |
🔮 Future Enhancements
- [ ] Result validator agent (currently pass-through)
- [ ] Query result caching for common questions
- [ ] Observability with OpenTelemetry
- [ ] Additional materialized views for edge cases
- [ ] Multi-tenant support with row-level security
- [ ] Integration with Airflow for automated view refreshes
📊 Sample Queries
Try these example questions:
- "What were total sales on January 2nd?"
- "Show me the top 5 products by revenue"
- "Compare delivery vs dine-in revenue"
- "What's the busiest hour for sales?"
- "How much revenue came from burgers category?"
See docs/EXAMPLE_QUERIES.md for more examples and expected results.
📄 License
Personal Project - MIT License
🙏 Acknowledgments
Built as a demonstration of production-oriented AI engineering principles, focusing on:
- Reliability and safety over raw speed
- Clear separation of concerns
- Deterministic validation layers
- Scalable architecture design
For questions or feedback, please open an issue or reach out directly.
Built With
- css
- dockerfile
- javascript
- plpgsql
- python
- typescript
Log in or sign up for Devpost to join the conversation.