How 3narinder/expense-tracker works
Purpose and deployable surfaces
ExpenseAI is a multi-client personal-finance product: users record transactions, categorize spending, manage budgets/accounts, view dashboard analytics, and request AI-generated insights. Its primary runtime is the Express/MongoDB API in server/; product clients are React/Vite (client/) and Expo React Native (mobile/). The separate Next.js marketing site lives in web/.
Backend API composition
The API boots through server/server.js and server/app.js, connects to MongoDB via server/config/db.js, and mounts domain route modules. Routes delegate to controllers, separating HTTP concerns from domain operations: e.g. server/routes/transaction.routes.js, server/controllers/transactionController.js, and server/routes/dashboard.routes.js.
Identity, access, and tenant scope
Authentication is handled by server/routes/auth.routes.js and server/controllers/authController.js; JWT protection is applied through server/middleware/auth.middleware.js. Users, accounts, and profile-scoped financial records are represented by server/models/UserSchema.js, server/models/AccountSchema.js, and server/utils/profileScope.js. Rate limiting forms a public API boundary in server/middleware/rateLimiter.middleware.js.
Financial data model and mutation flow
Transactions, categories, and budgets are persisted as MongoDB/Mongoose models in server/models/TransactionSchema.js, server/models/CategorySchema.js, and server/models/BudgetSchema.js. Client mutations flow from domain API services to authenticated REST endpoints, then controllers and models. Budget synchronization/period behavior is centralized server-side in server/utils/BudgetSync.js and server/utils/BudgetPeriod.js, rather than duplicated in clients.
Analytics and AI insight pipeline
Dashboard endpoints aggregate financial records for KPIs, category breakdowns, and trends through server/controllers/dashboardController.js; the browser consumes this as a feature-level query boundary in client/src/features/Dashboard/useDashboardData.js. AI insights have their own route/controller/model boundary—server/routes/aiInsight.routes.js, server/controllers/aiInsightController.js, server/models/InsightSchema.js—and use prompt/provider utilities in server/utils/Prompt.js and server/utils/groq.js. AI provider keys are required environment infrastructure.
Browser application
The Vite React entry point is client/src/main.jsx, with application composition/routing in client/src/App.jsx. Page-level screens (client/src/pages/Dashboard.jsx, client/src/pages/Transactions.jsx, client/src/pages/Insight.jsx) assemble reusable UI and feature hooks. Hooks own loading, caching/action orchestration and call resource-specific service adapters such as client/src/services/apiTransaction.js, client/src/services/apiDashboard.js, and client/src/services/apiAuth.js; Axios/token handling is isolated in client/src/utils/axios.js and client/src/utils/authToken.js.
Mobile and marketing boundaries
The Expo app uses file-based navigation, rooted at mobile/src/app/_layout.tsx, with authenticated product tabs under mobile/src/app/(tabs)/. Its current data access includes dashboard/budget query hooks and API modules at mobile/src/hooks/queries/useDashboardQuery.ts, mobile/src/services/api/dashboard.ts, and mobile/src/services/api/budgets.ts. web/app/page.tsx and web/app/layout.tsx form an independent Next.js public acquisition site; it should link into, not share runtime ownership of, the product application.
Main entry points: app.js Express app · auth.middleware.js Auth and JWT guard · transactionController.js Transaction controller · TransactionSchema.js MongoDB
Components 20
Browser Product
- React app shell · Composes browser routing and pages.
client/src/App.jsx - Dashboard query boundary
client/src/features/Dashboard/useDashboardData.js - Resource API services · Transaction, dashboard, and auth adapters call the API.
client/src/services/apiTransaction.js - HTTP token transport
client/src/utils/axios.js
Mobile Product
- Expo navigation · Authenticated product tabs live beneath this root.
mobile/src/app/_layout.tsx - Mobile dashboard query
mobile/src/hooks/queries/useDashboardQuery.ts - Mobile budget API
mobile/src/services/api/budgets.ts
Express API
- API bootstrap
server/server.js - Express app
server/app.js - Auth and JWT guard · Authenticates users and protects tenant-scoped API requests.
server/middleware/auth.middleware.js - Rate limiting
server/middleware/rateLimiter.middleware.js - Transaction REST routes
server/routes/transaction.routes.js - Transaction controller
server/controllers/transactionController.js - Budget synchronization · Centralizes budget synchronization and period behavior.
server/utils/BudgetSync.js - Dashboard analytics · Builds KPIs, category breakdowns, and trends.
server/controllers/dashboardController.js - AI insight pipeline · Serves insight requests and persists generated insights.
server/controllers/aiInsightController.js
Data & Providers
- MongoDB · Stores users, accounts, financial records, budgets, and insights.
server/models/TransactionSchema.js - Profile tenant scope
server/utils/profileScope.js - Groq provider · Requires provider keys in environment infrastructure.
server/utils/groq.js
Other components
- Marketing site · Independent public acquisition surface.
web/app/page.tsx
Connections 25
- React app shell → Dashboard query boundary: renders
- React app shell → Resource API services: uses actions
- Dashboard query boundary → Resource API services: queries
- Resource API services → HTTP token transport: uses
- HTTP token transport → Express app: REST with JWT
- Expo navigation → Mobile dashboard query: renders
- Expo navigation → Mobile budget API: uses
- Mobile dashboard query → Express app: dashboard REST
- Mobile budget API → Express app: budget REST
- Marketing site → React app shell: links to product
- API bootstrap → Express app: starts
- Express app → Rate limiting: applies
- Rate limiting → Auth and JWT guard: protects requests
- Auth and JWT guard → Transaction REST routes: authorizes
- Auth and JWT guard → Dashboard analytics: authorizes
- Auth and JWT guard → AI insight pipeline: authorizes
- Transaction REST routes → Transaction controller: delegates
- Transaction controller → Budget synchronization: synchronizes budgets
- Transaction controller → Profile tenant scope: scopes records
- Transaction controller → MongoDB: reads and writes
- Budget synchronization → MongoDB: updates budgets
- Dashboard analytics → Profile tenant scope: scopes aggregation
- Dashboard analytics → MongoDB: aggregates records
- AI insight pipeline → MongoDB: reads context and stores insights
- AI insight pipeline → Groq provider: generates insight