# 3narinder/expense-tracker architecture

> Architecture diagram of the GitHub repository 3narinder/expense-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/3narinder/expense-tracker
- Repository: https://github.com/3narinder/expense-tracker

## Overview

#### 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: [`server/app.js`](https://github.com/3narinder/expense-tracker/blob/main/server/app.js) (Express app), [`server/middleware/auth.middleware.js`](https://github.com/3narinder/expense-tracker/blob/main/server/middleware/auth.middleware.js) (Auth and JWT guard), [`server/controllers/transactionController.js`](https://github.com/3narinder/expense-tracker/blob/main/server/controllers/transactionController.js) (Transaction controller), [`server/models/TransactionSchema.js`](https://github.com/3narinder/expense-tracker/blob/main/server/models/TransactionSchema.js) (MongoDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser Product"]
  node_browser_app["React app shell<br/>Vite React<br/>[App.jsx]"]
  node_browser_dashboard["Dashboard query boundary<br/>feature hook"]
  node_browser_services["Resource API services<br/>service adapters<br/>[apiTransaction.js]"]
  node_browser_http["HTTP token transport<br/>Axios auth<br/>[axios.js]"]
end

subgraph group_mobile["Mobile Product"]
  node_mobile_nav["Expo navigation<br/>file-based router<br/>[_layout.tsx]"]
  node_mobile_dashboard["Mobile dashboard query<br/>query hook"]
  node_mobile_api["Mobile budget API<br/>API module<br/>[budgets.ts]"]
end

subgraph group_api["Express API"]
  node_api_boot["API bootstrap<br/>Express runtime<br/>[server.js]"]
  node_api_app["Express app<br/>middleware and mounts<br/>[app.js]"]
  node_auth_boundary["Auth and JWT guard<br/>identity boundary<br/>[auth.middleware.js]"]
  node_rate_limit["Rate limiting<br/>public API boundary"]
  node_finance_routes["Transaction REST routes<br/>route module"]
  node_finance_controller["Transaction controller<br/>domain controller"]
  node_budget_rules["Budget synchronization<br/>budget domain logic<br/>[BudgetSync.js]"]
  node_dashboard_controller["Dashboard analytics<br/>aggregation controller"]
  node_insight_controller["AI insight pipeline<br/>AI controller"]
end

subgraph group_data["Data &amp; Providers"]
  node_mongo[("MongoDB<br/>Mongoose persistence")]
  node_tenant_scope["Profile tenant scope<br/>access utility<br/>[profileScope.js]"]
  node_ai_provider{{"Groq provider<br/>external AI<br/>[groq.js]"}}
end

node_marketing["Marketing site<br/>Next.js<br/>[page.tsx]"]

node_browser_app -->|"renders"| node_browser_dashboard
node_browser_app -->|"uses actions"| node_browser_services
node_browser_dashboard -->|"queries"| node_browser_services
node_browser_services -->|"uses"| node_browser_http
node_browser_http -->|"REST with JWT"| node_api_app
node_mobile_nav -->|"renders"| node_mobile_dashboard
node_mobile_nav -->|"uses"| node_mobile_api
node_mobile_dashboard -->|"dashboard REST"| node_api_app
node_mobile_api -->|"budget REST"| node_api_app
node_marketing -.->|"links to product"| node_browser_app
node_api_boot -->|"starts"| node_api_app
node_api_app -->|"applies"| node_rate_limit
node_rate_limit -->|"protects requests"| node_auth_boundary
node_auth_boundary -->|"authorizes"| node_finance_routes
node_auth_boundary -->|"authorizes"| node_dashboard_controller
node_auth_boundary -->|"authorizes"| node_insight_controller
node_finance_routes -->|"delegates"| node_finance_controller
node_finance_controller -->|"synchronizes budgets"| node_budget_rules
node_finance_controller -->|"scopes records"| node_tenant_scope
node_finance_controller -->|"reads and writes"| node_mongo
node_budget_rules -->|"updates budgets"| node_mongo
node_dashboard_controller -->|"scopes aggregation"| node_tenant_scope
node_dashboard_controller -->|"aggregates records"| node_mongo
node_insight_controller -->|"reads context and stores insights"| node_mongo
node_insight_controller -->|"generates insight"| node_ai_provider

