Comprehensive business intelligence platform for hardware store operations with AI-powered natural language SQL queries, automated reporting, and interactive visualizations.
- Ask questions in plain English - "What are my top 10 selling products?"
- Vanna AI integration with support for:
- OpenAI GPT-4
- Grok (xAI) π
- Anthropic Claude
- Ollama (local, private, free)
- Auto-generated SQL from natural language
- Web-based chat interface at http://localhost:8084
- Financial metrics (revenue, profit, margins)
- Customer segmentation (VIP, High Value, Frequent, Regular)
- Product performance analytics
- Category-level profitability
- Inventory velocity tracking
- Trend analysis and forecasting
- Professional PNG reports
- Interactive dashboards (Streamlit)
- Category distribution charts
- Profit margin analysis
- Revenue breakdowns
- Environment-based configuration
- Secure credential management
- No hardcoded passwords
- .env file support
# Install dependencies
pip install pymssql python-dotenv matplotlib numpy
# Configure environment
cp .env.example .env
# Edit .env with your database credentials
# Run analysis
python src/business_analyzer_combined.pyTwo implementations available (see comparison):
A) Production-Ready Grok (Recommended) π:
# Install
pip install vanna chromadb pyodbc openai waitress python-dotenv pandas
# Configure .env
echo "GROK_API_KEY=xai-your-key" >> .env
# Run
python src/vanna_grok.py
# β http://localhost:8084
# Ask in Spanish: "Top 10 productos mΓ‘s vendidos"β¨ Features:
- π° Beautiful number formatting (Colombian pesos:
$123.456.789) - π€ AI-powered insights (Grok analyzes results and gives recommendations)
- πͺπΈ Spanish-optimized (Colombian business context)
- π Executive summaries with each query
B) Multi-Provider (Testing):
# Install
pip install vanna chromadb pyodbc openai
# Choose provider
export GROK_API_KEY='xai-your-key' # Grok (xAI)
# OR export OPENAI_API_KEY='sk-...' # OpenAI
# OR export ANTHROPIC_API_KEY='sk-ant-' # Anthropic
# Run
python src/vanna_chat.py
# β http://localhost:8084# Install Streamlit
pip install streamlit pandas plotly
# Run dashboard
streamlit run examples/streamlit_dashboard.pycoding_omarchy/
βββ README.md # β You are here
βββ .env.example # Environment configuration template
βββ .gitignore # Git exclusions
βββ .gitattributes # Git attributes
βββ requirements.txt # Python dependencies
β
βββ src/ # π» Source Code
β βββ __init__.py
β βββ business_analyzer_combined.py # Main analyzer (traditional)
β βββ vanna_grok.py # π AI chat (Grok-optimized, Spanish)
β βββ vanna_chat.py # AI chat (multi-provider support)
β βββ config.py # Configuration management
β βββ utils/ # Utility functions
β βββ __init__.py
β
βββ tests/ # π§ͺ Tests
β βββ __init__.py
β βββ test_business_metrics.py # Business logic tests
β βββ test_metabase_connection.py # Database connection tests
β
βββ docs/ # π Documentation
β βββ START_HERE.md # β Start here!
β βββ ROADMAP.md # πΊοΈ Strategic roadmap & what's next
β βββ VANNA_COMPARISON.md # π Vanna implementations comparison
β βββ VANNA_BEAUTIFUL_OUTPUT.md # π¨ Beautiful output examples
β βββ VANNA_SETUP.md # Vanna AI setup guide
β βββ ARCHITECTURE.md # Technical architecture
β βββ ANALYSIS_SUMMARY.md # Executive summary
β βββ IMPROVEMENT_ANALYSIS.md # Detailed analysis
β βββ QUICK_START_IMPROVEMENTS.md # Fast-track guide
β βββ P0_FIXES_APPLIED.md # Critical fixes
β βββ METABASE_TROUBLESHOOTING.md # Metabase guide
β βββ SECURITY.md # Security guidelines
β βββ CONTRIBUTING.md # Development guide
β βββ setup_instructions.md # Setup instructions
β
βββ examples/ # π‘ Examples
β βββ improvements_p0.py # Critical bug fixes
β βββ pandas_approach.py # Modern Pandas implementation
β βββ streamlit_dashboard.py # Web dashboard
β
βββ data/ # π Data Files
βββ database_explained.json # Database schema documentation
# Option A: Ask questions in plain English
python src/vanna_chat.py
# "What are my top customers this month?"
# Option B: Use Metabase (Docker)
docker run -d -p 3000:3000 metabase/metabase
# Point & click dashboards# Interactive Streamlit dashboard
streamlit run examples/streamlit_dashboard.py
# Real-time filtering, interactive charts# Traditional script-based analysis
python src/business_analyzer_combined.py --limit 5000
# Or use Pandas approach (10-100x faster)
python examples/pandas_approach.py| Provider | Cost | Speed | Quality | Setup Difficulty |
|---|---|---|---|---|
| OpenAI GPT-4 | $$ | Fast | βββββ | Easy |
| Grok (xAI) π | $$ | Fast | ββββ | Easy |
| Anthropic Claude | $$ | Fast | βββββ | Easy |
| Ollama (Local) | Free | Medium | βββ | Medium |
π¬ "What are my top 10 selling products?"
π¬ "Show me revenue by category this month"
π¬ "Which customers have the highest order values?"
π¬ "What's my profit margin by product?"
π¬ "Show me monthly revenue trends"
π¬ "Which products have low profit margins?"
π¬ "Compare this month's revenue to last month"
π¬ "Show me my best customers in the last 90 days"
# Install dependencies
pip install vanna chromadb pyodbc
# Set your Grok API key
export GROK_API_KEY='xai-your-grok-api-key'
# Edit src/vanna_chat.py
USE_GROK = True
USE_OPENAI = False
USE_OLLAMA = False
USE_ANTHROPIC = False
# Run
python src/vanna_chat.py# Basic analysis (default 1000 records)
python src/business_analyzer_combined.py
# Analyze more records
python src/business_analyzer_combined.py --limit 5000
# Analyze specific date range
python src/business_analyzer_combined.py \
--start-date 2025-01-01 \
--end-date 2025-10-31
# Skip re-analysis, just regenerate visualizations
python src/business_analyzer_combined.py --skip-analysisAll reports saved to ~/business_reports/ (configurable):
analysis_comprehensive_YYYY-MM-DD_to_YYYY-MM-DD.jsonbusiness_analysis_report_YYYYMMDD_HHMMSS.png
The repository includes specialized analysis and reporting scripts in /scripts/:
# SIKA product analysis
python scripts/analysis/sika_analysis.py
# General category analysis
python scripts/analysis/run_analysis.py
# Database investigation
python scripts/analysis/investigate_deposito.py# Generate English SIKA report
python scripts/reports/generate_sika_report.py
# Generate Spanish SIKA report
python scripts/reports/generate_sika_report_es.py
# Generate general analysis report
python scripts/reports/generate_report.pyAll generated reports are saved to the /reports/ directory.
# Database Connection
DB_HOST=your-server-host
DB_PORT=1433
DB_USER=your-username
DB_PASSWORD=your-password
DB_NAME=SmartBusiness
# AI Providers (choose one)
OPENAI_API_KEY=sk-your-openai-key
GROK_API_KEY=xai-your-grok-key # π Grok support
ANTHROPIC_API_KEY=sk-ant-your-key
# Output Configuration
OUTPUT_DIR=~/business_reports
REPORT_DPI=300
DEFAULT_LIMIT=1000See .env.example for all options.
IMPORTANT: Never commit credentials to version control!
β Best Practices:
- Use
.envfiles (already in.gitignore) - Use environment variables in production
- Rotate credentials regularly
- Use least-privilege database accounts
π See docs/SECURITY.md for detailed guidelines.
New to this project? Start here:
- docs/START_HERE.md - Quick overview and path selection
- docs/VANNA_SETUP.md - AI natural language setup (includes Grok!)
- docs/ANALYSIS_SUMMARY.md - Executive summary
Detailed guides:
- docs/IMPROVEMENT_ANALYSIS.md - 500+ line deep dive
- docs/QUICK_START_IMPROVEMENTS.md - Fast-track guide
- docs/P0_FIXES_APPLIED.md - Critical fixes applied
- docs/ANACONDA_TESTING.md - Multi-version Python testing π
- docs/AI_AGENT_INSTRUCTIONS.md - AI agent development guide π€
- .github/agents/ - Custom GitHub Copilot agents π€β¨
- docs/METABASE_TROUBLESHOOTING.md - Metabase guide
- docs/SECURITY.md - Security best practices
- docs/CONTRIBUTING.md - Development workflow
# Quick start - Run basic tests (no dependencies required)
python run_tests.py --quick
# Run all available tests
python run_tests.py
# Run with coverage report
python run_tests.py --cov
# Using pytest directly
pytest tests/ -v
# Run specific test file
pytest tests/test_basic.py -vTest on Python 3.8, 3.9, 3.10, and 3.11:
# Create Conda environment
conda env create -f environment.yml
conda activate business-analyzer
# Run tests
pytest tests/ -v --cov=src
# Test on specific Python version
conda create -n test-py310 python=3.10 -y
conda activate test-py310
pip install -r requirements.txt
pytest tests/ -vπ Full guide: docs/ANACONDA_TESTING.md
# Format code
black src/ tests/ examples/
# Lint
flake8 src/ tests/
# Type checking
mypy src/
# Sort imports
isort src/ tests/ examples/# Critical P0 fixes
python examples/improvements_p0.py
# Modern Pandas approach (10-100x faster)
python examples/pandas_approach.py
# Interactive Streamlit dashboard
streamlit run examples/streamlit_dashboard.pyFor AI agents working on this project:
π docs/AI_AGENT_INSTRUCTIONS.md - Complete guide for developing, debugging, refactoring, and fixing this project
π€ .github/agents/business-data-analyzer.agent.md - Custom GitHub Copilot agent specialized for this project
Using the Custom Agent:
In GitHub Copilot Chat or comments, use @business-data-analyzer to get specialized help:
@business-data-analyzer help me format this currency in Colombian pesos
@business-data-analyzer review this code for security issues
@business-data-analyzer write tests for this business metric function
Quick reference:
- Architecture: Vanna AI + Grok + MSSQL + Colombian formatting
- Branch naming:
claude/feature-name-SessionID(MUST start withclaude/) - Security: Always use
require_env(), never hardcode credentials - Formatting: Use
format_number()for Colombian pesos ($1.234.567) and percentages (45,6%) - Testing: Add tests for every feature, maintain 80%+ coverage
- Language: Spanish for user messages, English for code/docs
π .github/QUICK_REFERENCE.md - Quick commands and checklists
| Category | Metrics |
|---|---|
| Financial | Revenue (with/without IVA), profit margins, gross profit, average order value |
| Customers | Segmentation (VIP, High Value, Frequent, Regular), top customers, concentration |
| Products | Top sellers, profitability, star products, underperformers |
| Categories | Category revenue/margins, subcategories, risk assessment |
| Inventory | Fast movers, slow movers, velocity analysis |
| Trends | Monthly trends, seasonal patterns, category distribution |
β Check .env file exists and has correct credentials
β pip install matplotlib numpy
β Check API key is set: echo $OPENAI_API_KEY or echo $GROK_API_KEY
β See docs/METABASE_TROUBLESHOOTING.md
| Approach | Lines of Code | Performance | Use Case |
|---|---|---|---|
| Current Script | 1,492 | Baseline | Works today |
| Pandas Approach | 200 | 10-100x faster | Best for developers |
| Streamlit | 300 | 10x faster | Best for teams |
| Metabase | 0 (GUI) | Fast | Best for business users |
| Vanna AI π | 0 (Natural Language) | Real-time | Best for everyone |
Contributions welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests:
pytest tests/ - Format code:
black src/ tests/ - Submit a pull request
See docs/CONTRIBUTING.md for detailed guidelines.
[Specify your license here]
- Built for hardware store business intelligence
- Designed for SmartBusiness ERP integration
- Compatible with Magento e-commerce
- Vanna AI integration for natural language SQL
- Grok (xAI) support π
- π Documentation: See
docs/directory - π Issues: Open a GitHub issue
- π‘ Questions: See docs/START_HERE.md
| I want to... | Go here... |
|---|---|
| See what's next / roadmap πΊοΈ | docs/ROADMAP.md π |
| Run tests π§ͺ | python run_tests.py --quick + docs/TESTING.md |
| Use Grok AI in Spanish π | src/vanna_grok.py + docs/VANNA_COMPARISON.md |
| See beautiful output examples π¨ | docs/VANNA_BEAUTIFUL_OUTPUT.md |
| Ask questions in plain English | src/vanna_chat.py + docs/VANNA_SETUP.md |
| Get started quickly | docs/START_HERE.md |
| Compare Vanna implementations | docs/VANNA_COMPARISON.md |
| Run traditional analyzer | python src/business_analyzer_combined.py |
| Build web dashboard | streamlit run examples/streamlit_dashboard.py |
| Fix critical bugs | examples/improvements_p0.py |
| Understand the code | docs/IMPROVEMENT_ANALYSIS.md |
| Secure my deployment | docs/SECURITY.md |
β Star this repo if you find it useful!
π Ready to get started? β docs/START_HERE.md
Note: This tool processes business data. Ensure compliance with data privacy regulations (GDPR, CCPA, etc.) when handling customer information.