# sampurnr/shopledger-legacy-workshop architecture

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

- Interactive diagram: https://gitdiagram.com/sampurnr/shopledger-legacy-workshop
- Repository: https://github.com/sampurnr/shopledger-legacy-workshop

## Overview

ShopLedger is a small-shop POS and bookkeeping application. A shop operator uses the browser UI to manage products and customers, preview pricing, and place or cancel orders; API routes coordinate inventory, pricing, coupon, and Khata accounting operations and persist changes. The application also exposes dashboard and GST-reconciliation reports and a printable invoice. Source excerpts show the server and core order/report flows; the browser-to-API wiring and some route implementations are not shown, so those links are marked unverified or omitted.

Main entry points: [`server.js`](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/server.js) (Express server), [`routes/orders.js`](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/orders.js) (Order routes), [`lib/store.js`](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/store.js) (JSON store), [`routes/products.js`](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/products.js) (Product routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Shop interface"]
  node_ui["POS browser UI<br/>[app.js]"]
  node_webpage["Shop page<br/>[index.html]"]
end

subgraph group_api["HTTP application"]
  node_server["Express server<br/>[server.js]"]
  node_product_routes["Product routes<br/>[products.js]"]
  node_order_routes["Order routes<br/>[orders.js]"]
  node_customer_routes["Customer routes<br/>[customers.js]"]
  node_report_routes["Report routes<br/>[reports.js]"]
end

subgraph group_commerce["Sales and inventory"]
  node_inventory["Inventory<br/>[inventory.js]"]
  node_pricing["Pricing and tax<br/>[pricing.js]"]
  node_coupons["Coupon rules<br/>[coupons.js]"]
  node_tax["GST slabs<br/>[tax.js]"]
  node_orders["Order lifecycle<br/>[orders.js]"]
end

subgraph group_accounts["Customer accounts"]
  node_ledger["Khata ledger<br/>[ledger.js]"]
  node_dates["Date utilities<br/>[dates.js]"]
end

subgraph group_insight["Reporting and invoices"]
  node_reports["Dashboard and GST<br/>[reports.js]"]
  node_invoice["Invoice rendering<br/>[invoice.js]"]
end

subgraph group_persistence["Configuration and storage"]
  node_config["Shop configuration<br/>[config.js]"]
  node_store["JSON store<br/>[store.js]"]
  node_db[("Shop data<br/>[db.json]")]
end

node_operator(("Shop operator"))

node_operator -.->|"uses"| node_ui
node_ui -.->|"displays"| node_webpage
node_ui -.->|"requests API"| node_server
node_server -->|"mounts routes"| node_product_routes
node_server -->|"mounts routes"| node_order_routes
node_server -->|"mounts routes"| node_customer_routes
node_server -->|"mounts routes"| node_report_routes
node_server -->|"reads order data"| node_store
node_server -->|"looks up orders"| node_orders
node_server -->|"renders invoice"| node_invoice
node_product_routes -->|"reads data"| node_store
node_product_routes -->|"calculates stock"| node_inventory
node_product_routes -->|"gets GST slab"| node_tax
node_product_routes -->|"lists coupons"| node_coupons
node_order_routes -->|"reads and writes"| node_store
node_order_routes -->|"checks and reserves"| node_inventory
node_order_routes -->|"computes totals"| node_pricing
node_order_routes -->|"validates codes"| node_coupons
node_order_routes -->|"creates orders"| node_orders
node_order_routes -->|"charges Khata"| node_ledger
node_customer_routes -->|"reads and writes"| node_store
node_customer_routes -->|"handles accounts"| node_ledger
node_report_routes -->|"reads data"| node_store
node_report_routes -->|"builds reports"| node_reports
node_report_routes -->|"previews totals"| node_pricing
node_report_routes -->|"validates preview"| node_coupons
node_reports -->|"summarizes stock"| node_inventory
node_reports -->|"lists customers"| node_ledger
node_reports -->|"reconciles totals"| node_invoice
node_orders -->|"normalizes dates"| node_dates
node_orders -->|"releases stock"| node_inventory
node_orders -->|"reverses debit"| node_ledger
node_ledger -->|"dates settlements"| node_dates
node_pricing -->|"uses GST rules"| node_tax
node_pricing -->|"calculates discount"| node_coupons
node_inventory -->|"reads inventory defaults"| node_config
node_tax -->|"reads GST slabs"| node_config
node_coupons -->|"reads coupon rules"| node_config
node_invoice -->|"reads shop and tax settings"| node_config
node_store -->|"reads and writes JSON"| node_db

click node_ui "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/public/js/app.js"
click node_webpage "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/public/index.html"
click node_server "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/server.js"
click node_product_routes "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/products.js"
click node_order_routes "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/orders.js"
click node_customer_routes "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/customers.js"
click node_report_routes "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/reports.js"
click node_inventory "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/inventory.js"
click node_pricing "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/pricing.js"
click node_coupons "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/coupons.js"
click node_tax "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/tax.js"
click node_orders "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/orders.js"
click node_ledger "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/ledger.js"
click node_dates "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/dates.js"
click node_reports "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/reports.js"
click node_invoice "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/invoice.js"
click node_config "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/config.js"
click node_store "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/store.js"
click node_db "https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/data/db.json"

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_ui,node_webpage toneBlue
class node_server,node_product_routes,node_order_routes,node_customer_routes,node_report_routes toneAmber
class node_inventory,node_pricing,node_coupons,node_tax,node_orders toneMint
class node_ledger,node_dates toneRose
class node_reports,node_invoice,node_operator toneIndigo
class node_config,node_store,node_db toneTeal
```

## Components

### Shop interface

- [POS browser UI](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/public/js/app.js): `public/js/app.js`
- [Shop page](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/public/index.html): `public/index.html`

### HTTP application

- [Express server](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/server.js): `server.js`
- [Product routes](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/products.js): `routes/products.js`
- [Order routes](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/orders.js): `routes/orders.js`
- [Customer routes](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/customers.js): `routes/customers.js`
- [Report routes](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/routes/reports.js): `routes/reports.js`

### Sales and inventory

- [Inventory](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/inventory.js): `lib/inventory.js`
- [Pricing and tax](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/pricing.js): `lib/pricing.js`
- [Coupon rules](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/coupons.js): `lib/coupons.js`
- [GST slabs](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/tax.js): `lib/tax.js`
- [Order lifecycle](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/orders.js): `lib/orders.js`

### Customer accounts

- [Khata ledger](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/ledger.js): `lib/ledger.js`
- [Date utilities](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/dates.js): `lib/dates.js`

### Reporting and invoices

- [Dashboard and GST](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/reports.js): `lib/reports.js`
- [Invoice rendering](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/invoice.js): `lib/invoice.js`

### Configuration and storage

- [Shop configuration](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/config.js): `config.js`
- [JSON store](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/lib/store.js): `lib/store.js`
- [Shop data](https://github.com/sampurnr/shopledger-legacy-workshop/blob/main/data/db.json): `data/db.json`

### Other components

- **Shop operator**

## Connections

- Shop operator → POS browser UI: uses
- POS browser UI → Shop page: displays
- POS browser UI → Express server: requests API
- Express server → Product routes: mounts routes (evidence: `server.js`)
- Express server → Order routes: mounts routes (evidence: `server.js`)
- Express server → Customer routes: mounts routes (evidence: `server.js`)
- Express server → Report routes: mounts routes (evidence: `server.js`)
- Express server → JSON store: reads order data (evidence: `server.js`)
- Express server → Order lifecycle: looks up orders (evidence: `server.js`)
- Express server → Invoice rendering: renders invoice (evidence: `server.js`)
- Product routes → JSON store: reads data (evidence: `routes/products.js`)
- Product routes → Inventory: calculates stock (evidence: `routes/products.js`)
- Product routes → GST slabs: gets GST slab (evidence: `routes/products.js`)
- Product routes → Coupon rules: lists coupons (evidence: `routes/products.js`)
- Order routes → JSON store: reads and writes (evidence: `routes/orders.js`)
- Order routes → Inventory: checks and reserves (evidence: `routes/orders.js`)
- Order routes → Pricing and tax: computes totals (evidence: `routes/orders.js`)
- Order routes → Coupon rules: validates codes (evidence: `routes/orders.js`)
- Order routes → Order lifecycle: creates orders (evidence: `routes/orders.js`)
- Order routes → Khata ledger: charges Khata (evidence: `routes/orders.js`)
- Customer routes → JSON store: reads and writes (evidence: `routes/customers.js`)
- Customer routes → Khata ledger: handles accounts (evidence: `routes/customers.js`)
- Report routes → JSON store: reads data (evidence: `routes/reports.js`)
- Report routes → Dashboard and GST: builds reports (evidence: `routes/reports.js`)
- Report routes → Pricing and tax: previews totals (evidence: `routes/reports.js`)
- Report routes → Coupon rules: validates preview (evidence: `routes/reports.js`)
- Dashboard and GST → Inventory: summarizes stock (evidence: `lib/reports.js`)
- Dashboard and GST → Khata ledger: lists customers (evidence: `lib/reports.js`)
- Dashboard and GST → Invoice rendering: reconciles totals (evidence: `lib/reports.js`)
- Order lifecycle → Date utilities: normalizes dates (evidence: `lib/orders.js`)
- Order lifecycle → Inventory: releases stock (evidence: `lib/orders.js`)
- Order lifecycle → Khata ledger: reverses debit (evidence: `lib/orders.js`)
- Khata ledger → Date utilities: dates settlements (evidence: `lib/ledger.js`)
- Pricing and tax → GST slabs: uses GST rules (evidence: `lib/pricing.js`)
- Pricing and tax → Coupon rules: calculates discount (evidence: `lib/pricing.js`)
- Inventory → Shop configuration: reads inventory defaults (evidence: `lib/inventory.js`)
- GST slabs → Shop configuration: reads GST slabs (evidence: `lib/tax.js`)
- Coupon rules → Shop configuration: reads coupon rules (evidence: `lib/coupons.js`)
- Invoice rendering → Shop configuration: reads shop and tax settings (evidence: `lib/invoice.js`)
- JSON store → Shop data: reads and writes JSON (evidence: `lib/store.js`)
