# harip-git/spendgate_hari architecture

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

- Interactive diagram: https://gitdiagram.com/harip-git/spendgate_hari
- Repository: https://github.com/harip-git/spendgate_hari

## Overview

SpendGate is a Frappe app for managing employee expense claims against departmental budgets. Staff enter claims and expense lines; the claim controller validates them against budget limits, while authorized department heads and finance managers can approve, reject, or reassign claims. The app also exposes claim and budget APIs, sends submission notifications and optional webhooks, records audit events, and checks budget thresholds daily. The README gives only a brief product description; report and voucher capabilities are represented from the repository tree, whose implementation was not sampled.

Main entry points: [`spendgate/spendgate/doctype/expense_claim/expense_claim.py`](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.py) (Claim controller), [`spendgate/spendgate/doctype/expense_claim/expense_claim.js`](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.js) (Claim form), [`spendgate/tasks.py`](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/tasks.py) (Daily threshold check), [`spendgate/api.py`](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/api.py) (Webhook delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_claim["Claims and approvals"]
  node_claim_ui["Claim form<br/>[expense_claim.js]"]
  node_claim_ctrl["Claim controller<br/>[expense_claim.py]"]
  node_expense_lines["Expense lines<br/>[expense_line.py]"]
  node_approvals["Approval actions<br/>[expense_claim.py]"]
  node_voucher["Claim voucher"]
  node_pending_report["Pending approvals"]
end

subgraph group_budget["Budgets and setup"]
  node_budget["Budget rules<br/>[budget.py]"]
  node_department["Departments"]
  node_category["Expense categories"]
  node_settings["App settings"]
end

subgraph group_access["Access and APIs"]
  node_api["Expense APIs<br/>[api.py]"]
  node_permissions["Claim permissions<br/>[permission.py]"]
end

subgraph group_ops["Alerts and audit"]
  node_audit["Audit logging<br/>[audit.py]"]
  node_scheduler["Daily threshold check<br/>[tasks.py]"]
  node_notifications["Claim notifications<br/>[notifications.py]"]
  node_webhook["Webhook delivery<br/>[api.py]"]
end

node_user(("SpendGate user"))
node_frappe_db[("Frappe document store")]
node_mail["Email service"]
node_external_hook["Configured webhook"]

node_user -->|"enters claim"| node_claim_ui
node_claim_ui -->|"calls claim methods"| node_claim_ctrl
node_claim_ui -->|"calls decisions"| node_approvals
node_claim_ui -->|"requests remaining budget"| node_claim_ctrl
node_claim_ctrl -->|"reads and writes"| node_frappe_db
node_claim_ctrl -->|"loads linked budget"| node_budget
node_claim_ctrl -->|"queues notice"| node_notifications
node_claim_ctrl -->|"queues webhook"| node_webhook
node_approvals -->|"updates claim status"| node_frappe_db
node_user -->|"requests API"| node_api
node_api -->|"reads and shares"| node_frappe_db
node_user -->|"claim list access"| node_permissions
node_permissions -->|"filters claims"| node_frappe_db
node_scheduler -->|"reads budgets and logs"| node_frappe_db
node_scheduler -->|"reads alert threshold"| node_settings
node_scheduler -->|"sends budget alert"| node_mail
node_scheduler -->|"writes alert and audit logs"| node_frappe_db
node_webhook -->|"reads webhook URL"| node_settings
node_webhook -->|"loads submitted claim"| node_frappe_db
node_webhook -->|"posts claim event"| node_external_hook
node_audit -.->|"records changes"| node_frappe_db
node_frappe_db -.->|"stores line records"| node_expense_lines
node_notifications -.->|"sends claim notice"| node_mail
node_claim_ui -.->|"edits claim lines"| node_expense_lines

click node_claim_ui "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.js"
click node_claim_ctrl "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.py"
click node_expense_lines "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_line/expense_line.py"
click node_approvals "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.py"
click node_voucher "https://github.com/harip-git/spendgate_hari/tree/main/spendgate/spendgate/print_format/expense_claim_voucher"
click node_pending_report "https://github.com/harip-git/spendgate_hari/tree/main/spendgate/spendgate/report/pending_approvals"
click node_budget "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/budget/budget.py"
click node_department "https://github.com/harip-git/spendgate_hari/tree/main/spendgate/spendgate/doctype/department"
click node_category "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_category/expense_category.py"
click node_settings "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/spendgate_settings/spendgate_settings.py"
click node_api "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/api.py"
click node_permissions "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/permission.py"
click node_audit "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/audit.py"
click node_scheduler "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/tasks.py"
click node_notifications "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/notifications.py"
click node_webhook "https://github.com/harip-git/spendgate_hari/blob/main/spendgate/api.py"

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_claim_ui,node_claim_ctrl,node_expense_lines,node_approvals,node_voucher,node_pending_report,node_user toneBlue
class node_budget,node_department,node_category,node_settings,node_frappe_db toneAmber
class node_api,node_permissions,node_external_hook toneMint
class node_audit,node_scheduler,node_notifications,node_webhook toneRose
class node_mail toneIndigo
```

## Components

### Claims and approvals

- [Claim form](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.js): `spendgate/spendgate/doctype/expense_claim/expense_claim.js`
- [Claim controller](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.py): `spendgate/spendgate/doctype/expense_claim/expense_claim.py`
- [Expense lines](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_line/expense_line.py): `spendgate/spendgate/doctype/expense_line/expense_line.py`
- [Approval actions](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_claim/expense_claim.py): `spendgate/spendgate/doctype/expense_claim/expense_claim.py`
- [Claim voucher](https://github.com/harip-git/spendgate_hari/tree/main/spendgate/spendgate/print_format/expense_claim_voucher): `spendgate/spendgate/print_format/expense_claim_voucher`
- [Pending approvals](https://github.com/harip-git/spendgate_hari/tree/main/spendgate/spendgate/report/pending_approvals): `spendgate/spendgate/report/pending_approvals`

### Budgets and setup

- [Budget rules](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/budget/budget.py): `spendgate/spendgate/doctype/budget/budget.py`
- [Departments](https://github.com/harip-git/spendgate_hari/tree/main/spendgate/spendgate/doctype/department): `spendgate/spendgate/doctype/department`
- [Expense categories](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/expense_category/expense_category.py): `spendgate/spendgate/doctype/expense_category/expense_category.py`
- [App settings](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/spendgate/doctype/spendgate_settings/spendgate_settings.py): `spendgate/spendgate/doctype/spendgate_settings/spendgate_settings.py`

### Access and APIs

- [Expense APIs](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/api.py): `spendgate/api.py`
- [Claim permissions](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/permission.py): `spendgate/permission.py`

### Alerts and audit

- [Audit logging](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/audit.py): `spendgate/audit.py`
- [Daily threshold check](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/tasks.py): `spendgate/tasks.py`
- [Claim notifications](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/notifications.py): `spendgate/notifications.py`
- [Webhook delivery](https://github.com/harip-git/spendgate_hari/blob/main/spendgate/api.py): `spendgate/api.py`

### Other components

- **SpendGate user**
- **Frappe document store**
- **Email service**
- **Configured webhook**

## Connections

- SpendGate user → Claim form: enters claim (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.js`)
- Claim form → Claim controller: calls claim methods (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.js`)
- Claim form → Approval actions: calls decisions (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.js`)
- Claim form → Claim controller: requests remaining budget (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.js`)
- Claim controller → Frappe document store: reads and writes (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.py`)
- Claim controller → Budget rules: loads linked budget (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.py`)
- Claim controller → Claim notifications: queues notice (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.py`)
- Claim controller → Webhook delivery: queues webhook (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.py`)
- Approval actions → Frappe document store: updates claim status (evidence: `spendgate/spendgate/doctype/expense_claim/expense_claim.py`)
- SpendGate user → Expense APIs: requests API (evidence: `spendgate/api.py`)
- Expense APIs → Frappe document store: reads and shares (evidence: `spendgate/api.py`)
- SpendGate user → Claim permissions: claim list access
- Claim permissions → Frappe document store: filters claims (evidence: `spendgate/permission.py`)
- Daily threshold check → Frappe document store: reads budgets and logs (evidence: `spendgate/tasks.py`)
- Daily threshold check → App settings: reads alert threshold (evidence: `spendgate/tasks.py`)
- Daily threshold check → Email service: sends budget alert (evidence: `spendgate/tasks.py`)
- Daily threshold check → Frappe document store: writes alert and audit logs (evidence: `spendgate/tasks.py`)
- Webhook delivery → App settings: reads webhook URL (evidence: `spendgate/api.py`)
- Webhook delivery → Frappe document store: loads submitted claim (evidence: `spendgate/api.py`)
- Webhook delivery → Configured webhook: posts claim event (evidence: `spendgate/api.py`)
- Audit logging → Frappe document store: records changes
- Frappe document store → Expense lines: stores line records
- Claim notifications → Email service: sends claim notice
- Claim form → Expense lines: edits claim lines
