# anshraz27/aifinancialassistant architecture

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

- Interactive diagram: https://gitdiagram.com/anshraz27/aifinancialassistant
- Repository: https://github.com/anshraz27/aifinancialassistant

## Overview

1. **Overall shape**
   - FinScope is split into two main deployable parts: a **frontend SPA** and a **backend API**.  
   - The frontend handles the user experience for landing, auth, dashboards, and finance management; the backend owns authentication, business logic, persistence, and notifications.

2. **Frontend boundary**
   - The frontend is a **React app** built with **Vite** and styled with **Tailwind CSS**.  
   - It has a public marketing/landing experience (`LandingPage`, `HeroSection`, `FeaturesSection`, etc.) and a private app experience (`DashboardPage`, `BudgetPage`, `TransactionsPage`, `InvestmentsPage`, `ReportsPage`, settings/profile pages).

3. **Authenticated UI flow**
   - `ProtectedRoute` is the main client-side boundary between public and logged-in areas.  
   - `LoginPage` and `SignupPage` feed user credentials into the backend, after which the authenticated pages consume API data through the frontend’s API client.

4. **Frontend data access**
   - `frontend/services/api.js` is the central HTTP boundary from UI to backend.  
   - This layer is where the SPA likely attaches auth tokens and calls the REST endpoints used by dashboard, transaction, budget, report, and investment screens.

5. **Backend entry and application wiring**
   - `backend/server.js` appears to be the process entrypoint, while `backend/server/app.js` is the Express application setup.  
   - This separation usually means `server.js` starts the process and `app.js` configures middleware, route registration, and database connectivity.

6. **Backend API surface**
   - The backend is organized around feature-based controllers and routes: **auth**, **budget**, **dashboard**, **investment**, **report**, and **transaction**.  
   - This structure suggests a REST API where each domain has its own request handling and URL namespace.

7. **Domain model and persistence**
   - The data model layer is centered on four MongoDB-backed entities: **User**, **Transaction**, **Budget**, and **Investment**.  
   - These models are the core persistence boundary for the app’s finance data and support the dashboard and reporting aggregates.

8. **Authentication and security**
   - Authentication is implemented with **JWT-based auth**, supported by `authController`, `authRoute`, `authentication.js`, and middleware in `auth.js` / `authMiddleware.js`.  
   - The likely flow is: user logs in or signs up, backend issues a token, frontend stores/sends it, and protected routes validate it before allowing access.

9. **Financial workflows**
   - Transactions are the primary write path for income and expenses, budgets represent category limits, investments are tracked separately, and dashboards/reports are read-heavy aggregation layers.  
   - `dashboardController` and `reportController` likely summarize stored transactions and budgets into user-facing metrics like balance, monthly totals, and progress indicators.

10. **Notifications and external services**
   - `backend/server/utils/emailService.js` is the explicit integration point for **email alerts**, and the README says it is used for budget threshold notifications.  
   - This makes email the main external service boundary in the repository; MongoDB is the persistence dependency implied by the Mongoose-style model layout.

11. **Feature alignment with the UI**
   - The page structure mirrors the backend domains closely: transaction pages map to transaction APIs, budget pages to budget APIs, and reports/dashboard pages to aggregate endpoints.  
   - This one-to-one mapping makes the architecture easy to diagram as “UI screens → API controllers/routes → models/database.”

12. **Notable implementation gap**
   - The README advertises **AI receipt scanning / OCR**, but there is no dedicated OCR or AI module visible in the file tree.  
   - For an architecture diagram, treat OCR as a product feature mentioned in documentation, but not as a clearly isolated subsystem in the current codebase snapshot.

Main entry points: [`backend/server/app.js`](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/app.js) (App Setup), [`backend/server/models/User.js`](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/models/User.js) (Mongo Models), [`frontend/services/api.js`](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/services/api.js) (API Client), [`frontend/src/main.jsx`](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/main.jsx) (SPA)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_spa["SPA<br/>react-vite app<br/>[main.jsx]"]
  node_frontend_landing["Landing<br/>marketing UI<br/>[LandingPage.jsx]"]
  node_frontend_auth["Auth Pages<br/>login/signup UI<br/>[LoginPage.jsx]"]
  node_frontend_protected{{"Protected Route<br/>auth guard<br/>[ProtectedRoute.jsx]"}}
  node_frontend_app["App Views<br/>authenticated UI<br/>[DashboardPage.jsx]"]
  node_frontend_actions["Income/Expense/Investments<br/>entry flows<br/>[AddExpensePage.jsx]"]
  node_frontend_api["API Client<br/>http client<br/>[api.js]"]
