# beingzpranav/budget_planner architecture

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

- Interactive diagram: https://gitdiagram.com/beingzpranav/budget_planner
- Repository: https://github.com/beingzpranav/budget_planner

## Overview

1. **Overall shape**
   - ReceiptAI is a two-tier application: a **React/Vite single-page frontend** in `frontend/` and a **Flask backend API** in `backend/`.
   - The main runtime flow is: **user action in browser → frontend API call → Flask business logic / OCR / database → JSON response back to UI**.

2. **Frontend as the presentation and orchestration layer**
   - The frontend is organized around route-level pages in `frontend/src/pages/`: `Login`, `Scan`, `Dashboard`, `Expenses`, `Budget`, `Analytics`, `Forecast`, `Anomalies`, and `Settings`.
   - This suggests the UI is not just decorative; it is the primary place where users upload receipts, review extracted expense data, inspect forecasts, and manage budgets.

3. **Shared client-side state and API boundary**
   - `AuthContext.jsx` likely owns session/auth state across the app, while `ToastContext.jsx` handles cross-cutting notifications.
   - `api.js` is the main client boundary to the backend, centralizing HTTP calls so pages and components do not talk to Flask directly.
   - This clean separation makes the frontend a consumer of backend services rather than embedding business rules in UI code.

4. **Frontend UI composition**
   - Reusable UI is split into `components/`, including a `Sidebar`, a `Loader`, and navigation/header components.
   - The README’s mention of Shadcn-inspired styling, Tailwind, and Framer Motion indicates the frontend includes strong presentational concerns: animated navigation, dark theme styling, and responsive dashboard components.
   - `recharts` is likely used in the analytics/forecast pages to render spend trends and category breakdowns.

5. **Receipt scanning pipeline**
   - The `ScanPage` is the user entry point for receipt ingestion.
   - The backend is responsible for OCR and extraction, using the stack described in the README: **EasyOCR + PyTorch**, with **Pillow** and **NumPy** for image preprocessing.
   - The architecture likely follows: **upload image → backend preprocesses image → OCR extraction → merchant/items/tax/category inference → structured expense record returned to frontend**.

6. **Financial data and persistence**
   - The backend uses **SQLAlchemy** with **Alembic migrations**, which means the system has a relational data model and an explicit schema evolution path.
   - `backend/alembic/versions/0001_initial_schema.py` shows there is at least one formal schema migration, and `models.txt` suggests the model layer is documented or enumerated separately.
   - PostgreSQL is the backing store, with the README calling out Neon as the hosted database environment.

7. **Auth and user isolation**
   - The README states support for **email/password** and **Google OAuth**, with **JWT authorization**.
   - This implies a backend-authenticated API model where the frontend obtains a token and sends it on requests, and the backend scopes all expense/receipt/budget data to the authenticated user.
   - Per-user silos are a key architectural boundary: receipts, budgets, and analytics must be filtered by user identity at the API and database query layers.

8. **Analytics, forecasting, and anomaly detection**
   - The `Dashboard`, `AnalyticsPage`, `ForecastPage`, and `AnomaliesPage` imply separate views over the same core financial dataset.
   - The backend likely supplies aggregate summaries and derived metrics, while the frontend focuses on visualization and interaction.
   - The README’s “30-day budget forecast” and “anomaly detection” indicate these are computed features layered on top of stored historical expenses, not standalone user-entered data.

9. **Budgeting and expense management**
   - `BudgetPage` and `ExpensesPage` represent operational CRUD surfaces for managing categories, limits, and historical transactions.
   - This is the core business-data loop after receipt extraction: **scan receipt → store expense → inspect/edit/delete expense → compare against budget → surface analytics and anomalies**.

10. **Backend deployment and environment boundaries**
   - `backend/app.py` is the Flask entry point, and `backend/apprunner.yaml` suggests deployment to **AWS App Runner** or a similar container service.
   - `backend/.env.example` and `frontend/.env.example` show both sides rely on environment-based configuration, likely for API URLs, auth keys, and database credentials.
   - The frontend is built with Vite, so it is likely deployed separately from the backend and connected over HTTP(S).

