# xswift-coder770/financeos architecture

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

- Interactive diagram: https://gitdiagram.com/xswift-coder770/financeos
- Repository: https://github.com/xswift-coder770/financeos

## Overview

#### Purpose and topology
FinanceOS is a MERN personal-finance platform: authenticated users manage income/expenses, savings goals, and financial habits, while dashboard and analytics endpoints aggregate those records. The React/Vite SPA is deployed separately from the Express API; MongoDB Atlas is the system of record. Deployment targets cited by the repo are Vercel (frontend) and Render (backend).

#### Frontend entry and navigation
The browser application boots through `frontend/src/main.jsx`, composes the application in `frontend/src/App.jsx`, and centralizes page routing in `frontend/src/routes/AppRoutes.jsx`. Shared public/authenticated shell structure is separated into `frontend/src/layouts/MainLayout.jsx` and `frontend/src/layouts/AdminLayout.jsx`. Primary product screens are dashboard, expense tracker, goals, habits, and analytics under `frontend/src/pages/`.

#### Client state and API boundary
`frontend/src/context/AuthContext.jsx` owns session-oriented authentication state and supports persistent client sessions. Page-level operations cross the frontend/backend boundary through Axios-oriented service modules: `frontend/src/services/api.js`, `frontend/src/services/authServices.js`, and domain services such as `frontend/src/services/expenseServices.js`. The API base URL is environment-driven (`VITE_API_URL`), keeping local and deployed API targets outside UI components.

#### API host and request pipeline
`backend/server.js` is the Node/Express entry point: it initializes the HTTP server, database connection, security/cross-origin protections, and route mounting. Routes define REST resources and delegate behavior to controllers, e.g. `backend/routes/expenseRoutes.js` → `backend/controllers/expenseController.js`; equivalent boundaries exist for auth, goals, habits, dashboard, and analytics. `backend/middleware/errorMiddleware.js` provides the backend error boundary.

#### Identity and authorization
Authentication is implemented as register/login/current-user API behavior in `backend/routes/authroutes.js` and `backend/controllers/authController.js`. User credentials and roles persist in `backend/models/User.js`; passwords are hashed with bcrypt and signed JWTs are created by `backend/utils/generateToken.js`. `backend/middleware/authMiddleware.js` protects user-scoped APIs, while `backend/middleware/adminMiddleware.js` supports role-gated access where applied. Auth input validation is isolated in `backend/validations/authValidation.js`.

#### Financial domain persistence
Mongoose models represent the user-owned core records: `backend/models/Expense.js`, `backend/models/Goal.js`, and `backend/models/Habit.js`. Controllers perform CRUD and user scoping for those resource types through `backend/controllers/expenseController.js`, `backend/controllers/goalController.js`, and `backend/controllers/habitController.js`. Expenses cover the README’s income and expense tracking model via record type; goals track target/current amounts and habits track completion.

#### Aggregation and reporting flow
Dashboard and analytics are read-model endpoints rather than separate persistence domains. `backend/controllers/dashboardController.js` produces summary KPIs and recent transactions for `frontend/src/pages/Dashboard.jsx`; `backend/controllers/analyticsController.js` produces financial comparisons/distributions consumed by `frontend/src/pages/WealthAnalytics.jsx`. They derive outputs from the underlying user-scoped financial records, exposed through `backend/routes/dashboardRoutes.js` and `backend/routes/analyticsRoutes.js`.

#### Infrastructure and external dependencies
`backend/config/db.js` connects Mongoose to MongoDB Atlas through `MONGO_URI`. The API relies on JWT secrets and frontend-origin configuration (`JWT_SECRET`, `FRONTEND_URL`); the SPA relies on `VITE_API_URL`. Material runtime stack: React 19/Vite in the browser; Node.js/Express in the API service; MongoDB Atlas as managed database.

