# pku2213/sketch-coffee-pad-new architecture

> Architecture diagram of the GitHub repository pku2213/sketch-coffee-pad-new, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pku2213/sketch-coffee-pad-new
- Repository: https://github.com/pku2213/sketch-coffee-pad-new
- Video tour (about a minute): https://gitdiagram.com/pku2213/sketch-coffee-pad-new/video

## Overview

Sketch Coffee is an in-store tablet system for café ordering and daily operations. The main workflow is browsing and configuring a drink, calculating its price, recording it locally, then completing it in the ledger and syncing it to Feishu; offline orders wait for retry. Separate workflows cover recipes, restocking, and shift checklists. The graph includes the documented local-first storage and Feishu menu/checklist integrations. Several page and library implementations were not sampled, so those connections reflect README documentation rather than inspected call sites.

Main entry points: [`lib/db.ts`](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/db.ts) (Tablet IndexedDB), [`lib/sync.ts`](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/sync.ts) (Refresh and retry), [`components/MenuBrowser.tsx`](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/components/MenuBrowser.tsx) (Menu browser), [`app/order/page.tsx`](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/order/page.tsx) (Order page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Tablet workflows"]
  node_order["Order page<br/>[page.tsx]"]
  node_menu["Menu browser<br/>[MenuBrowser.tsx]"]
  node_recipes["Recipe page<br/>[page.tsx]"]
  node_ledger["Ledger page<br/>[page.tsx]"]
  node_restock["Restock page<br/>[page.tsx]"]
  node_duty["Duty checklist<br/>[page.tsx]"]
  node_settings["Settings modal<br/>[SettingsModal.tsx]"]
end

subgraph group_domain["Domain services"]
  node_pricing["Price calculation<br/>[pricing.ts]"]
  node_orders["Order lifecycle<br/>[orders.ts]"]
  node_search["Menu search<br/>[search.ts]"]
  node_restock_service["Supply tracking<br/>[restock.ts]"]
  node_settings_service["Shift settings<br/>[settings.ts]"]
  node_sync["Refresh and retry<br/>[sync.ts]"]
  node_menu_hook["Local menu access<br/>[useMenu.ts]"]
end

subgraph group_local["Local data"]
  node_localdb[("Tablet IndexedDB<br/>[db.ts]")]
end

subgraph group_remote["Feishu integration"]
  node_menu_api["Menu endpoint<br/>[route.ts]"]
  node_duty_api["Duty endpoint<br/>[route.ts]"]
  node_orders_api["Order sync endpoint<br/>[route.ts]"]
  node_feishu_client["Feishu client<br/>[feishu.ts]"]
end

node_staff(("Café staff"))
node_feishu[("Feishu Bitable")]

node_staff -->|"places orders"| node_order
node_staff -->|"views recipes"| node_recipes
node_staff -->|"tracks orders"| node_ledger
node_staff -->|"tracks supplies"| node_restock
node_staff -->|"checks tasks"| node_duty
node_staff -->|"sets preferences"| node_settings
node_order -->|"browses menu"| node_menu
node_recipes -->|"browses recipes"| node_menu
node_menu -->|"searches items"| node_search
node_menu -->|"loads menu"| node_menu_hook
node_menu -->|"refreshes menu"| node_sync
node_menu_hook -->|"reads menu"| node_localdb
node_order -->|"calculates price"| node_pricing
node_order -->|"records orders"| node_localdb
node_ledger -->|"completes or reverses"| node_orders
node_orders -->|"updates orders"| node_localdb
node_restock -->|"records changes"| node_restock_service
node_restock -->|"reads and writes"| node_localdb
node_duty -->|"refreshes checklist"| node_sync
node_duty -->|"stores check state"| node_localdb
node_settings -->|"updates settings"| node_settings_service
node_settings_service -->|"stores settings"| node_localdb
node_sync -->|"fetches menu"| node_menu_api
node_sync -->|"fetches checklist"| node_duty_api
node_sync -->|"uploads queued orders"| node_orders_api
node_sync -->|"refreshes and retries"| node_localdb
node_menu_api -->|"requests menu"| node_feishu_client
node_duty_api -->|"requests tasks"| node_feishu_client
node_orders_api -->|"checks and writes orders"| node_feishu_client
node_feishu_client -->|"reads and writes"| node_feishu

click node_order "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/order/page.tsx"
click node_menu "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/components/MenuBrowser.tsx"
click node_recipes "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/process/page.tsx"
click node_ledger "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/ledger/page.tsx"
click node_restock "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/restock/page.tsx"
click node_duty "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/duty/page.tsx"
click node_settings "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/components/SettingsModal.tsx"
click node_pricing "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/pricing.ts"
click node_orders "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/orders.ts"
click node_search "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/search.ts"
click node_restock_service "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/restock.ts"
click node_settings_service "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/settings.ts"
click node_sync "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/sync.ts"
click node_menu_hook "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/useMenu.ts"
click node_localdb "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/db.ts"
click node_menu_api "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/api/menu/route.ts"
click node_duty_api "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/api/duty/route.ts"
click node_orders_api "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/api/orders/sync/route.ts"
click node_feishu_client "https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/feishu.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_order,node_menu,node_recipes,node_ledger,node_restock,node_duty,node_settings toneBlue
class node_pricing,node_orders,node_search,node_restock_service,node_settings_service,node_sync,node_menu_hook,node_feishu toneAmber
class node_localdb toneMint
class node_menu_api,node_duty_api,node_orders_api,node_feishu_client toneRose
class node_staff toneIndigo
```

## Components

### Tablet workflows

- [Order page](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/order/page.tsx): `app/order/page.tsx`
- [Menu browser](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/components/MenuBrowser.tsx): `components/MenuBrowser.tsx`
- [Recipe page](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/process/page.tsx): `app/process/page.tsx`
- [Ledger page](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/ledger/page.tsx): `app/ledger/page.tsx`
- [Restock page](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/restock/page.tsx): `app/restock/page.tsx`
- [Duty checklist](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/duty/page.tsx): `app/duty/page.tsx`
- [Settings modal](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/components/SettingsModal.tsx): `components/SettingsModal.tsx`

### Domain services

- [Price calculation](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/pricing.ts): `lib/pricing.ts`
- [Order lifecycle](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/orders.ts): `lib/orders.ts`
- [Menu search](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/search.ts): `lib/search.ts`
- [Supply tracking](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/restock.ts): `lib/restock.ts`
- [Shift settings](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/settings.ts): `lib/settings.ts`
- [Refresh and retry](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/sync.ts): `lib/sync.ts`
- [Local menu access](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/useMenu.ts): `lib/useMenu.ts`

### Local data

- [Tablet IndexedDB](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/db.ts): `lib/db.ts`

### Feishu integration

- [Menu endpoint](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/api/menu/route.ts): `app/api/menu/route.ts`
- [Duty endpoint](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/api/duty/route.ts): `app/api/duty/route.ts`
- [Order sync endpoint](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/app/api/orders/sync/route.ts): `app/api/orders/sync/route.ts`
- [Feishu client](https://github.com/pku2213/sketch-coffee-pad-new/blob/main/lib/feishu.ts): `lib/feishu.ts`

### Other components

- **Café staff**
- **Feishu Bitable**

## Connections

- Café staff → Order page: places orders
- Café staff → Recipe page: views recipes
- Café staff → Ledger page: tracks orders
- Café staff → Restock page: tracks supplies
- Café staff → Duty checklist: checks tasks
- Café staff → Settings modal: sets preferences
- Order page → Menu browser: browses menu
- Recipe page → Menu browser: browses recipes
- Menu browser → Menu search: searches items
- Menu browser → Local menu access: loads menu
- Menu browser → Refresh and retry: refreshes menu
- Local menu access → Tablet IndexedDB: reads menu
- Order page → Price calculation: calculates price
- Order page → Tablet IndexedDB: records orders
- Ledger page → Order lifecycle: completes or reverses
- Order lifecycle → Tablet IndexedDB: updates orders
- Restock page → Supply tracking: records changes
- Restock page → Tablet IndexedDB: reads and writes
- Duty checklist → Refresh and retry: refreshes checklist
- Duty checklist → Tablet IndexedDB: stores check state
- Settings modal → Shift settings: updates settings
- Shift settings → Tablet IndexedDB: stores settings
- Refresh and retry → Menu endpoint: fetches menu
- Refresh and retry → Duty endpoint: fetches checklist
- Refresh and retry → Order sync endpoint: uploads queued orders
- Refresh and retry → Tablet IndexedDB: refreshes and retries
- Menu endpoint → Feishu client: requests menu
- Duty endpoint → Feishu client: requests tasks
- Order sync endpoint → Feishu client: checks and writes orders
- Feishu client → Feishu Bitable: reads and writes