11. **Operational / utility code**
   - `replace_currency.py` is a repo-level utility script, likely for data cleanup or text transformation related to currency parsing.
   - `backend/test_gemini.py` appears to be a standalone test or experimental integration file, but the main documented OCR stack is EasyOCR/PyTorch, so it should not be treated as a core subsystem unless verified.

12. **How to draw the architecture**
   - The clean diagram is: **Browser SPA** on the left, **Flask API + OCR/analytics/auth logic** in the center, and **PostgreSQL** on the right.
   - Add a secondary inbound path from the browser to the backend for **receipt image uploads**, and a token-based auth flow for **login / Google SSO / JWT-protected requests**.
   - The frontend’s pages sit above the API client and contexts; the backend’s subdomains are **auth**, **receipt ingestion/OCR**, **expense/budget persistence**, and **analytics/forecasting**.

Main entry points: [`frontend/src/App.jsx`](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/App.jsx) (App shell), [`backend/app.py`](https://github.com/beingzpranav/budget_planner/blob/main/backend/app.py) (Flask API), [`frontend/src/api.js`](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/api.js) (API client), [`frontend/src/pages/LoginPage.jsx`](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/LoginPage.jsx) (Login)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_root["ReceiptAI"]
  node_browser["Browser SPA<br/>user client"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>react shell<br/>[App.jsx]"]
  node_auth_ctx["Auth state<br/>react context<br/>[AuthContext.jsx]"]
  node_toast_ctx["Toasts<br/>ui context<br/>[ToastContext.jsx]"]
  node_api_client["API client<br/>http boundary<br/>[api.js]"]
  node_login_page["Login<br/>page<br/>[LoginPage.jsx]"]
  node_scan_page["Scan<br/>page<br/>[ScanPage.jsx]"]
  node_dashboard_page["Dashboard<br/>page<br/>[Dashboard.jsx]"]
  node_expenses_page["Expenses<br/>page<br/>[ExpensesPage.jsx]"]
  node_budget_page["Budget<br/>page<br/>[BudgetPage.jsx]"]
  node_analytics_page["Analytics<br/>page<br/>[AnalyticsPage.jsx]"]
  node_forecast_page["Forecast<br/>page<br/>[ForecastPage.jsx]"]
  node_anomalies_page["Anomalies<br/>page<br/>[AnomaliesPage.jsx]"]
  node_settings_page["Settings<br/>page<br/>[SettingsPage.jsx]"]
end

subgraph group_backend["Backend"]
  node_flask_app["Flask API<br/>backend entry<br/>[app.py]"]
  node_auth_service["Auth<br/>security service"]
  node_ocr_service["Receipt OCR<br/>ingestion service"]
  node_expense_service["Expenses<br/>domain service"]
  node_insights_service["Insights<br/>analytics service"]
  node_db[("PostgreSQL<br/>relational store")]
  node_migrations["Migrations<br/>schema evolution"]
  node_deploy["App Runner<br/>deployment config<br/>[apprunner.yaml]"]
end

node_browser -->|"uses"| node_frontend_app
node_frontend_app -->|"wraps"| node_auth_ctx
node_frontend_app -->|"wraps"| node_toast_ctx
node_frontend_app -->|"calls"| node_api_client
node_frontend_app -->|"routes"| node_login_page
node_frontend_app -->|"routes"| node_scan_page
node_frontend_app -->|"routes"| node_dashboard_page
node_frontend_app -->|"routes"| node_expenses_page
node_frontend_app -->|"routes"| node_budget_page
node_frontend_app -->|"routes"| node_analytics_page
node_frontend_app -->|"routes"| node_forecast_page
node_frontend_app -->|"routes"| node_anomalies_page
node_frontend_app -->|"routes"| node_settings_page
node_api_client -->|"HTTP API"| node_flask_app
node_login_page -->|"auth flow"| node_auth_service
node_scan_page -->|"upload"| node_ocr_service
node_ocr_service -->|"extracts to"| node_expense_service
node_expense_service -->|"persists"| node_db
node_auth_service -->|"verifies"| node_db
node_insights_service -->|"reads"| node_db
node_dashboard_page -->|"reads"| node_insights_service
node_analytics_page -->|"reads"| node_insights_service
node_forecast_page -->|"reads"| node_insights_service
node_anomalies_page -->|"reads"| node_insights_service
node_expenses_page -->|"manages"| node_expense_service
node_budget_page -->|"manages"| node_expense_service
node_flask_app -->|"dispatches"| node_auth_service
node_flask_app -->|"dispatches"| node_ocr_service
node_flask_app -->|"dispatches"| node_expense_service
node_flask_app -->|"dispatches"| node_insights_service
node_migrations -->|"migrates"| node_db
node_deploy -.->|"runs"| node_flask_app

click node_frontend_app "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/App.jsx"
click node_auth_ctx "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/AuthContext.jsx"
click node_toast_ctx "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/ToastContext.jsx"
click node_api_client "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/api.js"
click node_login_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/LoginPage.jsx"
click node_scan_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/ScanPage.jsx"
click node_dashboard_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/Dashboard.jsx"
click node_expenses_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/ExpensesPage.jsx"
click node_budget_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/BudgetPage.jsx"
click node_analytics_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/AnalyticsPage.jsx"
click node_forecast_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/ForecastPage.jsx"
click node_anomalies_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/AnomaliesPage.jsx"
click node_settings_page "https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/SettingsPage.jsx"
click node_flask_app "https://github.com/beingzpranav/budget_planner/blob/main/backend/app.py"
click node_migrations "https://github.com/beingzpranav/budget_planner/blob/main/backend/alembic/versions/0001_initial_schema.py"
click node_deploy "https://github.com/beingzpranav/budget_planner/blob/main/backend/apprunner.yaml"

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_browser toneBlue
class node_frontend_app,node_auth_ctx,node_toast_ctx,node_api_client,node_login_page,node_scan_page,node_dashboard_page,node_expenses_page,node_budget_page,node_analytics_page,node_forecast_page,node_anomalies_page,node_settings_page toneAmber
class node_flask_app,node_auth_service,node_ocr_service,node_expense_service,node_insights_service,node_db,node_migrations,node_deploy toneMint
```

## Components

### ReceiptAI

Top-level application split into frontend and backend runtimes.

- **Browser SPA**: user client · User-facing single-page application in the browser.

### Frontend

React/Vite SPA and shared client-side state.

- [App shell](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/App.jsx): react shell · Top-level frontend composition and routing. · `frontend/src/App.jsx`
- [Auth state](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/AuthContext.jsx): react context · Holds login/session state across the UI. · `frontend/src/AuthContext.jsx`
- [Toasts](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/ToastContext.jsx): ui context · Cross-cutting notification and feedback layer. · `frontend/src/ToastContext.jsx`
- [API client](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/api.js): http boundary · Centralized frontend HTTP client for backend calls. · `frontend/src/api.js`
- [Login](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/LoginPage.jsx): page · Email/password and Google sign-in entry point. · `frontend/src/pages/LoginPage.jsx`
- [Scan](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/ScanPage.jsx): page · Receipt upload and capture flow. · `frontend/src/pages/ScanPage.jsx`
- [Dashboard](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/Dashboard.jsx): page · Summary view for spending and account status. · `frontend/src/pages/Dashboard.jsx`
- [Expenses](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/ExpensesPage.jsx): page · Transaction browsing and expense management. · `frontend/src/pages/ExpensesPage.jsx`
- [Budget](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/BudgetPage.jsx): page · Budget limits and category planning view. · `frontend/src/pages/BudgetPage.jsx`
- [Analytics](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/AnalyticsPage.jsx): page · Charts and breakdowns for spending patterns. · `frontend/src/pages/AnalyticsPage.jsx`
- [Forecast](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/ForecastPage.jsx): page · Projected spending and budget outlook. · `frontend/src/pages/ForecastPage.jsx`
- [Anomalies](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/AnomaliesPage.jsx): page · Detects unusual spending or receipt patterns. · `frontend/src/pages/AnomaliesPage.jsx`
- [Settings](https://github.com/beingzpranav/budget_planner/blob/main/frontend/src/pages/SettingsPage.jsx): page · Account and application preferences. · `frontend/src/pages/SettingsPage.jsx`

### Backend

Flask API, OCR, persistence, and derived analytics.

- [Flask API](https://github.com/beingzpranav/budget_planner/blob/main/backend/app.py): backend entry · Main backend application entry point and request router. · `backend/app.py`
- **Auth**: security service · Email/password, Google OAuth, and JWT handling.
- **Receipt OCR**: ingestion service · Image preprocessing and OCR extraction pipeline.
- **Expenses**: domain service · Stores and updates receipts, expenses, and budgets.
- **Insights**: analytics service · Aggregates dashboard metrics, forecasting, and anomalies.
- **PostgreSQL**: relational store · Persistent user, receipt, expense, and budget data.
- [Migrations](https://github.com/beingzpranav/budget_planner/blob/main/backend/alembic/versions/0001_initial_schema.py): schema evolution · Alembic schema versioning and initial database setup. · `backend/alembic/versions/0001_initial_schema.py`
- [App Runner](https://github.com/beingzpranav/budget_planner/blob/main/backend/apprunner.yaml): deployment config · Container deployment configuration for the backend runtime. · `backend/apprunner.yaml`

## Connections

- Browser SPA → App shell: uses · The browser loads and runs the SPA.
- App shell → Auth state: wraps · Application composition provides shared auth state.
- App shell → Toasts: wraps · Application composition provides global notifications.
- App shell → API client: calls · Pages and components use the shared API boundary.
- App shell → Login: routes · Route-level login screen.
- App shell → Scan: routes · Route-level receipt scanning screen.
- App shell → Dashboard: routes · Route-level summary dashboard.
- App shell → Expenses: routes · Route-level expense management screen.
- App shell → Budget: routes · Route-level budget screen.
- App shell → Analytics: routes · Route-level analytics screen.
- App shell → Forecast: routes · Route-level forecasting screen.
- App shell → Anomalies: routes · Route-level anomaly screen.
- App shell → Settings: routes · Route-level settings screen.
- API client → Flask API: HTTP API · Client requests flow into the Flask backend.
- Login → Auth: auth flow · Login and OAuth requests are authenticated server-side.
- Scan → Receipt OCR: upload · Receipt images are sent for preprocessing and OCR.
- Receipt OCR → Expenses: extracts to · OCR output is transformed into structured expense data.
- Expenses → PostgreSQL: persists · Expenses, receipts, users, and budgets are stored in PostgreSQL.
- Auth → PostgreSQL: verifies · User records, credentials, and tokens depend on the database.
- Insights → PostgreSQL: reads · Aggregations and derived metrics are computed from stored history.
- Dashboard → Insights: reads · Dashboard consumes summary metrics.
- Analytics → Insights: reads · Analytics consumes grouped spend data.
- Forecast → Insights: reads · Forecasting consumes historical expense trends.
- Anomalies → Insights: reads · Anomaly detection consumes derived signals.
- Expenses → Expenses: manages · Expense CRUD and review operations.
- Budget → Expenses: manages · Budget thresholds and category limits.
- Flask API → Auth: dispatches · Backend routes request authentication and authorization.
- Flask API → Receipt OCR: dispatches · Backend routes receipt ingestion work to OCR logic.
- Flask API → Expenses: dispatches · Backend routes CRUD and business operations.
- Flask API → Insights: dispatches · Backend routes dashboard and derived metric requests.
- Migrations → PostgreSQL: migrates · Alembic maintains the relational schema.
- App Runner → Flask API: runs · Deployment config packages and runs the API service.
