How pushpak1203/msme-cash works
Purpose and Entry Points
An MVP cash-flow forecasting system for Indian MSMEs. It combines a FastAPI API, Supabase-backed user/financial data, forecasting and alert logic, and a Next.js 14 dashboard. Backend starts at backend/main.py; frontend routes begin at frontend/app/page.tsx and frontend/app/layout.tsx.
API and Request Boundary
FastAPI composes domain routes for authentication, transactions, forecasts, alerts, and dashboard aggregation. Protected requests validate Supabase JWTs before accessing user-scoped records.
• backend/main.py
• backend/api/routes/auth.py
• backend/api/routes/transactions.py
• backend/api/routes/forecast.py
• backend/api/routes/dashboard.py
Persistence and Identity
Supabase supplies Postgres persistence and Supabase Auth. The backend holds a singleton service-role client; the browser uses only public Supabase credentials. The initial migration defines schema and RLS isolation; seed data establishes the demo tenant, transaction history, forecasts, and alerts.
• backend/db/supabase_client.py
• backend/db/seed.py
• supabase/migrations/001_initial_schema.sql
Transaction Ingestion Pipeline
Transaction-facing APIs create, update, list, and delete user financial events. A data pipeline can supplement persisted history with realistic Account Aggregator and GST mock sources, establishing an integration boundary that can later be replaced by live providers.
• backend/services/data_pipeline.py
• backend/services/aa_mock.py
• backend/services/gst_mock.py
• backend/api/routes/transactions.py
Forecasting Stage
Historical cash-flow data is transformed into model features and forecast horizons. Prophet is the primary model; ARIMA is the fallback when Prophet cannot import or train. Forecast APIs expose 30/60/90-day outputs and a receivable-delay scenario, likely consuming persisted or generated forecast records.
• backend/ml/feature_engineering.py
• backend/ml/forecaster.py
• backend/ml/model_utils.py
• backend/api/routes/forecast.py
Alert and Dashboard Derivation
The alert engine converts cash-flow conditions into active alerts. Dashboard endpoints aggregate transaction, forecast, and alert state into a summary payload rather than making the frontend orchestrate multiple domain computations.
• backend/alerts/alert_engine.py
• backend/api/routes/alerts.py
• backend/api/routes/dashboard.py
• backend/models/schemas.py
Frontend Consumption
Next.js provides authenticated operational views: login, dashboard, transactions, forecasts, and alerts. Shared UI components render cash-flow charts, scenarios, summaries, and alert indicators; frontend calls the FastAPI base URL while Supabase supports browser authentication/session handling.
• frontend/app/login/page.tsx
• frontend/app/transactions/page.tsx
• frontend/app/forecasts/page.tsx
• frontend/app/alerts/page.tsx
• frontend/app/components/CashFlowChart.tsx
• frontend/app/components/ScenarioSlider.tsx
Main entry points: supabase_client.py Supabase client · main.py FastAPI application · transactions.py Transaction routes · page.tsx Dashboard home
Components 19
Next.js dashboard
- App shell
frontend/app/layout.tsx - Dashboard home
frontend/app/page.tsx - Login
frontend/app/login/page.tsx - Transactions view
frontend/app/transactions/page.tsx - Forecasts view
frontend/app/forecasts/page.tsx - Alerts view
frontend/app/alerts/page.tsx - Charts and scenarios
frontend/app/components/CashFlowChart.tsx
FastAPI backend
- FastAPI application
backend/main.py - Authentication routes · Validates Supabase JWTs for protected access.
backend/api/routes/auth.py - Transaction routes
backend/api/routes/transactions.py - Forecast routes
backend/api/routes/forecast.py - Dashboard routes · Builds a consolidated operational summary.
backend/api/routes/dashboard.py - Alert routes
backend/api/routes/alerts.py
Cash-flow intelligence
- Data pipeline · Supplements history with replaceable AA and GST mock sources.
backend/services/data_pipeline.py - Forecasting engine · Uses Prophet with ARIMA fallback for forecast horizons.
backend/ml/forecaster.py - Feature engineering
backend/ml/feature_engineering.py - Alert engine
backend/alerts/alert_engine.py
Identity and data
- Supabase client · Backend singleton for user-scoped data access.
backend/db/supabase_client.py - Supabase Auth and Postgres · Auth, persistence, and RLS tenant isolation.
supabase/migrations/001_initial_schema.sql
Connections 24
- App shell → Dashboard home
- App shell → Login
- Dashboard home → Dashboard routes: summary API
- Transactions view → Transaction routes: transaction API
- Forecasts view → Forecast routes: forecast API
- Alerts view → Alert routes: alert API
- Dashboard home → Charts and scenarios: renders
- Login → Supabase Auth and Postgres: browser authentication
- FastAPI application → Authentication routes: mounts
- FastAPI application → Transaction routes: mounts
- FastAPI application → Forecast routes: mounts
- FastAPI application → Dashboard routes: mounts
- FastAPI application → Alert routes: mounts
- Authentication routes → Supabase Auth and Postgres: JWT validation
- Transaction routes → Data pipeline: supplement history
- Transaction routes → Supabase client: CRUD records
- Data pipeline → Supabase client: persist events
- Supabase client → Supabase Auth and Postgres: service access
- Forecast routes → Forecasting engine: generate horizons
- Forecasting engine → Feature engineering: transform history
- Feature engineering → Supabase client: historical data
- Alert engine → Supabase client: read/write alerts
- Alert routes → Alert engine: active alerts
- Dashboard routes → Supabase client: aggregate state