How ayhanarashtasin/sust-ai-hackathon-onsiteround works
1. Repo shape and runtimes
- This is a three-part system: a React/Vite client (client/), a Node/Express API (server/), and a Python ML/training package (ml/).
- The application data lives in MongoDB via Mongoose. The client never talks to MongoDB directly; all reads and writes go through the API.
2. Primary product flow
- The core loop is: login → select agent outlet → view balances/forecast/alerts → inspect case details → take case actions.
- The UI is designed as a read-heavy console: the client polls the server for fresh state, while the server computes analytics and persists results.
3. Client boundary
- The client is a dashboard-style SPA with pages for Login, Dashboard, Agent Detail, Case View, and Service Status.
- It uses a shared API client, JWT auth context, polling hooks, and localized strings in English, Bengali, and Banglish.
- The client is intentionally read-only for decision data; it does not generate alerts or run ML.
4. Server boundary
- The Express server is the system of record for auth, agent state, alerts, case workflow, simulation control, and model status.
- JWT middleware attaches role, area, and provider scope to the request context, and controllers enforce those boundaries on every query and mutation.
- Server-side scoping is important: outlets, areas, and providers are not merged even if the UI shows them together.
5. Data model
- Main Mongo collections are Agent, Transaction, Alert, Prediction, and User.
- Agent stores one shared cash drawer plus separate e-money balances per provider.
- Alert stores case state, audit history, and evidence snapshots; Transaction stores signed balance deltas; Prediction is the audit log for model outputs.
6. Simulation engine as the data producer
- The repo is built around a simulated live environment rather than real integrations.
- server/services/simEngine.js generates scenario transactions, applies them atomically to agent balances, runs analytics, and upserts alerts on each tick.
- This is the main source of state change in the system; the UI mostly observes its output.
7. Analytics pipeline
- The decision-support path is assembled in server/services/ml/decisionSupport.js.
- It combines:
- data quality checks for stale/missing/mismatched feeds,
- forecasting for cash and each provider’s e-money,
- statistical anomaly detection,
- rule engine output,
- tabular ML predictions,
- and a hybrid decision combiner.
- The resulting outputs are written back as alert/prediction state for the client to display.
8. Forecast subsystem
- Liquidity forecasting is per resource: shared cash + separate provider balances.
- It estimates burn rate, depletion ETA, confidence, and top-up guidance.
- A key boundary is that bad or inconsistent data suppresses recommendations instead of producing confident advice.
9. Anomaly and evidence subsystem
- Anomaly detection focuses on two behaviors: velocity spikes and repeated near-identical amounts.
- Results are classified into review-worthy findings versus a benign demand_surge category.
- Evidence is made human-readable through an explanation layer and kept tied to specific transactions and data freshness signals.
10. Case workflow and governance
- Alerts are not just notifications; they are cases with a validated lifecycle: acknowledge, assign, escalate, resolve, dismiss.
- Role permissions differ by staff type: agent, field officer, ops, risk, and management.
- Every action appends to an audit trail, so the system supports coordination and traceability, not automated enforcement.
11. Safety and language controls
- The system is intentionally constrained to advisory-only behavior.
- A runtime language guard blocks prohibited terms, and alert prose is produced via OpenAI when available or deterministic templates otherwise.
- This means the explanation layer is a guarded downstream formatting step, not the source of truth for risk.
12. Seed data, demo data, and offline training
- The repo ships with deterministic synthetic sample data in data/ and database seeding scripts in server/scripts/.
- The ml/ package contains training artifacts, evaluation outputs, and tests for anomaly/liquidity models; it is separate from the runtime API path.
- In production-like demo mode, the server consumes these artifacts for inference but does not depend on a separate ML service.
13. Operational tooling and validation
- There are dedicated scripts for seeding, validation, sample-data generation, and HTTP latency measurement.
- GitHub Actions runs SonarCloud analysis.
- The test suite is broad across server services, controllers, workflow, simulation, and ML helpers, which makes the architecture heavily exercised around the server-side analytics pipeline.
14. What an architecture diagram should emphasize
- Draw the system as:
- Client UI polling
- Express API enforcing auth/scope
- Simulation + analytics pipeline producing alerts and forecasts
- MongoDB storing outlet, transaction, alert, prediction, and user state
- Offline Python ML training/artifacts feeding runtime inference
- The most important boundary is that the server owns all authoritative logic and state transitions; the browser is a consumer of computed results.
Main entry points: decisionSupport.js Decision Support · controllers Domain Controllers · models Mongo Models · simEngine.js Simulation Engine
Components 22
Client UI
React/Vite dashboard SPA that polls the API and renders decision-support state.
- App Shell · Top-level client composition and page routing.
client/src/App.jsx - Auth Context · Holds login state and bearer token handling for the UI.
client/src/context/AuthContext.jsx - API Client · Shared browser client for API requests.
client/src/api/client.js - Polling Hooks · Client-side refresh cadence for live dashboard state.
client/src/hooks/usePolling.js - Dashboard Pages · Login, dashboard, agent detail, case view, and service status screens.
client/src/pages - Decision UI · Balance, forecast, alerts, timeline, explanation, and model status components.
client/src/components
Express API
Authoritative runtime for auth, scoping, simulation, case workflow, and analytics.
- API Routes · HTTP boundary for auth, agents, alerts, model status, public endpoints, and simulation control.
server/routes - Auth Middleware · Attaches and enforces role, area, and provider scope on requests.
server/middleware/auth.js - Mongo Models · Agent, Alert, Transaction, Prediction, and User persistence models.
server/models - Simulation Engine · Generates scenario transactions, applies atomic balance changes, and triggers analytics on each tick.
server/services/simEngine.js - Decision Support · Combines data quality, forecasting, anomaly detection, rules, tabular ML, and hybrid scoring.
server/services/ml/decisionSupport.js - Forecasting · Estimates burn rate, depletion ETA, confidence, and top-up guidance for cash and provider balances.
server/services/forecast.js - Anomaly Detection · Finds velocity spikes and repeated near-identical amounts for review-worthy evidence.
server/services/anomaly.js - Rule Engine · Deterministic rule definitions and case classification logic.
server/services/rules/ruleEngine.js - Case Workflow · Acknowledgement, assignment, escalation, resolution, dismissal, and audit trail handling.
server/services/caseWorkflow.js - Explanation Layer · Human-readable alert narration with language guard and optional OpenAI-backed phrasing.
server/services/explain.js - Live Updates · Server-side state refresh and publication helpers for client polling.
server/services/liveUpdates.js - Domain Controllers · Agent, alert, decision, model, sim, auth, and public controllers that coordinate service calls.
server/controllers - Decision Config · Server configuration for model/runtime behavior and decision thresholds.
server/config/decisionConfig.js
Offline ML
Python training and packaged artifacts used for inference in the server runtime.
- Python Package · Offline data prep, metrics, and pipeline code for model training and validation.
ml/sust_ml - Model Artifacts · Versioned anomaly and liquidity artifacts, manifests, metrics, and model cards.
ml/artifacts
Data & Artifacts
Seed data and persisted model/sample artifacts used by the app and tooling.
- Sample Data · Deterministic demo agents, transactions, users, and ML manifests.
data/sample
Connections 27
- App Shell → Dashboard Pages: routes · App shell renders the page-level experience.
- App Shell → Auth Context: session · UI reads login and token state.
- Dashboard Pages → Decision UI: compose · Pages assemble the dashboard components.
- Decision UI → API Client: fetch · Visuals depend on API-backed decision data.
- Polling Hooks → API Client: refresh · Polling drives repeated reads from the server.
- API Client → API Routes: http · All browser reads and writes go through the API.
- API Routes → Auth Middleware: protect · Routes are wrapped by JWT scope enforcement.
- API Routes → Domain Controllers: dispatch · Route handlers delegate into domain controllers.
- Domain Controllers → Simulation Engine: control · Simulation endpoints start and manage the live scenario engine.
- Domain Controllers → Case Workflow: case ops · Alert actions mutate case lifecycle state.
- Domain Controllers → Decision Support: analyze · Decision endpoints compute model-backed state.
- Domain Controllers → Live Updates: status · Controllers expose current system state to the UI.
- Simulation Engine → Mongo Models: persist · Ticks apply transactions and update alert/state documents.
- Simulation Engine → Decision Support: produce · Each tick triggers analytics and alert generation.
- Decision Support → Forecasting: forecast · Liquidity forecasts are a core input to the hybrid output.
- Decision Support → Anomaly Detection: detect · Anomaly findings contribute evidence and case signals.
- Decision Support → Rule Engine: rule score · Rule outputs shape advisory classification.
- Decision Support → Explanation Layer: explain · Final outputs are rendered into guarded prose and evidence.
- Decision Support → Mongo Models: write back · Predictions and alerts are persisted as system state.
- Case Workflow → Mongo Models: audit · Case transitions append to alert history and audit trails.
- Live Updates → Polling Hooks: serve refresh · Live status endpoints support the client polling loop.
- Python Package → Model Artifacts: train · Offline training produces packaged inference artifacts.
- Decision Support → Model Artifacts: infer · Runtime loads packaged model outputs for tabular inference.
- Sample Data → Simulation Engine: seed · Deterministic fixtures feed demo and validation scenarios.
- Sample Data → Mongo Models: bootstrap · Sample data initializes collections for demo mode.
- Decision Config → Decision Support: tune · Decision thresholds and runtime settings shape analytics behavior.
- Explanation Layer → Mongo Models: annotate · Explanations are tied back to alerts and predictions.