# pushpak1203/msme-cash architecture

> Architecture diagram of the GitHub repository pushpak1203/msme-cash, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pushpak1203/msme-cash
- Repository: https://github.com/pushpak1203/msme-cash

## Overview

#### 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: [`backend/db/supabase_client.py`](https://github.com/pushpak1203/msme-cash/blob/main/backend/db/supabase_client.py) (Supabase client), [`backend/main.py`](https://github.com/pushpak1203/msme-cash/blob/main/backend/main.py) (FastAPI application), [`backend/api/routes/transactions.py`](https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/transactions.py) (Transaction routes), [`frontend/app/page.tsx`](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/page.tsx) (Dashboard home)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js dashboard"]
  node_web_shell["App shell<br/>Next.js entry<br/>[layout.tsx]"]
  node_home["Dashboard home<br/>Next.js route<br/>[page.tsx]"]
  node_login["Login<br/>Next.js route<br/>[page.tsx]"]
  node_transaction_view["Transactions view<br/>Next.js route<br/>[page.tsx]"]
  node_forecast_view["Forecasts view<br/>Next.js route<br/>[page.tsx]"]
  node_alert_view["Alerts view<br/>Next.js route<br/>[page.tsx]"]
  node_visual_components["Charts and scenarios<br/>React components<br/>[CashFlowChart.tsx]"]
end

subgraph group_api["FastAPI backend"]
  node_fastapi{{"FastAPI application<br/>API entry<br/>[main.py]"}}
  node_auth_api["Authentication routes<br/>API routes<br/>[auth.py]"]
  node_transaction_api["Transaction routes<br/>API routes<br/>[transactions.py]"]
  node_forecast_api["Forecast routes<br/>API routes<br/>[forecast.py]"]
  node_dashboard_api["Dashboard routes<br/>API routes<br/>[dashboard.py]"]
  node_alert_api["Alert routes<br/>API routes<br/>[alerts.py]"]
end

subgraph group_processing["Cash-flow intelligence"]
  node_ingestion["Data pipeline<br/>Ingestion service<br/>[data_pipeline.py]"]
  node_forecasting["Forecasting engine<br/>ML service<br/>[forecaster.py]"]
  node_features["Feature engineering<br/>ML transform"]
  node_alerts["Alert engine<br/>Rules engine<br/>[alert_engine.py]"]
end

subgraph group_data["Identity and data"]
  node_supabase_client["Supabase client<br/>Service-role client<br/>[supabase_client.py]"]
  node_supabase[("Supabase Auth and Postgres<br/>Managed platform")]
end

node_web_shell --> node_home
node_web_shell --> node_login
node_home -->|"summary API"| node_dashboard_api
node_transaction_view -->|"transaction API"| node_transaction_api
node_forecast_view -->|"forecast API"| node_forecast_api
node_alert_view -->|"alert API"| node_alert_api
node_home -->|"renders"| node_visual_components
node_login -->|"browser authentication"| node_supabase
node_fastapi -->|"mounts"| node_auth_api
node_fastapi -->|"mounts"| node_transaction_api
node_fastapi -->|"mounts"| node_forecast_api
node_fastapi -->|"mounts"| node_dashboard_api
node_fastapi -->|"mounts"| node_alert_api
node_auth_api -->|"JWT validation"| node_supabase
node_transaction_api -->|"supplement history"| node_ingestion
node_transaction_api -->|"CRUD records"| node_supabase_client
node_ingestion -->|"persist events"| node_supabase_client
node_supabase_client -->|"service access"| node_supabase
node_forecast_api -->|"generate horizons"| node_forecasting
node_forecasting -->|"transform history"| node_features
node_features -->|"historical data"| node_supabase_client
node_alerts -->|"read/write alerts"| node_supabase_client
node_alert_api -->|"active alerts"| node_alerts
node_dashboard_api -->|"aggregate state"| node_supabase_client