Main entry points: [`backend/server.js`](https://github.com/xswift-coder770/financeos/blob/main/backend/server.js) (API host), [`backend/middleware/authMiddleware.js`](https://github.com/xswift-coder770/financeos/blob/main/backend/middleware/authMiddleware.js) (JWT authorization), [`frontend/src/pages/Dashboard.jsx`](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/pages/Dashboard.jsx) (Finance screens), [`backend/controllers/authController.js`](https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/authController.js) (Authentication controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React/Vite SPA"]
  node_browser(("Browser user<br/>client"))
  node_main["SPA bootstrap<br/>React entry<br/>[main.jsx]"]
  node_app["Application composition<br/>React app<br/>[App.jsx]"]
  node_routes["Page routing<br/>React routes<br/>[AppRoutes.jsx]"]
  node_layouts["Public and app shells<br/>React layouts<br/>[MainLayout.jsx]"]
  node_pages["Finance screens<br/>React pages<br/>[Dashboard.jsx]"]
  node_auth_context["Session state<br/>Auth context<br/>[AuthContext.jsx]"]
  node_client_services["API services<br/>Axios services<br/>[api.js]"]
end

subgraph group_backend["Express API"]
  node_server{{"API host<br/>Express server<br/>[server.js]"}}
  node_resource_routes["Protected finance routes<br/>Express routes<br/>[expenseRoutes.js]"]
  node_auth_routes["Auth routes<br/>Express routes<br/>[authroutes.js]"]
  node_report_routes["Reporting routes<br/>Express routes<br/>[dashboardRoutes.js]"]
  node_auth_controller["Authentication controller<br/>[authController.js]"]
  node_finance_controllers["Finance controllers"]
  node_report_controllers["Reporting controllers"]
  node_authorization["JWT authorization<br/>Auth middleware<br/>[authMiddleware.js]"]
  node_error_boundary["API error boundary<br/>Error middleware<br/>[errorMiddleware.js]"]
  node_token_issuer["JWT issuer<br/>Token utility<br/>[generateToken.js]"]
end

subgraph group_data["Data &amp; infrastructure"]
  node_users["Users and roles<br/>Mongoose model<br/>[User.js]"]
  node_financial_records["Financial records<br/>Mongoose models<br/>[Expense.js]"]
  node_database[("MongoDB Atlas<br/>Managed database<br/>[db.js]")]
end

node_browser -->|"loads SPA"| node_main
node_main -->|"renders"| node_app
node_app -->|"mounts"| node_routes
node_routes -->|"selects shell"| node_layouts
node_layouts -->|"hosts"| node_pages
node_pages -->|"reads session"| node_auth_context
node_pages -->|"requests data"| node_client_services
node_client_services -->|"REST via VITE_API_URL"| node_server
node_server -->|"mounts"| node_auth_routes
node_server -->|"mounts"| node_resource_routes
node_server -->|"mounts"| node_report_routes
node_server -.->|"handles errors"| node_error_boundary
node_auth_routes -->|"delegates"| node_auth_controller
node_resource_routes -->|"protects"| node_authorization
node_authorization -->|"authorizes"| node_finance_controllers
node_report_routes -->|"protects"| node_authorization
node_authorization -->|"authorizes"| node_report_controllers
node_auth_controller -->|"registers and verifies"| node_users
node_auth_controller -->|"issues JWT"| node_token_issuer
node_finance_controllers -->|"CRUD and user scope"| node_financial_records
node_report_controllers -->|"aggregates"| node_financial_records
node_users -->|"persists"| node_database
node_financial_records -->|"persists"| node_database

click node_main "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/App.jsx"
click node_routes "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/routes/AppRoutes.jsx"
click node_layouts "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/layouts/MainLayout.jsx"
click node_pages "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/pages/Dashboard.jsx"
click node_auth_context "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/context/AuthContext.jsx"
click node_client_services "https://github.com/xswift-coder770/financeos/blob/main/frontend/src/services/api.js"
click node_server "https://github.com/xswift-coder770/financeos/blob/main/backend/server.js"
click node_resource_routes "https://github.com/xswift-coder770/financeos/blob/main/backend/routes/expenseRoutes.js"
click node_auth_routes "https://github.com/xswift-coder770/financeos/blob/main/backend/routes/authroutes.js"
click node_report_routes "https://github.com/xswift-coder770/financeos/blob/main/backend/routes/dashboardRoutes.js"
click node_auth_controller "https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/authController.js"
click node_finance_controllers "https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/expenseController.js"
click node_report_controllers "https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/dashboardController.js"
click node_authorization "https://github.com/xswift-coder770/financeos/blob/main/backend/middleware/authMiddleware.js"
click node_error_boundary "https://github.com/xswift-coder770/financeos/blob/main/backend/middleware/errorMiddleware.js"
click node_users "https://github.com/xswift-coder770/financeos/blob/main/backend/models/User.js"
click node_financial_records "https://github.com/xswift-coder770/financeos/blob/main/backend/models/Expense.js"
click node_token_issuer "https://github.com/xswift-coder770/financeos/blob/main/backend/utils/generateToken.js"
click node_database "https://github.com/xswift-coder770/financeos/blob/main/backend/config/db.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_browser,node_main,node_app,node_routes,node_layouts,node_pages,node_auth_context,node_client_services toneBlue
class node_server,node_resource_routes,node_auth_routes,node_report_routes,node_auth_controller,node_finance_controllers,node_report_controllers,node_authorization,node_error_boundary,node_token_issuer toneAmber
class node_users,node_financial_records,node_database toneMint
```

## Components

### React/Vite SPA

Browser application deployed independently.

- **Browser user**: client
- [SPA bootstrap](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [Application composition](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/App.jsx): React app · `frontend/src/App.jsx`
- [Page routing](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/routes/AppRoutes.jsx): React routes · `frontend/src/routes/AppRoutes.jsx`
- [Public and app shells](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/layouts/MainLayout.jsx): React layouts · Separates main and authenticated shell structure. · `frontend/src/layouts/MainLayout.jsx`
- [Finance screens](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/pages/Dashboard.jsx): React pages · Dashboard, expenses, goals, habits, and analytics. · `frontend/src/pages/Dashboard.jsx`
- [Session state](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/context/AuthContext.jsx): Auth context · Maintains persistent client authentication state. · `frontend/src/context/AuthContext.jsx`
- [API services](https://github.com/xswift-coder770/financeos/blob/main/frontend/src/services/api.js): Axios services · Uses environment-driven VITE_API_URL. · `frontend/src/services/api.js`

### Express API

Node service serving REST resources.

- [API host](https://github.com/xswift-coder770/financeos/blob/main/backend/server.js): Express server · Initializes HTTP, middleware, database, and route mounting. · `backend/server.js`
- [Protected finance routes](https://github.com/xswift-coder770/financeos/blob/main/backend/routes/expenseRoutes.js): Express routes · Expense, goal, and habit REST boundaries. · `backend/routes/expenseRoutes.js`
- [Auth routes](https://github.com/xswift-coder770/financeos/blob/main/backend/routes/authroutes.js): Express routes · Register, login, and current-user endpoints. · `backend/routes/authroutes.js`
- [Reporting routes](https://github.com/xswift-coder770/financeos/blob/main/backend/routes/dashboardRoutes.js): Express routes · Dashboard and analytics read-model endpoints. · `backend/routes/dashboardRoutes.js`
- [Authentication controller](https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/authController.js): Controller · `backend/controllers/authController.js`
- [Finance controllers](https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/expenseController.js): Controllers · CRUD with user scoping for expenses, goals, and habits. · `backend/controllers/expenseController.js`
- [Reporting controllers](https://github.com/xswift-coder770/financeos/blob/main/backend/controllers/dashboardController.js): Controllers · Builds dashboard KPIs and analytics from financial records. · `backend/controllers/dashboardController.js`
- [JWT authorization](https://github.com/xswift-coder770/financeos/blob/main/backend/middleware/authMiddleware.js): Auth middleware · Protects user APIs and supports role-gated access. · `backend/middleware/authMiddleware.js`
- [API error boundary](https://github.com/xswift-coder770/financeos/blob/main/backend/middleware/errorMiddleware.js): Error middleware · `backend/middleware/errorMiddleware.js`
- [JWT issuer](https://github.com/xswift-coder770/financeos/blob/main/backend/utils/generateToken.js): Token utility · `backend/utils/generateToken.js`

### Data & infrastructure

- [Users and roles](https://github.com/xswift-coder770/financeos/blob/main/backend/models/User.js): Mongoose model · Stores credential hashes and roles. · `backend/models/User.js`
- [Financial records](https://github.com/xswift-coder770/financeos/blob/main/backend/models/Expense.js): Mongoose models · User-owned expenses/income, goals, and habits. · `backend/models/Expense.js`
- [MongoDB Atlas](https://github.com/xswift-coder770/financeos/blob/main/backend/config/db.js): Managed database · System of record connected through MONGO_URI. · `backend/config/db.js`

## Connections

- Browser user → SPA bootstrap: loads SPA
- SPA bootstrap → Application composition: renders
- Application composition → Page routing: mounts
- Page routing → Public and app shells: selects shell
- Public and app shells → Finance screens: hosts
- Finance screens → Session state: reads session
- Finance screens → API services: requests data
- API services → API host: REST via VITE_API_URL
- API host → Auth routes: mounts
- API host → Protected finance routes: mounts
- API host → Reporting routes: mounts
- API host → API error boundary: handles errors
- Auth routes → Authentication controller: delegates
- Protected finance routes → JWT authorization: protects
- JWT authorization → Finance controllers: authorizes
- Reporting routes → JWT authorization: protects
- JWT authorization → Reporting controllers: authorizes
- Authentication controller → Users and roles: registers and verifies
- Authentication controller → JWT issuer: issues JWT
- Finance controllers → Financial records: CRUD and user scope
- Reporting controllers → Financial records: aggregates
- Users and roles → MongoDB Atlas: persists
- Financial records → MongoDB Atlas: persists
