How xswift-coder770/financeos works
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: server.js API host · authMiddleware.js JWT authorization · Dashboard.jsx Finance screens · authController.js Authentication controller
Components 21
React/Vite SPA
Browser application deployed independently.
- Browser user
- SPA bootstrap
frontend/src/main.jsx - Application composition
frontend/src/App.jsx - Page routing
frontend/src/routes/AppRoutes.jsx - Public and app shells · Separates main and authenticated shell structure.
frontend/src/layouts/MainLayout.jsx - Finance screens · Dashboard, expenses, goals, habits, and analytics.
frontend/src/pages/Dashboard.jsx - Session state · Maintains persistent client authentication state.
frontend/src/context/AuthContext.jsx - API services · Uses environment-driven VITE_API_URL.
frontend/src/services/api.js
Express API
Node service serving REST resources.
- API host · Initializes HTTP, middleware, database, and route mounting.
backend/server.js - Protected finance routes · Expense, goal, and habit REST boundaries.
backend/routes/expenseRoutes.js - Auth routes · Register, login, and current-user endpoints.
backend/routes/authroutes.js - Reporting routes · Dashboard and analytics read-model endpoints.
backend/routes/dashboardRoutes.js - Authentication controller
backend/controllers/authController.js - Finance controllers · CRUD with user scoping for expenses, goals, and habits.
backend/controllers/expenseController.js - Reporting controllers · Builds dashboard KPIs and analytics from financial records.
backend/controllers/dashboardController.js - JWT authorization · Protects user APIs and supports role-gated access.
backend/middleware/authMiddleware.js - API error boundary
backend/middleware/errorMiddleware.js - JWT issuer
backend/utils/generateToken.js
Data & infrastructure
- Users and roles · Stores credential hashes and roles.
backend/models/User.js - Financial records · User-owned expenses/income, goals, and habits.
backend/models/Expense.js - MongoDB Atlas · System of record connected through MONGO_URI.
backend/config/db.js
Connections 23
- 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