How beingzpranav/budget_planner works
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: App.jsx App shell · app.py Flask API · api.js API client · LoginPage.jsx Login
Components 22
ReceiptAI
Top-level application split into frontend and backend runtimes.
- Browser SPA · User-facing single-page application in the browser.
Frontend
React/Vite SPA and shared client-side state.
- App shell · Top-level frontend composition and routing.
frontend/src/App.jsx - Auth state · Holds login/session state across the UI.
frontend/src/AuthContext.jsx - Toasts · Cross-cutting notification and feedback layer.
frontend/src/ToastContext.jsx - API client · Centralized frontend HTTP client for backend calls.
frontend/src/api.js - Login · Email/password and Google sign-in entry point.
frontend/src/pages/LoginPage.jsx - Scan · Receipt upload and capture flow.
frontend/src/pages/ScanPage.jsx - Dashboard · Summary view for spending and account status.
frontend/src/pages/Dashboard.jsx - Expenses · Transaction browsing and expense management.
frontend/src/pages/ExpensesPage.jsx - Budget · Budget limits and category planning view.
frontend/src/pages/BudgetPage.jsx - Analytics · Charts and breakdowns for spending patterns.
frontend/src/pages/AnalyticsPage.jsx - Forecast · Projected spending and budget outlook.
frontend/src/pages/ForecastPage.jsx - Anomalies · Detects unusual spending or receipt patterns.
frontend/src/pages/AnomaliesPage.jsx - Settings · Account and application preferences.
frontend/src/pages/SettingsPage.jsx
Backend
Flask API, OCR, persistence, and derived analytics.
- Flask API · Main backend application entry point and request router.
backend/app.py - Auth · Email/password, Google OAuth, and JWT handling.
- Receipt OCR · Image preprocessing and OCR extraction pipeline.
- Expenses · Stores and updates receipts, expenses, and budgets.
- Insights · Aggregates dashboard metrics, forecasting, and anomalies.
- PostgreSQL · Persistent user, receipt, expense, and budget data.
- Migrations · Alembic schema versioning and initial database setup.
backend/alembic/versions/0001_initial_schema.py - App Runner · Container deployment configuration for the backend runtime.
backend/apprunner.yaml
Connections 32
- 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.