# jayangupta/shopledger architecture

> Architecture diagram of the GitHub repository jayangupta/shopledger, 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/jayangupta/shopledger
- Repository: https://github.com/jayangupta/shopledger

## Overview

ShopLedger is a small-shop POS and bookkeeping application. Staff use its web interface and API to browse products, preview prices and coupons, place or cancel orders, manage customer credit, and review reports; order creation checks stock and credit, records the order, and persists changes. The server also serves printable tax invoices. The sampled sources support the main server, route, and domain-service relationships; the README is empty, and the frontend implementation and several route modules were not excerpted, so their internal behavior is not inferred.

Main entry points: [`server.js`](https://github.com/jayangupta/shopledger/blob/main/server.js) (Express Server), [`routes/orders.js`](https://github.com/jayangupta/shopledger/blob/main/routes/orders.js) (Order Routes), [`lib/store.js`](https://github.com/jayangupta/shopledger/blob/main/lib/store.js) (JSON Store), [`routes/products.js`](https://github.com/jayangupta/shopledger/blob/main/routes/products.js) (Product Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Web Interface"]
  node_web["POS Interface<br/>[app.js]"]
end

subgraph group_api["HTTP API"]
  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 Operations"]
  node_inventory["Inventory<br/>[inventory.js]"]
  node_pricing["Pricing<br/>[pricing.js]"]
  node_coupons["Coupons<br/>[coupons.js]"]
  node_tax["Tax Rules<br/>[tax.js]"]
  node_orders["Order Lifecycle<br/>[orders.js]"]
  node_invoice["Tax Invoice<br/>[invoice.js]"]
end

subgraph group_accounts["Accounts and Reporting"]
  node_ledger["Customer Ledger<br/>[ledger.js]"]
  node_dates["Date Utilities<br/>[dates.js]"]
  node_reports["Reports and Reconciliation<br/>[reports.js]"]
end

subgraph group_persistence["Persistence and Configuration"]
  node_store["JSON Store<br/>[store.js]"]
  node_database[("Shop Data<br/>[db.json]")]
  node_config["Shop Configuration<br/>[config.js]"]
end

node_staff(("Shop Staff"))

node_staff -.->|"uses"| node_web
node_server -->|"serves static files"| node_web
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 orders"| node_store
node_server -->|"looks up order"| node_orders
node_server -->|"renders invoice"| node_invoice
node_server -->|"configures port"| node_config
node_product_routes -->|"reads products"| node_store
node_product_routes -->|"calculates stock"| node_inventory
node_product_routes -->|"gets tax 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 code"| node_coupons
node_order_routes -->|"adds or cancels"| node_orders
node_order_routes -->|"checks credit"| node_ledger
node_customer_routes -->|"reads and writes"| node_store
node_customer_routes -->|"manages balances"| 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 -->|"checks preview code"| node_coupons
node_store -->|"reads and writes"| node_database
node_orders -->|"normalizes dates"| node_dates
node_orders -->|"releases stock"| node_inventory
node_orders -->|"reverses credit"| node_ledger
node_ledger -->|"dates settlements"| node_dates
node_reports -->|"summarizes stock"| node_inventory
node_reports -->|"totals receivables"| node_ledger
node_reports -->|"compares figures"| node_invoice
node_pricing -->|"resolves tax"| node_tax
node_pricing -->|"calculates discounts"| node_coupons
node_coupons -->|"reads coupon rules"| node_config
node_inventory -->|"reads inventory defaults"| node_config
node_tax -->|"reads tax slabs"| node_config
node_invoice -->|"reads shop and tax settings"| node_config

click node_web "https://github.com/jayangupta/shopledger/blob/main/public/js/app.js"
click node_server "https://github.com/jayangupta/shopledger/blob/main/server.js"
click node_product_routes "https://github.com/jayangupta/shopledger/blob/main/routes/products.js"
click node_order_routes "https://github.com/jayangupta/shopledger/blob/main/routes/orders.js"
click node_customer_routes "https://github.com/jayangupta/shopledger/blob/main/routes/customers.js"
click node_report_routes "https://github.com/jayangupta/shopledger/blob/main/routes/reports.js"
click node_inventory "https://github.com/jayangupta/shopledger/blob/main/lib/inventory.js"
click node_pricing "https://github.com/jayangupta/shopledger/blob/main/lib/pricing.js"
click node_coupons "https://github.com/jayangupta/shopledger/blob/main/lib/coupons.js"
click node_tax "https://github.com/jayangupta/shopledger/blob/main/lib/tax.js"
click node_orders "https://github.com/jayangupta/shopledger/blob/main/lib/orders.js"
click node_invoice "https://github.com/jayangupta/shopledger/blob/main/lib/invoice.js"
click node_ledger "https://github.com/jayangupta/shopledger/blob/main/lib/ledger.js"
click node_dates "https://github.com/jayangupta/shopledger/blob/main/lib/dates.js"
click node_reports "https://github.com/jayangupta/shopledger/blob/main/lib/reports.js"
click node_store "https://github.com/jayangupta/shopledger/blob/main/lib/store.js"
click node_database "https://github.com/jayangupta/shopledger/blob/main/data/db.json"
click node_config "https://github.com/jayangupta/shopledger/blob/main/config.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_web 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,node_invoice toneMint
class node_ledger,node_dates,node_reports toneRose
class node_store,node_database,node_config,node_staff toneIndigo
```

## Components

### Web Interface

- [POS Interface](https://github.com/jayangupta/shopledger/blob/main/public/js/app.js): `public/js/app.js`

### HTTP API

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

### Sales Operations

- [Inventory](https://github.com/jayangupta/shopledger/blob/main/lib/inventory.js): `lib/inventory.js`
- [Pricing](https://github.com/jayangupta/shopledger/blob/main/lib/pricing.js): `lib/pricing.js`
- [Coupons](https://github.com/jayangupta/shopledger/blob/main/lib/coupons.js): `lib/coupons.js`
- [Tax Rules](https://github.com/jayangupta/shopledger/blob/main/lib/tax.js): `lib/tax.js`
- [Order Lifecycle](https://github.com/jayangupta/shopledger/blob/main/lib/orders.js): `lib/orders.js`
- [Tax Invoice](https://github.com/jayangupta/shopledger/blob/main/lib/invoice.js): `lib/invoice.js`

### Accounts and Reporting

- [Customer Ledger](https://github.com/jayangupta/shopledger/blob/main/lib/ledger.js): `lib/ledger.js`
- [Date Utilities](https://github.com/jayangupta/shopledger/blob/main/lib/dates.js): `lib/dates.js`
- [Reports and Reconciliation](https://github.com/jayangupta/shopledger/blob/main/lib/reports.js): `lib/reports.js`

### Persistence and Configuration

- [JSON Store](https://github.com/jayangupta/shopledger/blob/main/lib/store.js): `lib/store.js`
- [Shop Data](https://github.com/jayangupta/shopledger/blob/main/data/db.json): `data/db.json`
- [Shop Configuration](https://github.com/jayangupta/shopledger/blob/main/config.js): `config.js`

### Other components

- **Shop Staff**

## Connections

- Shop Staff → POS Interface: uses
- Express Server → POS Interface: serves static files (evidence: `server.js`)
- 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 orders (evidence: `server.js`)
- Express Server → Order Lifecycle: looks up order (evidence: `server.js`)
- Express Server → Tax Invoice: renders invoice (evidence: `server.js`)
- Express Server → Shop Configuration: configures port (evidence: `server.js`)
- Product Routes → JSON Store: reads products (evidence: `routes/products.js`)
- Product Routes → Inventory: calculates stock (evidence: `routes/products.js`)
- Product Routes → Tax Rules: gets tax slab (evidence: `routes/products.js`)
- Product Routes → Coupons: 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: computes totals (evidence: `routes/orders.js`)
- Order Routes → Coupons: validates code (evidence: `routes/orders.js`)
- Order Routes → Order Lifecycle: adds or cancels (evidence: `routes/orders.js`)
- Order Routes → Customer Ledger: checks credit (evidence: `routes/orders.js`)
- Customer Routes → JSON Store: reads and writes (evidence: `routes/customers.js`)
- Customer Routes → Customer Ledger: manages balances (evidence: `routes/customers.js`)
- Report Routes → JSON Store: reads data (evidence: `routes/reports.js`)
- Report Routes → Reports and Reconciliation: builds reports (evidence: `routes/reports.js`)
- Report Routes → Pricing: previews totals (evidence: `routes/reports.js`)
- Report Routes → Coupons: checks preview code (evidence: `routes/reports.js`)
- JSON Store → Shop Data: reads and writes (evidence: `lib/store.js`)
- Order Lifecycle → Date Utilities: normalizes dates (evidence: `lib/orders.js`)
- Order Lifecycle → Inventory: releases stock (evidence: `lib/orders.js`)
- Order Lifecycle → Customer Ledger: reverses credit (evidence: `lib/orders.js`)
- Customer Ledger → Date Utilities: dates settlements (evidence: `lib/ledger.js`)
- Reports and Reconciliation → Inventory: summarizes stock (evidence: `lib/reports.js`)
- Reports and Reconciliation → Customer Ledger: totals receivables (evidence: `lib/reports.js`)
- Reports and Reconciliation → Tax Invoice: compares figures (evidence: `lib/reports.js`)
- Pricing → Tax Rules: resolves tax (evidence: `lib/pricing.js`)
- Pricing → Coupons: calculates discounts (evidence: `lib/pricing.js`)
- Coupons → Shop Configuration: reads coupon rules (evidence: `lib/coupons.js`)
- Inventory → Shop Configuration: reads inventory defaults (evidence: `lib/inventory.js`)
- Tax Rules → Shop Configuration: reads tax slabs (evidence: `lib/tax.js`)
- Tax Invoice → Shop Configuration: reads shop and tax settings (evidence: `lib/invoice.js`)
