# damtoan-it05/expense-manager-backend architecture

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

- Interactive diagram: https://gitdiagram.com/damtoan-it05/expense-manager-backend
- Repository: https://github.com/damtoan-it05/expense-manager-backend

## Overview

Expense Manager is a personal income-and-expense backend API. Clients send requests to the Express app, which mounts feature routes; protected routes authenticate users, operate on MongoDB-backed records, and return results. The main domain stages are account access, category management, transaction tracking, budgeting with spend alerts, and statistics; administrators also manage users and inspect system totals. The graph reflects the sampled routes and README capabilities. Source evidence for unsampled details is limited, so unverified relationships are omitted.

Main entry points: [`Backend/src/app.js`](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/app.js) (Express app), [`Backend/src/middleware/auth.js`](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/middleware/auth.js) (JWT access), [`Backend/src/routes/admin.js`](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/admin.js) (Admin routes), [`Backend/src/routes/budgets.js`](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/budgets.js) (Budget routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API entry"]
  node_app["Express app<br/>[app.js]"]
end

subgraph group_features["Expense features"]
  node_auth_routes["Account routes<br/>[auth.js]"]
  node_category_routes["Category routes<br/>[categories.js]"]
  node_transaction_routes["Transaction routes<br/>[transactions.js]"]
  node_budget_routes["Budget routes<br/>[budgets.js]"]
  node_statistics_routes["Statistics routes<br/>[statistics.js]"]
  node_admin_routes["Admin routes<br/>[admin.js]"]
end

subgraph group_access["Access control"]
  node_auth_middleware["JWT access<br/>[auth.js]"]
end

subgraph group_data["Domain data"]
  node_user_model[("User records<br/>[User.js]")]
  node_category_model[("Category records<br/>[Category.js]")]
  node_transaction_model[("Transaction records<br/>[Transaction.js]")]
  node_budget_model[("Budget records<br/>[Budget.js]")]
end

node_client(("API client"))
node_mongo[("MongoDB")]

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_auth_routes
node_app -->|"mounts routes"| node_category_routes
node_app -->|"mounts routes"| node_transaction_routes
node_app -->|"mounts routes"| node_budget_routes
node_app -->|"mounts routes"| node_statistics_routes
node_app -->|"mounts routes"| node_admin_routes
node_app -->|"connects to"| node_mongo
node_auth_routes -->|"reads and writes"| node_user_model
node_auth_routes -->|"protects account actions"| node_auth_middleware
node_category_routes -->|"protects routes"| node_auth_middleware
node_category_routes -->|"reads and writes"| node_category_model
node_transaction_routes -->|"protects routes"| node_auth_middleware
node_transaction_routes -->|"reads and writes"| node_transaction_model
node_transaction_routes -->|"checks categories"| node_category_model
node_budget_routes -->|"protects routes"| node_auth_middleware
node_budget_routes -->|"reads and writes"| node_budget_model
node_budget_routes -->|"aggregates spending"| node_transaction_model
node_budget_routes -->|"validates categories"| node_category_model
node_statistics_routes -->|"protects routes"| node_auth_middleware
node_statistics_routes -->|"aggregates transactions"| node_transaction_model
node_statistics_routes -->|"looks up categories"| node_category_model
node_admin_routes -->|"requires admin"| node_auth_middleware
node_admin_routes -->|"manages users"| node_user_model
node_admin_routes -->|"aggregates activity"| node_transaction_model
node_admin_routes -->|"deletes user budgets"| node_budget_model
node_admin_routes -->|"deletes user categories"| node_category_model
node_auth_middleware -->|"loads user"| node_user_model

click node_app "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/app.js"
click node_auth_routes "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/auth.js"
click node_category_routes "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/categories.js"
click node_transaction_routes "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/transactions.js"
click node_budget_routes "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/budgets.js"
click node_statistics_routes "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/statistics.js"
click node_admin_routes "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/admin.js"
click node_auth_middleware "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/middleware/auth.js"
click node_user_model "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/User.js"
click node_category_model "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/Category.js"
click node_transaction_model "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/Transaction.js"
click node_budget_model "https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/Budget.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_app,node_client toneBlue
class node_auth_routes,node_category_routes,node_transaction_routes,node_budget_routes,node_statistics_routes,node_admin_routes,node_mongo toneAmber
class node_auth_middleware toneMint
class node_user_model,node_category_model,node_transaction_model,node_budget_model toneRose
```

## Components

### API entry

- [Express app](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/app.js): `Backend/src/app.js`

### Expense features

- [Account routes](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/auth.js): `Backend/src/routes/auth.js`
- [Category routes](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/categories.js): `Backend/src/routes/categories.js`
- [Transaction routes](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/transactions.js): `Backend/src/routes/transactions.js`
- [Budget routes](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/budgets.js): `Backend/src/routes/budgets.js`
- [Statistics routes](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/statistics.js): `Backend/src/routes/statistics.js`
- [Admin routes](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/routes/admin.js): `Backend/src/routes/admin.js`

### Access control

- [JWT access](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/middleware/auth.js): `Backend/src/middleware/auth.js`

### Domain data

- [User records](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/User.js): `Backend/src/models/User.js`
- [Category records](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/Category.js): `Backend/src/models/Category.js`
- [Transaction records](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/Transaction.js): `Backend/src/models/Transaction.js`
- [Budget records](https://github.com/damtoan-it05/expense-manager-backend/blob/main/Backend/src/models/Budget.js): `Backend/src/models/Budget.js`

### Other components

- **API client**
- **MongoDB**

## Connections

- API client → Express app: sends requests (evidence: `README.md`)
- Express app → Account routes: mounts routes (evidence: `Backend/src/app.js`)
- Express app → Category routes: mounts routes (evidence: `Backend/src/app.js`)
- Express app → Transaction routes: mounts routes (evidence: `Backend/src/app.js`)
- Express app → Budget routes: mounts routes (evidence: `Backend/src/app.js`)
- Express app → Statistics routes: mounts routes (evidence: `Backend/src/app.js`)
- Express app → Admin routes: mounts routes (evidence: `Backend/src/app.js`)
- Express app → MongoDB: connects to (evidence: `Backend/src/app.js`)
- Account routes → User records: reads and writes (evidence: `Backend/src/routes/auth.js`)
- Account routes → JWT access: protects account actions (evidence: `Backend/src/routes/auth.js`)
- Category routes → JWT access: protects routes (evidence: `Backend/src/routes/categories.js`)
- Category routes → Category records: reads and writes (evidence: `Backend/src/routes/categories.js`)
- Transaction routes → JWT access: protects routes (evidence: `Backend/src/routes/transactions.js`)
- Transaction routes → Transaction records: reads and writes (evidence: `Backend/src/routes/transactions.js`)
- Transaction routes → Category records: checks categories (evidence: `Backend/src/routes/transactions.js`)
- Budget routes → JWT access: protects routes (evidence: `Backend/src/routes/budgets.js`)
- Budget routes → Budget records: reads and writes (evidence: `Backend/src/routes/budgets.js`)
- Budget routes → Transaction records: aggregates spending (evidence: `Backend/src/routes/budgets.js`)
- Budget routes → Category records: validates categories (evidence: `Backend/src/routes/budgets.js`)
- Statistics routes → JWT access: protects routes (evidence: `Backend/src/routes/statistics.js`)
- Statistics routes → Transaction records: aggregates transactions (evidence: `Backend/src/routes/statistics.js`)
- Statistics routes → Category records: looks up categories (evidence: `Backend/src/routes/statistics.js`)
- Admin routes → JWT access: requires admin (evidence: `Backend/src/routes/admin.js`)
- Admin routes → User records: manages users (evidence: `Backend/src/routes/admin.js`)
- Admin routes → Transaction records: aggregates activity (evidence: `Backend/src/routes/admin.js`)
- Admin routes → Budget records: deletes user budgets (evidence: `Backend/src/routes/admin.js`)
- Admin routes → Category records: deletes user categories (evidence: `Backend/src/routes/admin.js`)
- JWT access → User records: loads user (evidence: `Backend/src/middleware/auth.js`)