click node_web_shell "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/layout.tsx"
click node_home "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/page.tsx"
click node_login "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/login/page.tsx"
click node_transaction_view "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/transactions/page.tsx"
click node_forecast_view "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/forecasts/page.tsx"
click node_alert_view "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/alerts/page.tsx"
click node_visual_components "https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/components/CashFlowChart.tsx"
click node_fastapi "https://github.com/pushpak1203/msme-cash/blob/main/backend/main.py"
click node_auth_api "https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/auth.py"
click node_transaction_api "https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/transactions.py"
click node_forecast_api "https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/forecast.py"
click node_dashboard_api "https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/dashboard.py"
click node_alert_api "https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/alerts.py"
click node_ingestion "https://github.com/pushpak1203/msme-cash/blob/main/backend/services/data_pipeline.py"
click node_forecasting "https://github.com/pushpak1203/msme-cash/blob/main/backend/ml/forecaster.py"
click node_features "https://github.com/pushpak1203/msme-cash/blob/main/backend/ml/feature_engineering.py"
click node_alerts "https://github.com/pushpak1203/msme-cash/blob/main/backend/alerts/alert_engine.py"
click node_supabase_client "https://github.com/pushpak1203/msme-cash/blob/main/backend/db/supabase_client.py"
click node_supabase "https://github.com/pushpak1203/msme-cash/blob/main/supabase/migrations/001_initial_schema.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_shell,node_home,node_login,node_transaction_view,node_forecast_view,node_alert_view,node_visual_components toneBlue
class node_fastapi,node_auth_api,node_transaction_api,node_forecast_api,node_dashboard_api,node_alert_api toneAmber
class node_ingestion,node_forecasting,node_features,node_alerts toneMint
class node_supabase_client,node_supabase toneRose
```

## Components

### Next.js dashboard

- [App shell](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/layout.tsx): Next.js entry · `frontend/app/layout.tsx`
- [Dashboard home](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/page.tsx): Next.js route · `frontend/app/page.tsx`
- [Login](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/login/page.tsx): Next.js route · `frontend/app/login/page.tsx`
- [Transactions view](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/transactions/page.tsx): Next.js route · `frontend/app/transactions/page.tsx`
- [Forecasts view](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/forecasts/page.tsx): Next.js route · `frontend/app/forecasts/page.tsx`
- [Alerts view](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/alerts/page.tsx): Next.js route · `frontend/app/alerts/page.tsx`
- [Charts and scenarios](https://github.com/pushpak1203/msme-cash/blob/main/frontend/app/components/CashFlowChart.tsx): React components · `frontend/app/components/CashFlowChart.tsx`

### FastAPI backend

- [FastAPI application](https://github.com/pushpak1203/msme-cash/blob/main/backend/main.py): API entry · `backend/main.py`
- [Authentication routes](https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/auth.py): API routes · Validates Supabase JWTs for protected access. · `backend/api/routes/auth.py`
- [Transaction routes](https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/transactions.py): API routes · `backend/api/routes/transactions.py`
- [Forecast routes](https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/forecast.py): API routes · `backend/api/routes/forecast.py`
- [Dashboard routes](https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/dashboard.py): API routes · Builds a consolidated operational summary. · `backend/api/routes/dashboard.py`
- [Alert routes](https://github.com/pushpak1203/msme-cash/blob/main/backend/api/routes/alerts.py): API routes · `backend/api/routes/alerts.py`

### Cash-flow intelligence

- [Data pipeline](https://github.com/pushpak1203/msme-cash/blob/main/backend/services/data_pipeline.py): Ingestion service · Supplements history with replaceable AA and GST mock sources. · `backend/services/data_pipeline.py`
- [Forecasting engine](https://github.com/pushpak1203/msme-cash/blob/main/backend/ml/forecaster.py): ML service · Uses Prophet with ARIMA fallback for forecast horizons. · `backend/ml/forecaster.py`
- [Feature engineering](https://github.com/pushpak1203/msme-cash/blob/main/backend/ml/feature_engineering.py): ML transform · `backend/ml/feature_engineering.py`
- [Alert engine](https://github.com/pushpak1203/msme-cash/blob/main/backend/alerts/alert_engine.py): Rules engine · `backend/alerts/alert_engine.py`

### Identity and data

- [Supabase client](https://github.com/pushpak1203/msme-cash/blob/main/backend/db/supabase_client.py): Service-role client · Backend singleton for user-scoped data access. · `backend/db/supabase_client.py`
- [Supabase Auth and Postgres](https://github.com/pushpak1203/msme-cash/blob/main/supabase/migrations/001_initial_schema.sql): Managed platform · Auth, persistence, and RLS tenant isolation. · `supabase/migrations/001_initial_schema.sql`

## Connections

- 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
