# swayam-thecoder/spendwise architecture

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

- Interactive diagram: https://gitdiagram.com/swayam-thecoder/spendwise
- Repository: https://github.com/swayam-thecoder/spendwise

## Overview

SpendWise is a personal-finance application for managing expenses, categories, monthly budgets, and dashboard analytics, with account, session, and email-verification workflows. The main flow is a user using the frontend to submit authenticated requests to the API; route handlers validate and dispatch domain operations, which read or write PostgreSQL through Prisma. The README is empty, so capabilities are inferred from the source index and tree. Frontend-to-API wiring and unsampled service relationships are not shown; those links are omitted rather than assumed.

Main entry points: [`backend/config/prisma.js`](https://github.com/swayam-thecoder/spendwise/blob/main/backend/config/prisma.js) (Prisma client), [`backend/app.js`](https://github.com/swayam-thecoder/spendwise/blob/main/backend/app.js) (Express API), [`backend/middleware/auth.middleware.js`](https://github.com/swayam-thecoder/spendwise/blob/main/backend/middleware/auth.middleware.js) (Auth middleware), [`backend/services/auth.service.js`](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/auth.service.js) (Account and sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_web["Finance screens<br/>[page.tsx]"]
  node_authscreens["Sign-in screens<br/>[page.tsx]"]
  node_apiclient["API client<br/>[client.ts]"]
  node_frontservices["Domain clients<br/>[expense.service.ts]"]
end

subgraph group_api["API and access"]
  node_server["Express API<br/>[app.js]"]
  node_authroutes["Auth routes<br/>[auth.routes.js]"]
  node_expenseroutes["Expense routes<br/>[expense.routes.js]"]
  node_categoryroutes["Category routes<br/>[category.routes.js]"]
  node_budgetroutes["Budget routes<br/>[budget.routes.js]"]
  node_dashroutes["Dashboard routes"]
  node_authguard["Auth middleware<br/>[auth.middleware.js]"]
end

subgraph group_finance["Finance domains"]
  node_expensecontroller["Expense handlers"]
  node_expenseservice["Expense operations<br/>[expense.service.js]"]
  node_categorycontroller["Category handlers"]
  node_categoryservice["Category operations"]
  node_budgetcontroller["Budget handlers"]
  node_budgetservice["Budget calculations<br/>[budget.service.js]"]
  node_dashboardcontroller["Dashboard handlers"]
  node_dashboardservice["Analytics summaries"]
end

subgraph group_identity["Identity services"]
  node_authcontroller["Auth handlers<br/>[auth.controller.js]"]
  node_authservice["Account and sessions<br/>[auth.service.js]"]
  node_email["Email delivery<br/>[email.service.js]"]
  node_token["Token utilities<br/>[token.js]"]
end

subgraph group_storage["Persistence"]
  node_dbclient["Prisma client<br/>[prisma.js]"]
  node_database[("PostgreSQL")]
end

node_user(("Finance user"))

node_user -->|"uses"| node_web
node_user -->|"signs in"| node_authscreens
node_web -.->|"requests"| node_apiclient
node_authscreens -.->|"authenticates"| node_apiclient
node_frontservices -.->|"uses"| node_apiclient
node_server -->|"mounts"| node_authroutes
node_server -->|"mounts"| node_expenseroutes
node_server -->|"mounts"| node_categoryroutes
node_server -->|"mounts"| node_budgetroutes
node_server -->|"mounts"| node_dashroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authroutes -->|"applies"| node_authguard
node_expenseroutes -->|"applies"| node_authguard
node_categoryroutes -->|"applies"| node_authguard
node_budgetroutes -->|"applies"| node_authguard
node_dashroutes -->|"applies"| node_authguard
node_expenseroutes -->|"dispatches"| node_expensecontroller
node_categoryroutes -->|"dispatches"| node_categorycontroller
node_budgetroutes -->|"dispatches"| node_budgetcontroller
node_dashroutes -->|"dispatches"| node_dashboardcontroller
node_authcontroller -->|"calls"| node_authservice
node_authcontroller -->|"generates tokens"| node_token
node_authservice -->|"uses"| node_token
node_authservice -->|"sends mail"| node_email
node_expensecontroller -->|"calls"| node_expenseservice
node_categorycontroller -->|"calls"| node_categoryservice
node_budgetcontroller -->|"calls"| node_budgetservice
node_dashboardcontroller -->|"calls"| node_dashboardservice
node_authservice -->|"queries"| node_dbclient
node_expensecontroller -->|"queries"| node_dbclient
node_expenseservice -->|"queries"| node_dbclient
node_categoryservice -->|"queries"| node_dbclient
node_budgetservice -->|"queries"| node_dbclient
node_dashboardservice -->|"queries"| node_dbclient
node_dbclient -.->|"reads and writes"| node_database

click node_web "https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/app/(dashboard)/dashboard/page.tsx"
click node_authscreens "https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/app/(auth)/login/page.tsx"
click node_apiclient "https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/lib/api/client.ts"
click node_frontservices "https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/services/expense.service.ts"
click node_server "https://github.com/swayam-thecoder/spendwise/blob/main/backend/app.js"
click node_authroutes "https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/auth.routes.js"
click node_expenseroutes "https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/expense.routes.js"
click node_categoryroutes "https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/category.routes.js"
click node_budgetroutes "https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/budget.routes.js"
click node_dashroutes "https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/dashboard.routes.js"
click node_authguard "https://github.com/swayam-thecoder/spendwise/blob/main/backend/middleware/auth.middleware.js"
click node_authcontroller "https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/auth.controller.js"
click node_authservice "https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/auth.service.js"
click node_email "https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/email.service.js"
click node_token "https://github.com/swayam-thecoder/spendwise/blob/main/backend/utils/token.js"
click node_expensecontroller "https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/expense.controller.js"
click node_expenseservice "https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/expense.service.js"
click node_categorycontroller "https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/category.controller.js"
click node_categoryservice "https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/category.service.js"
click node_budgetcontroller "https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/budget.controller.js"
click node_budgetservice "https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/budget.service.js"
click node_dashboardcontroller "https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/dashboard.controller.js"
click node_dashboardservice "https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/dashboard.service.js"
click node_dbclient "https://github.com/swayam-thecoder/spendwise/blob/main/backend/config/prisma.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_web,node_authscreens,node_apiclient,node_frontservices,node_user toneBlue
class node_server,node_authroutes,node_expenseroutes,node_categoryroutes,node_budgetroutes,node_dashroutes,node_authguard toneAmber
class node_expensecontroller,node_expenseservice,node_categorycontroller,node_categoryservice,node_budgetcontroller,node_budgetservice,node_dashboardcontroller,node_dashboardservice toneMint
class node_authcontroller,node_authservice,node_email,node_token toneRose
class node_dbclient,node_database toneIndigo
```

## Components

### Web application

- [Finance screens](https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/app/(dashboard)/dashboard/page.tsx): `frontend/src/app/(dashboard)/dashboard/page.tsx`
- [Sign-in screens](https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/app/(auth)/login/page.tsx): `frontend/src/app/(auth)/login/page.tsx`
- [API client](https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/lib/api/client.ts): `frontend/src/lib/api/client.ts`
- [Domain clients](https://github.com/swayam-thecoder/spendwise/blob/main/frontend/src/services/expense.service.ts): `frontend/src/services/expense.service.ts`

### API and access

- [Express API](https://github.com/swayam-thecoder/spendwise/blob/main/backend/app.js): `backend/app.js`
- [Auth routes](https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/auth.routes.js): `backend/routes/auth.routes.js`
- [Expense routes](https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/expense.routes.js): `backend/routes/expense.routes.js`
- [Category routes](https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/category.routes.js): `backend/routes/category.routes.js`
- [Budget routes](https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/budget.routes.js): `backend/routes/budget.routes.js`
- [Dashboard routes](https://github.com/swayam-thecoder/spendwise/blob/main/backend/routes/dashboard.routes.js): `backend/routes/dashboard.routes.js`
- [Auth middleware](https://github.com/swayam-thecoder/spendwise/blob/main/backend/middleware/auth.middleware.js): `backend/middleware/auth.middleware.js`

### Finance domains

- [Expense handlers](https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/expense.controller.js): `backend/controllers/expense.controller.js`
- [Expense operations](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/expense.service.js): `backend/services/expense.service.js`
- [Category handlers](https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/category.controller.js): `backend/controllers/category.controller.js`
- [Category operations](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/category.service.js): `backend/services/category.service.js`
- [Budget handlers](https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/budget.controller.js): `backend/controllers/budget.controller.js`
- [Budget calculations](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/budget.service.js): `backend/services/budget.service.js`
- [Dashboard handlers](https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/dashboard.controller.js): `backend/controllers/dashboard.controller.js`
- [Analytics summaries](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/dashboard.service.js): `backend/services/dashboard.service.js`

### Identity services

- [Auth handlers](https://github.com/swayam-thecoder/spendwise/blob/main/backend/controllers/auth.controller.js): `backend/controllers/auth.controller.js`
- [Account and sessions](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/auth.service.js): `backend/services/auth.service.js`
- [Email delivery](https://github.com/swayam-thecoder/spendwise/blob/main/backend/services/email.service.js): `backend/services/email.service.js`
- [Token utilities](https://github.com/swayam-thecoder/spendwise/blob/main/backend/utils/token.js): `backend/utils/token.js`

### Persistence

- [Prisma client](https://github.com/swayam-thecoder/spendwise/blob/main/backend/config/prisma.js): `backend/config/prisma.js`
- **PostgreSQL**

### Other components

- **Finance user**

## Connections

- Finance user → Finance screens: uses
- Finance user → Sign-in screens: signs in
- Finance screens → API client: requests
- Sign-in screens → API client: authenticates
- Domain clients → API client: uses
- Express API → Auth routes: mounts (evidence: `backend/app.js`)
- Express API → Expense routes: mounts (evidence: `backend/app.js`)
- Express API → Category routes: mounts (evidence: `backend/app.js`)
- Express API → Budget routes: mounts (evidence: `backend/app.js`)
- Express API → Dashboard routes: mounts (evidence: `backend/app.js`)
- Auth routes → Auth handlers: dispatches (evidence: `backend/routes/auth.routes.js`)
- Auth routes → Auth middleware: applies (evidence: `backend/routes/auth.routes.js`)
- Expense routes → Auth middleware: applies (evidence: `backend/routes/expense.routes.js`)
- Category routes → Auth middleware: applies (evidence: `backend/routes/category.routes.js`)
- Budget routes → Auth middleware: applies (evidence: `backend/routes/budget.routes.js`)
- Dashboard routes → Auth middleware: applies (evidence: `backend/routes/dashboard.routes.js`)
- Expense routes → Expense handlers: dispatches (evidence: `backend/routes/expense.routes.js`)
- Category routes → Category handlers: dispatches (evidence: `backend/routes/category.routes.js`)
- Budget routes → Budget handlers: dispatches (evidence: `backend/routes/budget.routes.js`)
- Dashboard routes → Dashboard handlers: dispatches (evidence: `backend/routes/dashboard.routes.js`)
- Auth handlers → Account and sessions: calls (evidence: `backend/controllers/auth.controller.js`)
- Auth handlers → Token utilities: generates tokens (evidence: `backend/controllers/auth.controller.js`)
- Account and sessions → Token utilities: uses (evidence: `backend/services/auth.service.js`)
- Account and sessions → Email delivery: sends mail (evidence: `backend/services/auth.service.js`)
- Expense handlers → Expense operations: calls (evidence: `backend/controllers/expense.controller.js`)
- Category handlers → Category operations: calls (evidence: `backend/controllers/category.controller.js`)
- Budget handlers → Budget calculations: calls (evidence: `backend/controllers/budget.controller.js`)
- Dashboard handlers → Analytics summaries: calls (evidence: `backend/controllers/dashboard.controller.js`)
- Account and sessions → Prisma client: queries (evidence: `backend/services/auth.service.js`)
- Expense handlers → Prisma client: queries
- Expense operations → Prisma client: queries (evidence: `backend/services/expense.service.js`)
- Category operations → Prisma client: queries (evidence: `backend/services/category.service.js`)
- Budget calculations → Prisma client: queries (evidence: `backend/services/budget.service.js`)
- Analytics summaries → Prisma client: queries (evidence: `backend/services/dashboard.service.js`)
- Prisma client → PostgreSQL: reads and writes
