How shuvodipdassowmik/somonnoy-sustc works
1. Top-level shape
- The repo is a three-tier prototype: React client in client/, Node/Express API in server/, and a separate FastAPI ML service in ml/.
- The main architecture boundary is between the interactive UI, the business/API layer, and the model-serving layer.
2. Client subsystem
- The client is a Vite + React app that renders the landing page, auth pages, and role-specific dashboards.
- It is organized by feature area: auth, dashboard, operations, alerts, insights, management, and landing.
- Shared UI concerns live in reusable components like PageSpinner, FormError, and ProviderLogo, with a DashboardLayout wrapping authenticated screens.
3. Client state and API access
- Authentication state is centralized in AuthContext, and feature hooks encapsulate fetching and local view logic.
- API usage is routed through a shared client service layer in client/src/services, with endpoint definitions separated from request code.
- The UI is designed around role-scoped dashboards rather than a single generic app surface.
4. Server subsystem
- The Node/Express server is the main orchestration layer: it exposes routes for auth, operations, alerts, management, and graph insights.
- Controllers and services are separated so that request handling, domain logic, and external integrations do not mix.
- The server is responsible for combining database data, ML output, and Gemini-based anomaly analysis into consumable dashboard payloads.
5. Auth and access boundaries
- Authentication is JWT-based with HttpOnly cookies, and the server enforces role- and provider-aware access through middleware.
- auth.middleware.js handles protected access, providerScope.middleware.js limits data visibility to the authenticated provider context, and ratelimiter.middleware.js protects selected endpoints.
- This makes provider, agent, analyst, and management views distinct security boundaries rather than just UI filters.
6. Primary data store
- The persistent store is Postgres, with domain-specific schema and migrations under server/src/db.
- Migrations are split by functional area: alerts, management, and operations.
- Seeding/setup scripts build the synthetic demo data used by the dashboards, including provider ops and risk analyst data.
7. Liquidity shortage prediction path
- The server sends recent synthetic transaction and balance records to the separate FastAPI ML service in ml/.
- The ML side uses LightGBM model artifacts stored under ml/models and returns shortage timing, alert level, confidence, and evidence metrics.
- The ML repo also contains training, feature engineering, and evaluation scripts, which indicates this is a standalone model-serving boundary rather than an in-process library.
8. Transaction anomaly analysis path
- Risk analyst alert generation is handled in the server by transactionAnomaly and riskAnomalyRefresh services.
- The flow fetches recent transactions, skips already-recorded alert keys, analyzes activity per agent, and uses Gemini for schema-validated JSON anomaly reasoning.
- If Gemini fails or returns invalid output, the server falls back to deterministic checks, so the anomaly system has an external-AI path and a local safety net.
9. Alerting and review workflow
- Alerts are first-class entities in the server, with validators, services, and routes dedicated to them.
- The alert lifecycle is review-oriented: results are stored as pending analyst or operations alerts with evidence, uncertainty, and guidance.
- The README makes clear this is a decision-support system, not an automation system that executes financial actions.
10. Operations and provider-facing analytics
- The operations feature area covers provider and agent dashboards, including liquidity monitoring and the Bangladesh area heat map.
- Supporting code includes geocode constants, summary hooks, and utilities for operations-specific aggregation.
- This subsystem ties together operational pressure signals from the database and ML outputs for network-level coordination.
11. Graph and peer-comparison insights
- The insights area is a separate analytical surface that visualizes customer-network relationships and clustering behavior.
- The graph pipeline uses server-side graph insight services and a client ForceGraph/detail-panel UI to explain repeated amounts, repeated interactions, and cross-provider clusters.
- Peer comparison analytics sit alongside this as a contextual baseline for agent behavior rather than a hard enforcement mechanism.
12. Management and admin scope
- Management functionality is isolated into its own routes, controller/service, and client feature area.
- This is the highest administrative boundary in the app, distinct from provider ops and risk analyst workflows.
- The structure suggests user provisioning or oversight flows, not just dashboard viewing.
13. Deployment and runtime boundary
- The architecture is split across three deployable surfaces: Vercel for the client, Render for the Node server, and Render-hosted FastAPI for ML.
- Environment variables define the integration points: database connection, JWT secrets, Gemini key/model, client base URL, and ML API base URL.
- This means the client never talks directly to Postgres, Gemini, or ML; all those dependencies are brokered by the server except the server-to-ML and server-to-Gemini calls.
14. What to show in an architecture diagram
- The most important boxes are: Users, React client, Express API, Postgres, FastAPI LightGBM service, and Gemini API.
- The most important arrows are:
- client → server for authenticated dashboard requests
- server → Postgres for operational data and alerts
- server → ML service for shortage prediction
- server → Gemini for anomaly reasoning
- server → client for role-specific dashboards, alerts, insights, and graph data
Main entry points: App.jsx React Client · src/services State + API · app.js Express API · src/services Domain Services
Components 20
Client
React Vite frontend and feature surfaces
- React Client · Browser UI for auth, dashboards, alerts, insights, and management
client/src/App.jsx - Auth UI · Login, register, and auth shell flows
client/src/features/auth - Dashboards · Role-scoped landing and authenticated dashboard surfaces
client/src/pages/Dashboard.jsx - Operations UI · Provider and agent operational monitoring views
client/src/features/operations - Alerts UI · Provider and risk analyst alert review screens
client/src/features/alerts - Insights UI · Graph and cluster exploration interface
client/src/features/insights - Management UI · Administrative oversight and user management screens
client/src/features/management - State + API · Auth context, API service, endpoint definitions, and feature hooks
client/src/services
Server
Express API, domain services, and persistence
- Express API · Main orchestration layer for auth, operations, alerts, management, and insights
server/src/app.js - Auth Boundary · JWT cookie auth and protected access enforcement
server/src/middlewares/auth.middleware.js - Domain Services · Request handling and business logic for alerts, operations, management, and graphs
server/src/services - Alerts Engine · Alert generation, validation, storage, and review lifecycle
server/src/services/alert.service.js - Operations Data · Provider and agent operational payloads and summaries
server/src/services/liquidityPayload.service.js - Graph Insights · Customer-network and peer-comparison insight generation
server/src/services/graphInsight.service.js - Gemini Reasoning · Schema-validated anomaly reasoning with deterministic fallback support
server/src/services/llm/gemini.js - Postgres · Domain schema, migrations, and seeded demo data
server/src/db/schema.sql
ML Service
Standalone FastAPI model-serving boundary
- FastAPI ML · Standalone liquidity prediction service for shortage inference
ml/app.py - LightGBM Models · Serialized shortage and pressure models used by the ML API
ml/models - Training Pipeline · Data generation, feature engineering, training, and evaluation scripts
ml/src/03_liquidity_forecast_model.py
Other components
- Users · End users and internal roles consuming the system
Connections 27
- Users → React Client: use app · People interact with the browser UI
- React Client → Auth UI: auth flow · Login and registration screens
- React Client → Dashboards: role dashboards · Authenticated landing and dashboard surfaces
- React Client → Operations UI: operations views · Provider and agent monitoring screens
- React Client → Alerts UI: alerts views · Alert review and status screens
- React Client → Insights UI: graph views · Network and peer-comparison analysis screens
- React Client → Management UI: admin views · Management and oversight screens
- Auth UI → State + API: auth state · Auth context and form hooks
- Dashboards → State + API: fetch data · Shared client API access and hooks
- Operations UI → State + API: fetch data · Operations data access through services
- Alerts UI → State + API: fetch data · Alert-specific API access
- Insights UI → State + API: fetch data · Graph data retrieval and view state
- Management UI → State + API: fetch data · Management API access
- React Client → Express API: https · Authenticated UI requests to the API
- Express API → Auth Boundary: protect routes · JWT and provider-aware access control
- Express API → Domain Services: route to logic · Controllers delegate into domain services
- Domain Services → Alerts Engine: alerts · Alert lifecycle and review workflow
- Domain Services → Operations Data: operations · Operational summaries and dashboards
- Domain Services → Graph Insights: insights · Graph and peer-comparison payloads
- Alerts Engine → Postgres: read/write · Persist alerts and consume domain records
- Operations Data → Postgres: read · Load transactions, balances, and provider data
- Graph Insights → Postgres: read · Build relationship and clustering views from stored data
- Alerts Engine → Gemini Reasoning: analyze · Use Gemini for anomaly reasoning when needed
- Operations Data → FastAPI ML: predict shortage · Send recent records for liquidity inference
- FastAPI ML → LightGBM Models: load models · Serve LightGBM artifacts from disk
- FastAPI ML → Training Pipeline: trained by · Training and evaluation generate the model artifacts
- Express API → Postgres: data access · Shared persistence for auth, management, operations, and alerts