end

subgraph group_backend["Backend"]
  node_backend_entry["Server Entry<br/>node entrypoint<br/>[server.js]"]
  node_backend_app["App Setup<br/>express app<br/>[app.js]"]
  node_backend_auth{{"Auth API<br/>auth controllers/routes<br/>[authController.js]"}}
  node_backend_budget{{"Budget API<br/>budget controller"}}
  node_backend_dashboard{{"Dashboard API<br/>aggregate controller"}}
  node_backend_investment{{"Investment API<br/>investment controller"}}
  node_backend_report{{"Report API<br/>report controller"}}
  node_backend_transaction{{"Transaction API<br/>transaction controller"}}
  node_backend_models[("Mongo Models<br/>mongoose models<br/>[User.js]")]
  node_backend_authmw{{"Auth Middleware<br/>jwt middleware<br/>[authMiddleware.js]"}}
  node_backend_email["Email Alerts<br/>notification service<br/>[emailService.js]"]
end

node_frontend_spa -->|"renders"| node_frontend_landing
node_frontend_spa -->|"routes to"| node_frontend_auth
node_frontend_spa -->|"guards"| node_frontend_protected
node_frontend_protected -->|"allows access"| node_frontend_app
node_frontend_app -->|"fetches data"| node_frontend_api
node_frontend_actions -->|"submits"| node_frontend_api
node_frontend_auth -->|"authenticates via"| node_frontend_api
node_frontend_api -->|"calls"| node_backend_app
node_backend_entry -->|"starts"| node_backend_app
node_backend_app -->|"registers"| node_backend_auth
node_backend_app -->|"registers"| node_backend_budget
node_backend_app -->|"registers"| node_backend_dashboard
node_backend_app -->|"registers"| node_backend_investment
node_backend_app -->|"registers"| node_backend_report
node_backend_app -->|"registers"| node_backend_transaction
node_backend_auth -->|"protects with"| node_backend_authmw
node_backend_budget -->|"persists with"| node_backend_models
node_backend_dashboard -->|"aggregates"| node_backend_models
node_backend_investment -->|"persists with"| node_backend_models
node_backend_report -->|"analyzes"| node_backend_models
node_backend_transaction -->|"persists with"| node_backend_models
node_backend_budget -->|"triggers"| node_backend_email

