1. Production Architecture (Future — Focus ERP Integration)
API / SQL View
(Node.js)
(Frontend)
Data flows in one direction only: Focus ERP → API/SQL View → Backend → Gemini → Dashboard. The backend is the only component that communicates with both the data source and Gemini API. The frontend never directly accesses Focus ERP or Gemini.
Why a Backend Is Required
- API key protection: The Gemini API key must never be exposed to the browser.
- Data transformation: Data from Focus ERP must be cleaned, transformed, and minimised before being sent to Gemini.
- Audit trail: All AI analysis requests must be logged and auditable.
- Access control: The backend enforces role-based access control in production.
Data Minimisation Rules
- Only relevant reject fields are sent to Gemini — no PII, no financial codes.
- Batch-level details are aggregated to case level before AI processing.
- Gemini receives no inventory quantity or location data beyond what is needed for risk scoring.
2. Current Prototype Architecture
(backend/server.js)
or
(Frontend)
The prototype now runs as a secure backend-served dashboard:
- Backend Mode: Run
npm startto startbackend/server.json port 3000. It reads the Excel file, optionally calls Gemini API, and returns data to the frontend. - Demo Fallback: If the Excel file is missing or unreadable, the backend serves safe demo records from the data service.
3. Security Model
- API Key Protection: The Gemini API key is stored in
.envon the server only. It is never in HTML, CSS, or browser-side JavaScript. Even if someone inspects the page source, the API key cannot be found. - No Direct Database Access: The frontend never connects to Focus ERP or the Excel file directly. All data passes through the backend.
- Read-Only Access: The prototype has no write capability to Focus ERP or any data source. This is intentional and prevents accidental data changes.
- Role-Based Access (Future): In production, access to specific views will be controlled by user roles (Executive, Finance, QC, IT).
- HTTPS Required (Future): All communication between the dashboard and backend must use HTTPS in production.
4. Future Focus ERP Integration Options
Option 1 — Focus API (Recommended)
If Focus ERP provides a REST or SOAP API, the backend can pull reject data directly. This is the cleanest approach and supports real-time or near-real-time updates. The backend would call the Focus API on a schedule (e.g., every 5 minutes) or on-demand.
Option 2 — Read-Only SQL View
If Focus uses a SQL database, create a read-only SQL view that exposes only the required reject and destruction fields. The backend connects to this view with a read-only database account. This is secure and does not risk modifying Focus data.
Option 3 — Scheduled Excel/CSV Export
The simplest integration: schedule Focus ERP to export reject data to a shared location (e.g., network folder or SFTP server) as CSV or Excel. The backend reads the latest file on a schedule. This is the least real-time option but the easiest to implement initially.
5. API Endpoints (Current Prototype)
6. UAT Checklist
- ✓ Static mode: Open index.html directly — all data renders correctly
- ✓ Backend mode: npm install && npm start — server starts without errors
- ✓ API health check: GET /api/health returns 200 with valid JSON
- ✓ Filter bar: Department, risk level, status, date range, and search filters work
- ✓ Anomaly detection: Items with >3x average cost flagged and displayed
- ✓ Predictive cost: 30-day projection calculated from daily average
- ✓ Token-based auth: Login page, token validation, and 401 redirect work
- ✓ Audit log: /api/audit-log returns entries and file-based logging works
- ✓ Gemini cache: Results cached for 5 minutes, cache_age_seconds in response
- ✗ Excel file loaded: Verify Excel data maps to reject records correctly
- ✗ Gemini integration: Test with valid API key — analysis returns expected JSON structure
- ✓ Graceful fallback: Remove Excel file — verify demo data loads automatically
- ✓ Graceful fallback: Remove API key from .env — verify simulated AI runs
- ✓ All 6 pages render with correct navigation and no broken links
- ✓ RTL layout verified across all pages on desktop and mobile
- ✓ No API keys exposed in frontend code or browser developer tools
7. Go-Live Readiness Checklist
- ✗ Focus ERP integration confirmed (API, SQL view, or scheduled export)
- ✗ Backend deployed to secure server with HTTPS enabled
- ✗ Gemini API key configured in server environment (not in code)
- ✗ DASHBOARD_TOKEN changed from default to a strong, unique value
- ✗ Role-based access control implemented and tested
- ✗ Data minimisation rules verified and documented
- ✗ Audit logging enabled and verified for all API requests
- ✗ FOCUS_API_URL and FOCUS_API_TOKEN configured for live data
- ✗ User acceptance testing completed with real Focus data
- ✗ Disaster recovery and backup plan documented
- ✗ Training completed for all user roles (Executive, Finance, QC, IT)
- ✗ SOP updated to include dashboard in reject and destruction workflow
- ✗ Performance tested with full Focus ERP data volume