# richard2606-hub/bukusaksi architecture

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

- Interactive diagram: https://gitdiagram.com/richard2606-hub/bukusaksi
- Repository: https://github.com/richard2606-hub/bukusaksi

## Overview

Buku Saksi is a Malaysian shop credit-book app: sellers record debts or bills, customers confirm through a one-time link, and either side can verify the customer’s hash-chained history. Other documented capabilities include importing old ledger photos, reminders, shop/account management, and sales measurement. The map follows documented workflows and sampled calls; some page-to-API wiring and unsampled subsystems are represented only where the README supports them.

Main entry points: [`lib/store.ts`](https://github.com/richard2606-hub/bukusaksi/blob/main/lib/store.ts) (Record store), [`app/api/entries/route.ts`](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/entries/route.ts) (Entry actions), [`app/account/page.tsx`](https://github.com/richard2606-hub/bukusaksi/blob/main/app/account/page.tsx) (Shop account), [`app/c/[token]/page.tsx`](https://github.com/richard2606-hub/bukusaksi/blob/main/app/c/%5Btoken%5D/page.tsx) (Shared record)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_seller["Seller workflows"]
  node_snap["Snap bill<br/>[page.tsx]"]
  node_import["Ledger import<br/>[page.tsx]"]
  node_debt["Debt entry<br/>[page.tsx]"]
  node_reminders["Reminders<br/>[page.tsx]"]
  node_measure["Shop measure<br/>[page.tsx]"]
  node_customers["Customer list<br/>[page.tsx]"]
end

subgraph group_customer["Customer records"]
  node_customerpage["Shared record<br/>[page.tsx]"]
end

subgraph group_core["Business services"]
  node_ocr["Photo reading<br/>[route.ts]"]
  node_parser["Line parsing<br/>[route.ts]"]
  node_entries["Entry actions<br/>[route.ts]"]
  node_confirmation["Confirmation<br/>[route.ts]"]
  node_reminderapi["Reminder drafting<br/>[route.ts]"]
  node_ukurapi["Ukur analysis<br/>[route.ts]"]
  node_store[("Record store<br/>[store.ts]")]
  node_chain["Hash chain<br/>[chain.ts]"]
  node_totals["Money totals<br/>[totals.ts]"]
  node_ilmu["ILMU client<br/>[ilmu.ts]"]
end

subgraph group_identity["Shop and identity"]
  node_account["Shop account<br/>[page.tsx]"]
  node_shopapi["Shop management<br/>[route.ts]"]
  node_auth["Owner access<br/>[auth.ts]"]
end

node_seller(("Seller"))
node_customer(("Customer"))

node_seller -->|"records photo"| node_snap
node_seller -->|"imports ledger"| node_import
node_seller -->|"records debt"| node_debt
node_snap -.->|"requests reading"| node_ocr
node_import -.->|"requests reading"| node_ocr
node_debt -.->|"requests parsing"| node_parser
node_debt -.->|"submits record"| node_entries
node_ocr -->|"reads photo"| node_ilmu
node_parser -->|"parses line"| node_ilmu
node_entries -->|"writes records"| node_store
node_entries -->|"computes total"| node_totals
node_entries -->|"computes balance"| node_chain
node_entries -->|"issues confirm link"| node_customerpage
node_customer -->|"opens link"| node_customerpage
node_customerpage -->|"confirms or disputes"| node_confirmation
node_confirmation -->|"reads and appends"| node_store
node_confirmation -->|"seals result"| node_chain
node_customerpage -->|"verifies history"| node_chain
node_seller -->|"drafts reminder"| node_reminders
node_reminders -.->|"requests draft"| node_reminderapi
node_reminderapi -->|"reads records"| node_store
node_reminderapi -->|"drafts message"| node_ilmu
node_seller -->|"views shop measure"| node_measure
node_measure -.->|"requests analysis"| node_ukurapi
node_ukurapi -->|"reads shop data"| node_store
node_ukurapi -->|"requests analysis"| node_ilmu
node_seller -->|"manages customers"| node_customers
node_customers -.->|"views records"| node_entries
node_seller -->|"manages shop"| node_account
node_account -->|"loads shop context"| node_auth
node_account -->|"checks shop records"| node_store
node_account -.->|"manages shop"| node_shopapi
node_shopapi -->|"checks owner access"| node_auth
node_shopapi -->|"updates shop"| node_store
node_auth -->|"loads memberships"| node_store

click node_snap "https://github.com/richard2606-hub/bukusaksi/blob/main/app/snap-bill/page.tsx"
click node_import "https://github.com/richard2606-hub/bukusaksi/blob/main/app/import/page.tsx"
click node_debt "https://github.com/richard2606-hub/bukusaksi/blob/main/app/add-debt/page.tsx"
click node_reminders "https://github.com/richard2606-hub/bukusaksi/blob/main/app/reminders/page.tsx"
click node_measure "https://github.com/richard2606-hub/bukusaksi/blob/main/app/ukur/page.tsx"
click node_customers "https://github.com/richard2606-hub/bukusaksi/blob/main/app/customers/page.tsx"
click node_ocr "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/ocr/route.ts"
click node_parser "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/parse/route.ts"
click node_entries "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/entries/route.ts"
click node_confirmation "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/confirm/route.ts"
click node_reminderapi "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/reminder/route.ts"
click node_ukurapi "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/ukur/route.ts"
click node_store "https://github.com/richard2606-hub/bukusaksi/blob/main/lib/store.ts"
click node_chain "https://github.com/richard2606-hub/bukusaksi/blob/main/lib/chain.ts"
click node_totals "https://github.com/richard2606-hub/bukusaksi/blob/main/lib/totals.ts"
click node_ilmu "https://github.com/richard2606-hub/bukusaksi/blob/main/lib/ilmu.ts"
click node_customerpage "https://github.com/richard2606-hub/bukusaksi/blob/main/app/c/%5Btoken%5D/page.tsx"
click node_account "https://github.com/richard2606-hub/bukusaksi/blob/main/app/account/page.tsx"
click node_shopapi "https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/shop/route.ts"
click node_auth "https://github.com/richard2606-hub/bukusaksi/blob/main/lib/auth.ts"

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_snap,node_import,node_debt,node_reminders,node_measure,node_customers toneBlue
class node_customerpage toneAmber
class node_ocr,node_parser,node_entries,node_confirmation,node_reminderapi,node_ukurapi,node_store,node_chain,node_totals,node_ilmu toneMint
class node_account,node_shopapi,node_auth toneRose
class node_seller,node_customer toneIndigo
```

## Components

### Seller workflows

- [Snap bill](https://github.com/richard2606-hub/bukusaksi/blob/main/app/snap-bill/page.tsx): `app/snap-bill/page.tsx`
- [Ledger import](https://github.com/richard2606-hub/bukusaksi/blob/main/app/import/page.tsx): `app/import/page.tsx`
- [Debt entry](https://github.com/richard2606-hub/bukusaksi/blob/main/app/add-debt/page.tsx): `app/add-debt/page.tsx`
- [Reminders](https://github.com/richard2606-hub/bukusaksi/blob/main/app/reminders/page.tsx): `app/reminders/page.tsx`
- [Shop measure](https://github.com/richard2606-hub/bukusaksi/blob/main/app/ukur/page.tsx): `app/ukur/page.tsx`
- [Customer list](https://github.com/richard2606-hub/bukusaksi/blob/main/app/customers/page.tsx): `app/customers/page.tsx`

### Customer records

- [Shared record](https://github.com/richard2606-hub/bukusaksi/blob/main/app/c/%5Btoken%5D/page.tsx): `app/c/[token]/page.tsx`

### Business services

- [Photo reading](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/ocr/route.ts): `app/api/ocr/route.ts`
- [Line parsing](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/parse/route.ts): `app/api/parse/route.ts`
- [Entry actions](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/entries/route.ts): `app/api/entries/route.ts`
- [Confirmation](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/confirm/route.ts): `app/api/confirm/route.ts`
- [Reminder drafting](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/reminder/route.ts): `app/api/reminder/route.ts`
- [Ukur analysis](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/ukur/route.ts): `app/api/ukur/route.ts`
- [Record store](https://github.com/richard2606-hub/bukusaksi/blob/main/lib/store.ts): `lib/store.ts`
- [Hash chain](https://github.com/richard2606-hub/bukusaksi/blob/main/lib/chain.ts): `lib/chain.ts`
- [Money totals](https://github.com/richard2606-hub/bukusaksi/blob/main/lib/totals.ts): `lib/totals.ts`
- [ILMU client](https://github.com/richard2606-hub/bukusaksi/blob/main/lib/ilmu.ts): `lib/ilmu.ts`

### Shop and identity

- [Shop account](https://github.com/richard2606-hub/bukusaksi/blob/main/app/account/page.tsx): `app/account/page.tsx`
- [Shop management](https://github.com/richard2606-hub/bukusaksi/blob/main/app/api/shop/route.ts): `app/api/shop/route.ts`
- [Owner access](https://github.com/richard2606-hub/bukusaksi/blob/main/lib/auth.ts): `lib/auth.ts`

### Other components

- **Seller**
- **Customer**

## Connections

- Seller → Snap bill: records photo
- Seller → Ledger import: imports ledger
- Seller → Debt entry: records debt
- Snap bill → Photo reading: requests reading
- Ledger import → Photo reading: requests reading
- Debt entry → Line parsing: requests parsing
- Debt entry → Entry actions: submits record
- Photo reading → ILMU client: reads photo (evidence: `app/api/ocr/route.ts`)
- Line parsing → ILMU client: parses line (evidence: `app/api/parse/route.ts`)
- Entry actions → Record store: writes records (evidence: `app/api/entries/route.ts`)
- Entry actions → Money totals: computes total (evidence: `app/api/entries/route.ts`)
- Entry actions → Hash chain: computes balance (evidence: `app/api/entries/route.ts`)
- Entry actions → Shared record: issues confirm link (evidence: `app/api/entries/route.ts`)
- Customer → Shared record: opens link
- Shared record → Confirmation: confirms or disputes
- Confirmation → Record store: reads and appends (evidence: `app/api/confirm/route.ts`)
- Confirmation → Hash chain: seals result (evidence: `app/api/confirm/route.ts`)
- Shared record → Hash chain: verifies history (evidence: `app/c/[token]/page.tsx`)
- Seller → Reminders: drafts reminder
- Reminders → Reminder drafting: requests draft
- Reminder drafting → Record store: reads records (evidence: `app/api/reminder/route.ts`)
- Reminder drafting → ILMU client: drafts message (evidence: `app/api/reminder/route.ts`)
- Seller → Shop measure: views shop measure
- Shop measure → Ukur analysis: requests analysis
- Ukur analysis → Record store: reads shop data (evidence: `app/api/ukur/route.ts`)
- Ukur analysis → ILMU client: requests analysis (evidence: `app/api/ukur/route.ts`)
- Seller → Customer list: manages customers
- Customer list → Entry actions: views records
- Seller → Shop account: manages shop
- Shop account → Owner access: loads shop context (evidence: `app/account/page.tsx`)
- Shop account → Record store: checks shop records (evidence: `app/account/page.tsx`)
- Shop account → Shop management: manages shop
- Shop management → Owner access: checks owner access (evidence: `app/api/shop/route.ts`)
- Shop management → Record store: updates shop (evidence: `app/api/shop/route.ts`)
- Owner access → Record store: loads memberships (evidence: `lib/auth.ts`)