click node_frontend_spa "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/main.jsx"
click node_frontend_landing "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/components/LandingPage.jsx"
click node_frontend_auth "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/pages/LoginPage.jsx"
click node_frontend_protected "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/components/ProtectedRoute.jsx"
click node_frontend_app "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/pages/DashboardPage.jsx"
click node_frontend_actions "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/pages/AddExpensePage.jsx"
click node_frontend_api "https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/services/api.js"
click node_backend_entry "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server.js"
click node_backend_app "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/app.js"
click node_backend_auth "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/authController.js"
click node_backend_budget "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/budgetController.js"
click node_backend_dashboard "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/dashboardController.js"
click node_backend_investment "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/investmentController.js"
click node_backend_report "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/reportController.js"
click node_backend_transaction "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/transactionController.js"
click node_backend_models "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/models/User.js"
click node_backend_authmw "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/middleware/authMiddleware.js"
click node_backend_email "https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/utils/emailService.js"

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_frontend_spa,node_frontend_landing,node_frontend_auth,node_frontend_protected,node_frontend_app,node_frontend_actions,node_frontend_api toneBlue
class node_backend_entry,node_backend_app,node_backend_auth,node_backend_budget,node_backend_dashboard,node_backend_investment,node_backend_report,node_backend_transaction,node_backend_models,node_backend_authmw,node_backend_email toneAmber
```

## Components

### Frontend

React SPA with public marketing pages and authenticated finance workflows.

- [SPA](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/main.jsx): react-vite app · Client application shell and routing for the user-facing product. · `frontend/src/main.jsx`
- [Landing](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/components/LandingPage.jsx): marketing UI · Public landing experience with hero, features, benefits, testimonials, and CTA sections. · `frontend/src/components/LandingPage.jsx`
- [Auth Pages](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/pages/LoginPage.jsx): login/signup UI · Credential entry screens for login and account creation. · `frontend/src/pages/LoginPage.jsx`
- [Protected Route](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/components/ProtectedRoute.jsx): auth guard · Client-side boundary separating public pages from the authenticated app. · `frontend/src/components/ProtectedRoute.jsx`
- [App Views](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/pages/DashboardPage.jsx): authenticated UI · Private dashboard, budget, transactions, investments, reports, profile, and settings screens. · `frontend/src/pages/DashboardPage.jsx`
- [Income/Expense/Investments](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/src/pages/AddExpensePage.jsx): entry flows · Dedicated forms for creating financial records that feed the main app views. · `frontend/src/pages/AddExpensePage.jsx`
- [API Client](https://github.com/anshraz27/aifinancialassistant/blob/main/frontend/services/api.js): http client · Central frontend boundary for calling backend REST endpoints and handling auth-aware requests. · `frontend/services/api.js`

### Backend

Express API with auth, domain controllers, persistence, and notifications.

- [Server Entry](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server.js): node entrypoint · Process startup entry that launches the backend runtime. · `backend/server.js`
- [App Setup](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/app.js): express app · Express application wiring for middleware, routes, and core server configuration. · `backend/server/app.js`
- [Auth API](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/authController.js): auth controllers/routes · JWT-based signup, login, and token validation flow. · `backend/server/controllers/authController.js`
- [Budget API](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/budgetController.js): budget controller · Budget CRUD and threshold-related domain handling. · `backend/server/controllers/budgetController.js`
- [Dashboard API](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/dashboardController.js): aggregate controller · Read-heavy summary endpoints for balances, trends, and progress metrics. · `backend/server/controllers/dashboardController.js`
- [Investment API](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/investmentController.js): investment controller · Investment tracking endpoints and related domain logic. · `backend/server/controllers/investmentController.js`
- [Report API](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/reportController.js): report controller · Reporting and analytics endpoints derived from stored finance data. · `backend/server/controllers/reportController.js`
- [Transaction API](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/controllers/transactionController.js): transaction controller · Primary income and expense write path plus transaction retrieval. · `backend/server/controllers/transactionController.js`
- [Mongo Models](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/models/User.js): mongoose models · Core persistence entities for users, transactions, budgets, and investments. · `backend/server/models/User.js`
- [Auth Middleware](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/middleware/authMiddleware.js): jwt middleware · Request protection and token verification for secured backend routes. · `backend/server/middleware/authMiddleware.js`
- [Email Alerts](https://github.com/anshraz27/aifinancialassistant/blob/main/backend/server/utils/emailService.js): notification service · Outbound email integration used for budget threshold notifications. · `backend/server/utils/emailService.js`

## Connections

- SPA → Landing: renders · Public shell renders landing and marketing content.
- SPA → Auth Pages: routes to · Handles login and signup entry points.
- SPA → Protected Route: guards · Separates authenticated screens from public pages.
- Protected Route → App Views: allows access · Unlocked users reach private finance views.
- App Views → API Client: fetches data · Authenticated pages consume backend data through the shared client.
- Income/Expense/Investments → API Client: submits · Entry forms create transactions, budgets, and investments through the API client.
- Auth Pages → API Client: authenticates via · Login and signup calls flow through the HTTP client.
- API Client → App Setup: calls · SPA reaches backend REST endpoints through the application server.
- Server Entry → App Setup: starts · Process entry boots the Express app.
- App Setup → Auth API: registers · App wiring mounts auth routes and controllers.
- App Setup → Budget API: registers · Budget API is mounted under its route namespace.
- App Setup → Dashboard API: registers · Dashboard summary endpoints are exposed by the app.
- App Setup → Investment API: registers · Investment routes and handlers are mounted.
- App Setup → Report API: registers · Report endpoints are exposed by the backend.
- App Setup → Transaction API: registers · Transaction routes are wired into the Express app.
- Auth API → Auth Middleware: protects with · JWT validation middleware secures authenticated paths.
- Budget API → Mongo Models: persists with · Budget operations read and write MongoDB-backed models.
- Dashboard API → Mongo Models: aggregates · Dashboard summaries are computed from stored finance entities.
- Investment API → Mongo Models: persists with · Investment operations use the data model layer.
- Report API → Mongo Models: analyzes · Reports derive metrics from persisted records.
- Transaction API → Mongo Models: persists with · Transactions are the primary write path into the database models.
- Budget API → Email Alerts: triggers · Budget threshold events send email alerts.
