# Jetour BI Dashboard Dark-themed sales & CRM pipeline dashboard for Jetour Mauritius, powered by CMS BI data. ## Quick Deploy ```bash # 1. Clone git clone https://gitea.iseva.net.za/jjsm01/jetour-bi.git cd jetour-bi # 2. Create database createdb jetour-bi # 3. Run migrations pip install psycopg bcrypt DATABASE_URL="postgresql://postgres:***@localhost:5432/jetour-bi" python migrate.py # 4. Start dashboard pip install fastapi uvicorn uvicorn app:app --host 0.0.0.0 --port 8765 # 5. Open http://localhost:8765 # Default login: admin / admin ``` ## Architecture ``` Browser → FastAPI (:8765) → PostgreSQL (jetour-bi) ↑ n8n workflows (02:00-02:50) ───┘ (populate BI data from CMS) n8n report triggers (07:00) ───┘ (daily/weekly/monthly emails) ``` ## Database | Table | Purpose | |-------|---------| | `prospects` | CMS BI prospect records | | `prospect_otps` | Vehicle orders (model, color, amount, stock) | | `status_logs` | Status change history | | `change_log` | Field-level audit trail (auto-triggered) | | `appointments` | Delivery/test-drive appointments | | `report_recipients` | Email report recipients per type | | `app_settings` | SMTP config, app preferences | | `dashboard_users` | Auth users | ### Migrations ```bash # Apply all pending migrations (idempotent) DATABASE_URL="postgresql://user:***@host:5432/dbname" python migrate.py # Or pass URL directly python migrate.py postgresql://user:***@host:5432/jetour-bi ``` Migrations are tracked in the `_migrations` table. Safe to run repeatedly. ## Dashboard Pages | URL | Description | |-----|-------------| | `/` | Main dashboard (pipeline, velocity, models, vehicle orders) | | `/settings.html` | Email report settings (recipients + SMTP config) | ## n8n Integration 5 workflows manage the data pipeline. n8n just calls dashboard endpoints: | Workflow | Schedule | Endpoint | |----------|----------|----------| | Daily Report | 07:00 SAST | `POST /api/send-report/daily` | | Weekly Report | Mon 07:00 | `POST /api/send-report/weekly` | | Monthly Report | 1st 07:00 | `POST /api/send-report/monthly` | Dashboard handles all SMTP send + recipient resolution. ## Docker Deployment ```bash # Build and start (app + PostgreSQL + n8n) docker compose up -d # Set passwords DB_PASSWORD=*** N8N_ENCRYPTION_KEY=*** docker compose up -d # View logs docker compose logs -f app # Stop docker compose down # Reset (destroy DB volume) docker compose down -v ``` ### Environment variables | Variable | Default | Description | |----------|---------|-------------| | `DB_HOST` | `db` | PostgreSQL host | | `DB_PORT` | `5432` | PostgreSQL port | | `DB_NAME` | `jetour-bi` | Database name | | `DB_USER` | `jetour` | Database user | | `DB_PASSWORD` | `jetour` | Database password | | `JWT_SECRET` | `change-me-in-production` | JWT signing secret | | `SMTP_HOST` | (empty) | SMTP server for email reports | | `SMTP_PORT` | `587` | SMTP port | | `SMTP_USER` | (empty) | SMTP username | | `SMTP_PASS` | (empty) | SMTP password | | `SMTP_FROM` | `reports@jetour.mu` | From address | | `N8N_ENCRYPTION_KEY` | `change-me-to-a-random-string` | n8n encryption key | ### Ports | Service | Port | Description | |---------|------|-------------| | Dashboard | `8765` | Web UI | | n8n | `5678` | Workflow automation | | PostgreSQL | `5433` | Mapped from container `5432` |