π Live Demo: https://ai-grocery-analytics.onrender.com/
AIDA (AI Decision Analyst) is a production-quality, portfolio-ready business intelligence dashboard and conversational AI analyst designed specifically for grocery retail owners. Instead of relying on generic chat replies, AIDA combines a Glassmorphism frontend UI with a modular database interface, an XGBoost demand forecasting pipeline, and the Google Gemini API to answer concrete retail inquiries and suggest supply chain optimization guidelines. To democratize Data analytics for local retail stores.
- Aggregate KPI Widgets: Real-time count-up animations tracking gross revenues, sales quantity, net profit margins, customer footfall counts, and active low-stock alerts.
- Interactive Visualizations (Chart.js): Daily sales & customer trend graphs, category market share distributions, top-selling items, and safety risk polar grids.
- Theme Controls: Global theme switching (frosted glass dark mode and high-contrast light mode) with localStorage state persistence.
- Live ML Forecasting Selector: Pick any product and store branch from dropdown selectors to overlay historical transaction trends with XGBoost daily demand predictions.
- Replenishment Table: Clear logs summarizing safety limits, suggested restocks, order priorities, and alert tags.
- Automatic Function Calling: Gemini evaluates user questions and automatically runs local Python tools to query databases and execute ML models before generating natural language responses.
- Local Fallback Engine: If the Gemini API Key is missing or rate-limited, a local rule-based engine handles requests, keeping the application fully functional out-of-the-box.
- Structured Outputs: Formulates complex metrics reports as clean markdown list structures and tables directly in the chat history.
- PDF Report Exporter: Programmatic vector PDF compilation using ReportLab, complete with headers, KPI grids, reorder tables, and colored warning tags.
- CSV Catalog Exporter: Downloads full, spreadsheet-compatible inventory reports containing stock risks, suppliers, and profit margins.
The project layout separates frontend assets, backend blueprints, ML pipelines, and unit tests:
AI-Grocery-Analytics/
βββ app.py # Flask Application Factory
βββ config.py # Global system config (SQLite, MongoDB, Gemini)
βββ requirements.txt # Package dependencies
βββ Dockerfile # Production container configuration
βββ LICENSE # MIT License specifications
βββ CONTRIBUTING.md # PR workflows & commits conventions
βββ CHANGELOG.md # Project release version logs
βββ CODE_OF_CONDUCT.md # Community codes of conduct
β
βββ images/ # Application Screenshots
β βββ 1.png # Dashboard Overview & AIDA Assistant
β βββ 2.png # XGBoost Demand Forecasting Chart
β βββ 3.png # Inventory Reorder Recommendations Log
β
βββ database/ # Modular DB Layer
β βββ base.py # Abstract database interface (ABC)
β βββ sqlite_impl.py # SQLite database connector implementation
β βββ mongodb_impl.py # MongoDB NoSQL connector stub
β βββ db_factory.py # Database Factory pattern
β βββ initialize.py # DB tables bootstrap and data importer
β
βββ dataset/ # Data simulation
β βββ generator.py # Synthetic daily retail CSV generator
β βββ products.csv # Generated product catalog (ignored)
β βββ grocery_sales.csv # Generated transaction aggregates (ignored)
β
βββ ml/ # Machine Learning Pipeline
β βββ train.py # Chronological models comparison script
β βββ predict.py # Demand forecasting & reorder calculations
β
βββ models/ # Deserialized ML components
β βββ demand_forecast_model.joblib # Saved XGBoost regressor
β βββ encoders.joblib # Categorical label preprocessors
β
βββ routes/ # Flask Blueprints
β βββ auth.py # Secure credentials checking & sessions
β βββ api.py # Dashboard metrics REST feeds
β βββ chat.py # Chat prompts forwarding to Gemini
β βββ reports.py # CSV/PDF downloads endpoints
β βββ views.py # Protected template render controllers
β
βββ static/ # Frontend Assets
β βββ css/
β β βββ dashboard.css # Frosted glass design system, animations
β βββ js/
β βββ dashboard.js # Count-ups & Chart.js controllers
β βββ chat.js # Conversational UI & markdown parser
β βββ theme.js # Light/Dark toggler, alerts fetcher
β
βββ templates/ # Jinja2 HTML Templates
β βββ base.html # Master layout shell
β βββ login.html # Glassmorphic auth portal
β βββ dashboard.html # Main workspace grids
β βββ profile.html # User scopes profile panel
β βββ settings.html # Settings and credentials slider
β
βββ utils/ # Core System Utilities
β βββ logger.py # Application logs formatter
β βββ pdf_generator.py # ReportLab PDF compiler
β
βββ tests/ # Full QA test suites
β βββ test_db.py # Database integrity unit tests
β βββ test_ml.py # ML inference validation tests
β βββ test_api.py # Flask REST endpoints integration tests
β
βββ docs/ # Architectural & DB layouts
βββ architecture.md # Component diagrams & data lifecycles
βββ db_schema.md # ER diagram & columns specifications
βββ api_docs.md # REST endpoints payload specifications
βββ deployment.md # Production server configurations
- Python 3.9, 3.10, 3.11, or 3.13.
- Pip (Python Package Manager).
- Clone the repository:
git clone https://github.com/yourusername/AI-Grocery-Analytics.git cd AI-Grocery-Analytics - Create and Activate a Virtual Environment:
- Windows (PowerShell):
python -m venv venv .\venv\Scripts\Activate.ps1 - Linux/macOS:
python3 -m venv venv source venv/bin/activate
- Windows (PowerShell):
- Install Dependencies:
pip install -r requirements.txt
- Configure Environment Variables:
Copy
.env.templateto.envand fill in your Gemini API Key:Editcp .env.template .env
.env:SECRET_KEY=secure-random-string GEMINI_API_KEY=AIzaSyYourActualGoogleGeminiKeyHere DB_TYPE=sqlite
AIDA provides automated scripts to compile mock data, index databases, and train forecasts:
# 1. Compile 78,840 synthetic transaction records
python -m dataset.generator
# 2. Schema load, database index, and default admin user registry
python database/initialize.py
# 3. Model preprocessing and XGBoost forecast compilation
python -m ml.trainLaunch the Flask development server:
python app.pyOpen your browser and navigate to http://localhost:5000.
- Default Admin Credentials:
- Username:
admin - Password:
admin123
- Username:
AIDA's ML pipeline reads historical transactions directly from the SQLite database, parses dates, and uses Label Encoders to normalize categorical dimensions. To ensure realistic evaluations, the dataset is split chronologically, holding out the last 30 days for testing.
Four models are trained and compared. In our simulation, the XGBoost Regressor yielded the highest test performance:
| Algorithm Name | Mean Absolute Error (MAE) | Root Mean Squared Error (RMSE) | R-squared ((R^2)) |
|---|---|---|---|
| Linear Regression | 4.9182 | 6.4549 | 0.3470 |
| Decision Tree | 3.3495 | 4.5254 | 0.6791 |
| Random Forest | 3.2735 | 4.4097 | 0.6953 |
| XGBoost Regressor | 3.1672 | 4.2164 | 0.7214 |
The trained best model (demand_forecast_model.joblib) is saved and loaded by the inference engine to suggest safety limits and restocks.
The QA framework contains 10 comprehensive unit and integration tests covering database schemas, user registrations, XGBoost predictions, API access bounds, and login sessions.
Execute the test discovery command:
python -m unittest discover -s testsAIDA is ready for deployment in modern serverless and container architectures.
- Live Deployment: The application is deployed and running on Render at https://ai-grocery-analytics.onrender.com/.
- Docker:
docker build -t aida:latest .->docker run -d -p 5000:5000 -e GEMINI_API_KEY="key" aida:latest - Render: Connect repository, set build command and start command as
gunicorn app:create_app(). - Railway: Connect repository, attach a persistent Volume to mount
/app/databasefor SQLite persistence. - See docs/deployment.md for full server configuration guides.
- This project is licensed under the MIT License.
- Contribution rules and guidelines are detailed in CONTRIBUTING.md.
- We expect all contributors to read and follow the Code of Conduct.


