# smartbuddy1/backend_expense architecture

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

- Interactive diagram: https://gitdiagram.com/smartbuddy1/backend_expense
- Repository: https://github.com/smartbuddy1/backend_expense

## Overview

ASEMS is a backend API for managing site expenses and cash advances across projects, from submission or request through approval and payment or disbursement. The Express entry point dispatches requests to domain routes; authentication protects access, and Prisma provides persistence. The sampled expense and advance handlers show payment-ledger recording, while receipt uploads can use S3 or local storage. Other route modules are included as documented API branches, but their internal behavior is not inferred from their filenames.

Main entry points: [`src/index.js`](https://github.com/smartbuddy1/backend_expense/blob/main/src/index.js) (Express API), [`src/routes/expenses.js`](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/expenses.js) (Expenses), [`src/db.js`](https://github.com/smartbuddy1/backend_expense/blob/main/src/db.js) (Prisma client), [`src/routes/advances.js`](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/advances.js) (Advances)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_app["Express API<br/>[index.js]"]
  node_authroute["Login and identity<br/>[auth.js]"]
  node_authmw["Auth middleware<br/>[auth.js]"]
  node_users["Users<br/>[users.js]"]
  node_prisma["Prisma client<br/>[db.js]"]
end

subgraph group_projects["Project setup"]
  node_organizations["Organizations<br/>[organizations.js]"]
  node_projectsroute["Projects<br/>[projects.js]"]
  node_team["Team members<br/>[teamMembers.js]"]
end

subgraph group_spending["Expense and advance"]
  node_expenses["Expenses<br/>[expenses.js]"]
  node_advances["Advances<br/>[advances.js]"]
  node_heads["Operational heads"]
  node_publicforms["Public forms<br/>[publicForms.js]"]
end

subgraph group_finance["Finance and records"]
  node_settlements["Settlements<br/>[settlements.js]"]
  node_ledger["Payments ledger<br/>[paymentsLedger.js]"]
  node_sitelogs["Site logs<br/>[siteLogs.js]"]
  node_database[("Application database<br/>[schema.prisma]")]
  node_storage["Receipt storage<br/>[s3.js]"]
end

node_client(("API client"))
node_s3[("AWS S3")]
node_localuploads[("Local uploads")]

node_client -->|"sends requests"| node_app
node_app -->|"dispatches"| node_authroute
node_app -->|"dispatches"| node_users
node_app -->|"dispatches"| node_organizations
node_app -->|"dispatches"| node_projectsroute
node_app -->|"dispatches"| node_team
node_app -->|"dispatches"| node_expenses
node_app -->|"dispatches"| node_advances
node_app -->|"dispatches"| node_heads
node_app -->|"dispatches"| node_publicforms
node_app -->|"dispatches"| node_settlements
node_app -->|"dispatches"| node_ledger
node_app -->|"dispatches"| node_sitelogs
node_authroute -->|"queries users"| node_prisma
node_authmw -->|"checks users"| node_prisma
node_expenses -->|"protects routes"| node_authmw
node_advances -->|"protects routes"| node_authmw
node_expenses -->|"reads and writes"| node_prisma
node_advances -->|"reads and writes"| node_prisma
node_prisma -->|"persists data"| node_database
node_expenses -->|"uploads receipts"| node_storage
node_storage -.->|"stores objects"| node_s3
node_storage -->|"stores fallback files"| node_localuploads
node_expenses -->|"records payments"| node_ledger
node_advances -->|"records disbursals"| node_ledger

click node_app "https://github.com/smartbuddy1/backend_expense/blob/main/src/index.js"
click node_authroute "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/auth.js"
click node_authmw "https://github.com/smartbuddy1/backend_expense/blob/main/src/middleware/auth.js"
click node_users "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/users.js"
click node_organizations "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/organizations.js"
click node_projectsroute "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/projects.js"
click node_team "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/teamMembers.js"
click node_expenses "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/expenses.js"
click node_advances "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/advances.js"
click node_heads "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/operationalHeads.js"
click node_publicforms "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/publicForms.js"
click node_settlements "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/settlements.js"
click node_ledger "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/paymentsLedger.js"
click node_sitelogs "https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/siteLogs.js"
click node_prisma "https://github.com/smartbuddy1/backend_expense/blob/main/src/db.js"
click node_database "https://github.com/smartbuddy1/backend_expense/blob/main/prisma/schema.prisma"
click node_storage "https://github.com/smartbuddy1/backend_expense/blob/main/src/utils/s3.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_authroute,node_authmw,node_users,node_prisma,node_client toneBlue
class node_organizations,node_projectsroute,node_team,node_s3,node_localuploads toneAmber
class node_expenses,node_advances,node_heads,node_publicforms toneMint
class node_settlements,node_ledger,node_sitelogs,node_database,node_storage toneRose
```

## Components

### API and access

- [Express API](https://github.com/smartbuddy1/backend_expense/blob/main/src/index.js): `src/index.js`
- [Login and identity](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/auth.js): `src/routes/auth.js`
- [Auth middleware](https://github.com/smartbuddy1/backend_expense/blob/main/src/middleware/auth.js): `src/middleware/auth.js`
- [Users](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/users.js): `src/routes/users.js`
- [Prisma client](https://github.com/smartbuddy1/backend_expense/blob/main/src/db.js): `src/db.js`

### Project setup

- [Organizations](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/organizations.js): `src/routes/organizations.js`
- [Projects](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/projects.js): `src/routes/projects.js`
- [Team members](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/teamMembers.js): `src/routes/teamMembers.js`

### Expense and advance

- [Expenses](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/expenses.js): `src/routes/expenses.js`
- [Advances](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/advances.js): `src/routes/advances.js`
- [Operational heads](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/operationalHeads.js): `src/routes/operationalHeads.js`
- [Public forms](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/publicForms.js): `src/routes/publicForms.js`

### Finance and records

- [Settlements](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/settlements.js): `src/routes/settlements.js`
- [Payments ledger](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/paymentsLedger.js): `src/routes/paymentsLedger.js`
- [Site logs](https://github.com/smartbuddy1/backend_expense/blob/main/src/routes/siteLogs.js): `src/routes/siteLogs.js`
- [Application database](https://github.com/smartbuddy1/backend_expense/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Receipt storage](https://github.com/smartbuddy1/backend_expense/blob/main/src/utils/s3.js): `src/utils/s3.js`

### Other components

- **API client**
- **AWS S3**
- **Local uploads**

## Connections

- API client → Express API: sends requests
- Express API → Login and identity: dispatches
- Express API → Users: dispatches
- Express API → Organizations: dispatches
- Express API → Projects: dispatches
- Express API → Team members: dispatches
- Express API → Expenses: dispatches
- Express API → Advances: dispatches
- Express API → Operational heads: dispatches
- Express API → Public forms: dispatches
- Express API → Settlements: dispatches
- Express API → Payments ledger: dispatches
- Express API → Site logs: dispatches
- Login and identity → Prisma client: queries users
- Auth middleware → Prisma client: checks users
- Expenses → Auth middleware: protects routes
- Advances → Auth middleware: protects routes
- Expenses → Prisma client: reads and writes
- Advances → Prisma client: reads and writes
- Prisma client → Application database: persists data
- Expenses → Receipt storage: uploads receipts
- Receipt storage → AWS S3: stores objects
- Receipt storage → Local uploads: stores fallback files
- Expenses → Payments ledger: records payments
- Advances → Payments ledger: records disbursals
