Architecture tour
Follow one barcode scan and purchase action from the React UI through the Go API and SQLite and back.
Follow what happens when a household member scans a UPC barcode in Scan / Action to record a purchase.
1. Camera or HID barcode scan (web/src/components/ScannerDrawer.tsx)
BarcodeScanner.tsxdecodes the barcode using self-hostedzxing-wasm(or reads keyboard input from a USB/Bluetooth scanner).ScannerDrawer.tsxposts the code toPOST /api/scan/resolveviaweb/src/api.ts.
2. Resolution and optional lookup (internal/api/workflows.go)
Server.handleScanResolvechecks whether the code is an itemized QR URL (/go/i/:id,/go/p/:id,/go/l/:id) or a retail barcode stored in thebarcodestable.- If the retail barcode is unknown, the client calls
POST /api/upc/lookup(internal/upc) and, when configured,POST /api/upc/classify(internal/llm) to suggest a standardized product name, category, and location.
3. Recording the purchase (internal/api/workflows.go & internal/domain/)
- Submitting the Purchase form sends
POST /api/workflows/purchase. - The handler creates or reuses the
products,variants, andbarcodesrows, calculates due dates usinginternal/domain(either rolling-average history or fixeddefault_due_days), inserts the newitemsrows in SQLite (internal/db), and auto-clears the manual shopping-list flag if stock now meetsmin_stock.
4. Label printing and UI refresh (internal/printer/)
- If the product's label mode is
per_itemorper_product,internal/printerrenders the Gotext/templateZPL layout and sends it over IPP or raw TCP:9100(skipped/simulated inDEMO_MODE). - The API returns the created items and any printer warning. React Query invalidates
["products"]and["products", "counts"], updating the inventory list and sidebar badges immediately.
Run make test to execute the Go and Vitest suites covering every layer of this flow.