# santoshrobot7/so-approvals-public architecture

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

- Interactive diagram: https://gitdiagram.com/santoshrobot7/so-approvals-public
- Repository: https://github.com/santoshrobot7/so-approvals-public

## Overview

SO Approvals digitizes CG Motors’ sales-order-for-billing workflow: sales staff prepare forms and supporting files, submit them for rule-selected or manually picked approvals, and after final approval record SAP order details and download a combined PDF for attachment in SAP. The browser app calls the Worker API; shared logic defines form validation, totals, roles, and chains, while D1 persists workflow state and documents. The README documents user/rule administration, brand-scoped access, signatures, and PDF assembly. Unsampled routes and storage internals are represented only at documented subsystem level.

Main entry points: [`src/worker.js`](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js) (API routing), [`public/app.js`](https://github.com/santoshrobot7/so-approvals-public/blob/main/public/app.js) (Forms and admin UI), [`public/shared.js`](https://github.com/santoshrobot7/so-approvals-public/blob/main/public/shared.js) (Form and chain rules), [`public/pdf.js`](https://github.com/santoshrobot7/so-approvals-public/blob/main/public/pdf.js) (PDF builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Browser experience"]
  node_browser["Forms and admin UI<br/>[app.js]"]
  node_pdf["PDF builder<br/>[pdf.js]"]
end

subgraph group_workflow["Approval workflow"]
  node_shared["Form and chain rules<br/>[shared.js]"]
  node_formflow["Form lifecycle<br/>[worker.js]"]
  node_approvals["Approval decisions<br/>[worker.js]"]
  node_admin["Users and rules<br/>[worker.js]"]
  node_attachments["Supporting documents<br/>[worker.js]"]
  node_sapstage["SAP handoff<br/>[worker.js]"]
end

subgraph group_platform["API and identity"]
  node_api["API routing<br/>[worker.js]"]
  node_identity["Sessions and access<br/>[worker.js]"]
end

subgraph group_records["Workflow records"]
  node_d1[("D1 records")]
  node_schema["Workflow schema"]
end

node_sales(("Sales staff"))
node_approver(("Approvers and admins"))
node_sap(("SAP order process"))

node_sales -->|"fills forms"| node_browser
node_approver -->|"reviews forms"| node_browser
node_browser -->|"calls API"| node_api
node_browser -->|"uses rules"| node_shared
node_browser -->|"builds download"| node_pdf
node_pdf -->|"uses form definitions"| node_shared
node_api -->|"checks sessions"| node_identity
node_api -->|"routes form actions"| node_formflow
node_api -->|"routes decisions"| node_approvals
node_api -->|"routes admin actions"| node_admin
node_api -->|"routes file actions"| node_attachments
node_api -->|"routes SAP actions"| node_sapstage
node_formflow -->|"validates and selects chain"| node_shared
node_approvals -->|"checks role access"| node_shared
node_formflow -.->|"reads and writes"| node_d1
node_approvals -.->|"records decisions"| node_d1
node_identity -->|"reads sessions and users"| node_d1
node_admin -.->|"manages users and rules"| node_d1
node_attachments -.->|"stores file pieces"| node_d1
node_sapstage -.->|"records order handoff"| node_d1
node_schema -->|"defines schema"| node_d1
node_browser -.->|"uploads and fetches files"| node_attachments
node_browser -.->|"records SO details"| node_sapstage
node_pdf -->|"loads attached files"| node_attachments
node_sales -->|"attaches final PDF"| node_sap

click node_browser "https://github.com/santoshrobot7/so-approvals-public/blob/main/public/app.js"
click node_pdf "https://github.com/santoshrobot7/so-approvals-public/blob/main/public/pdf.js"
click node_shared "https://github.com/santoshrobot7/so-approvals-public/blob/main/public/shared.js"
click node_api "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_identity "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_formflow "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_approvals "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_admin "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_attachments "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_sapstage "https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js"
click node_schema "https://github.com/santoshrobot7/so-approvals-public/tree/main/migrations"

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,node_pdf toneBlue
class node_shared,node_formflow,node_approvals,node_admin,node_attachments,node_sapstage toneAmber
class node_api,node_identity toneMint
class node_d1,node_schema toneRose
class node_sales,node_approver,node_sap toneIndigo
```

## Components

### Browser experience

- [Forms and admin UI](https://github.com/santoshrobot7/so-approvals-public/blob/main/public/app.js): `public/app.js`
- [PDF builder](https://github.com/santoshrobot7/so-approvals-public/blob/main/public/pdf.js): `public/pdf.js`

### Approval workflow

- [Form and chain rules](https://github.com/santoshrobot7/so-approvals-public/blob/main/public/shared.js): `public/shared.js`
- [Form lifecycle](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`
- [Approval decisions](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`
- [Users and rules](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`
- [Supporting documents](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`
- [SAP handoff](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`

### API and identity

- [API routing](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`
- [Sessions and access](https://github.com/santoshrobot7/so-approvals-public/blob/main/src/worker.js): `src/worker.js`

### Workflow records

- **D1 records**
- [Workflow schema](https://github.com/santoshrobot7/so-approvals-public/tree/main/migrations): `migrations`

### Other components

- **Sales staff**
- **Approvers and admins**
- **SAP order process**

## Connections

- Sales staff → Forms and admin UI: fills forms (evidence: `README.md`)
- Approvers and admins → Forms and admin UI: reviews forms (evidence: `README.md`)
- Forms and admin UI → API routing: calls API (evidence: `public/app.js`)
- Forms and admin UI → Form and chain rules: uses rules (evidence: `public/app.js`)
- Forms and admin UI → PDF builder: builds download (evidence: `public/app.js`)
- PDF builder → Form and chain rules: uses form definitions (evidence: `public/pdf.js`)
- API routing → Sessions and access: checks sessions (evidence: `src/worker.js`)
- API routing → Form lifecycle: routes form actions (evidence: `src/worker.js`)
- API routing → Approval decisions: routes decisions (evidence: `src/worker.js`)
- API routing → Users and rules: routes admin actions (evidence: `src/worker.js`)
- API routing → Supporting documents: routes file actions (evidence: `src/worker.js`)
- API routing → SAP handoff: routes SAP actions (evidence: `src/worker.js`)
- Form lifecycle → Form and chain rules: validates and selects chain (evidence: `src/worker.js`)
- Approval decisions → Form and chain rules: checks role access (evidence: `src/worker.js`)
- Form lifecycle → D1 records: reads and writes
- Approval decisions → D1 records: records decisions
- Sessions and access → D1 records: reads sessions and users (evidence: `src/worker.js`)
- Users and rules → D1 records: manages users and rules
- Supporting documents → D1 records: stores file pieces
- SAP handoff → D1 records: records order handoff
- Workflow schema → D1 records: defines schema (evidence: `README.md`)
- Forms and admin UI → Supporting documents: uploads and fetches files
- Forms and admin UI → SAP handoff: records SO details
- PDF builder → Supporting documents: loads attached files
- Sales staff → SAP order process: attaches final PDF (evidence: `README.md`)