click node_browser_app "https://github.com/3narinder/expense-tracker/blob/main/client/src/App.jsx"
click node_browser_dashboard "https://github.com/3narinder/expense-tracker/blob/main/client/src/features/Dashboard/useDashboardData.js"
click node_browser_services "https://github.com/3narinder/expense-tracker/blob/main/client/src/services/apiTransaction.js"
click node_browser_http "https://github.com/3narinder/expense-tracker/blob/main/client/src/utils/axios.js"
click node_mobile_nav "https://github.com/3narinder/expense-tracker/blob/main/mobile/src/app/_layout.tsx"
click node_mobile_dashboard "https://github.com/3narinder/expense-tracker/blob/main/mobile/src/hooks/queries/useDashboardQuery.ts"
click node_mobile_api "https://github.com/3narinder/expense-tracker/blob/main/mobile/src/services/api/budgets.ts"
click node_marketing "https://github.com/3narinder/expense-tracker/blob/main/web/app/page.tsx"
click node_api_boot "https://github.com/3narinder/expense-tracker/blob/main/server/server.js"
click node_api_app "https://github.com/3narinder/expense-tracker/blob/main/server/app.js"
click node_auth_boundary "https://github.com/3narinder/expense-tracker/blob/main/server/middleware/auth.middleware.js"
click node_rate_limit "https://github.com/3narinder/expense-tracker/blob/main/server/middleware/rateLimiter.middleware.js"
click node_finance_routes "https://github.com/3narinder/expense-tracker/blob/main/server/routes/transaction.routes.js"
click node_finance_controller "https://github.com/3narinder/expense-tracker/blob/main/server/controllers/transactionController.js"
click node_budget_rules "https://github.com/3narinder/expense-tracker/blob/main/server/utils/BudgetSync.js"
click node_dashboard_controller "https://github.com/3narinder/expense-tracker/blob/main/server/controllers/dashboardController.js"
click node_insight_controller "https://github.com/3narinder/expense-tracker/blob/main/server/controllers/aiInsightController.js"
click node_mongo "https://github.com/3narinder/expense-tracker/blob/main/server/models/TransactionSchema.js"
click node_tenant_scope "https://github.com/3narinder/expense-tracker/blob/main/server/utils/profileScope.js"
click node_ai_provider "https://github.com/3narinder/expense-tracker/blob/main/server/utils/groq.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_app,node_browser_dashboard,node_browser_services,node_browser_http toneBlue
class node_mobile_nav,node_mobile_dashboard,node_mobile_api toneAmber
class node_api_boot,node_api_app,node_auth_boundary,node_rate_limit,node_finance_routes,node_finance_controller,node_budget_rules,node_dashboard_controller,node_insight_controller toneMint
class node_mongo,node_tenant_scope,node_ai_provider toneRose
class node_marketing toneNeutral
```

## Components

### Browser Product

- [React app shell](https://github.com/3narinder/expense-tracker/blob/main/client/src/App.jsx): Vite React · Composes browser routing and pages. · `client/src/App.jsx`
- [Dashboard query boundary](https://github.com/3narinder/expense-tracker/blob/main/client/src/features/Dashboard/useDashboardData.js): feature hook · `client/src/features/Dashboard/useDashboardData.js`
- [Resource API services](https://github.com/3narinder/expense-tracker/blob/main/client/src/services/apiTransaction.js): service adapters · Transaction, dashboard, and auth adapters call the API. · `client/src/services/apiTransaction.js`
- [HTTP token transport](https://github.com/3narinder/expense-tracker/blob/main/client/src/utils/axios.js): Axios auth · `client/src/utils/axios.js`

### Mobile Product

- [Expo navigation](https://github.com/3narinder/expense-tracker/blob/main/mobile/src/app/_layout.tsx): file-based router · Authenticated product tabs live beneath this root. · `mobile/src/app/_layout.tsx`
- [Mobile dashboard query](https://github.com/3narinder/expense-tracker/blob/main/mobile/src/hooks/queries/useDashboardQuery.ts): query hook · `mobile/src/hooks/queries/useDashboardQuery.ts`
- [Mobile budget API](https://github.com/3narinder/expense-tracker/blob/main/mobile/src/services/api/budgets.ts): API module · `mobile/src/services/api/budgets.ts`

### Express API

- [API bootstrap](https://github.com/3narinder/expense-tracker/blob/main/server/server.js): Express runtime · `server/server.js`
- [Express app](https://github.com/3narinder/expense-tracker/blob/main/server/app.js): middleware and mounts · `server/app.js`
- [Auth and JWT guard](https://github.com/3narinder/expense-tracker/blob/main/server/middleware/auth.middleware.js): identity boundary · Authenticates users and protects tenant-scoped API requests. · `server/middleware/auth.middleware.js`
- [Rate limiting](https://github.com/3narinder/expense-tracker/blob/main/server/middleware/rateLimiter.middleware.js): public API boundary · `server/middleware/rateLimiter.middleware.js`
- [Transaction REST routes](https://github.com/3narinder/expense-tracker/blob/main/server/routes/transaction.routes.js): route module · `server/routes/transaction.routes.js`
- [Transaction controller](https://github.com/3narinder/expense-tracker/blob/main/server/controllers/transactionController.js): domain controller · `server/controllers/transactionController.js`
- [Budget synchronization](https://github.com/3narinder/expense-tracker/blob/main/server/utils/BudgetSync.js): budget domain logic · Centralizes budget synchronization and period behavior. · `server/utils/BudgetSync.js`
- [Dashboard analytics](https://github.com/3narinder/expense-tracker/blob/main/server/controllers/dashboardController.js): aggregation controller · Builds KPIs, category breakdowns, and trends. · `server/controllers/dashboardController.js`
- [AI insight pipeline](https://github.com/3narinder/expense-tracker/blob/main/server/controllers/aiInsightController.js): AI controller · Serves insight requests and persists generated insights. · `server/controllers/aiInsightController.js`

### Data & Providers

- [MongoDB](https://github.com/3narinder/expense-tracker/blob/main/server/models/TransactionSchema.js): Mongoose persistence · Stores users, accounts, financial records, budgets, and insights. · `server/models/TransactionSchema.js`
- [Profile tenant scope](https://github.com/3narinder/expense-tracker/blob/main/server/utils/profileScope.js): access utility · `server/utils/profileScope.js`
- [Groq provider](https://github.com/3narinder/expense-tracker/blob/main/server/utils/groq.js): external AI · Requires provider keys in environment infrastructure. · `server/utils/groq.js`

### Other components

- [Marketing site](https://github.com/3narinder/expense-tracker/blob/main/web/app/page.tsx): Next.js · Independent public acquisition surface. · `web/app/page.tsx`

## Connections

- 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
