How kratospidey/sasta_dmart works
1. Repository shape
- This repo is a three-part checkout system built around Firebase Realtime Database:
- a Raspberry Pi checkout kiosk
- a laptop operator dashboard
- a public hosted claim page for phone-based Google sign-in
- Shared Python code lives under sasta_dmart/; the hosted phone flow lives in public_claim/; docs and RTDB rules are in docs/.
2. Primary runtime boundaries
- The Pi owns checkout, camera/barcode scanning, session creation, and transaction writing.
- The public claim site owns authentication and one-time claim of a pending checkout session.
- The laptop dashboard is monitoring/diagnostics only; it is explicitly not part of the phone auth path.
- Firebase is the integration point between all three runtimes.
3. Pi checkout application
- pi_checkout_gui_firebase.py is the main Pi entrypoint.
- It depends on Pi-specific packages like Picamera2, Tk, PIL, and pyzbar, which indicates a local GUI app that previews camera input and scans barcodes.
- Its backend responsibilities are session lifecycle, QR generation, Firebase polling for claim status, and final bill/transaction submission.
4. Laptop dashboard
- laptop_firebase_portal.py is the operator-facing entrypoint.
- The sasta_dmart/portal/ package includes Python templates and static assets, so this is a server-rendered dashboard rather than a client-heavy SPA.
- Its role is to display transactions, session state, and diagnostics from Firebase; it does not participate in login or claim actions.
5. Public claim page
- public_claim/ is a static web app served from a canonical HTTPS origin such as claim.yourdomain.com.
- It contains the customer flow for QR-based session claim and a separate purchase history page (history.html / history.js).
- The build step (public_claim/build_config.py) injects Firebase web config into a generated config.js, so the hosted site is deployment-configured rather than server-rendered.
6. Shared application logic
- sasta_dmart/firebase.py centralizes Firebase access, likely separating Admin SDK use on Pi/laptop from web-client Firebase usage.
- sasta_dmart/sessions.py encapsulates session token creation and lifecycle transitions.
- sasta_dmart/transactions.py encapsulates bill/transaction creation and persistence.
- sasta_dmart/config.py holds runtime configuration sourced from environment variables.
- These modules form the core domain layer shared by the Pi and laptop apps.
7. Product and barcode subsystem
- sasta_dmart/products.json is the product catalog source of truth.
- sasta_dmart/product_catalog.py loads and validates catalog data.
- sasta_dmart/barcodes.py and generate_barcodes.py handle barcode generation and catalog-upsert workflows.
- This subsystem feeds the Pi scanner and keeps product identity, pricing, and barcode representation consistent.
8. Session and claim data flow
- The Pi creates a high-entropy token and writes a login_sessions/<token> record to Firebase RTDB.
- The QR code points to the public claim domain with that token.
- After Google sign-in on the hosted page, the phone client verifies the token and performs an atomic pending -> claimed transition.
- The Pi polls Firebase for that state change and then associates the checkout session with the claimed user.
9. Transaction and history flow
- Once checkout is complete, the Pi writes a final transaction record to Firebase.
- The README shows a dual-branch model: a closed transactions branch and a customer-readable customer_transactions/<uid> branch.
- public_claim/history.html reads purchase history for the signed-in customer from the customer-facing branch.
10. Security and access control
- RTDB rules in docs/firebase-rtdb-rules.json are a central part of the architecture.
- Client-side claim flows require authentication, session claims are atomic, and transaction storage is not broadly client-writable.
- The Pi and laptop use the Firebase Admin SDK via a service account, so they bypass client RTDB restrictions while staying trusted.
11. Deployment/configuration model
- Runtime settings are environment-driven: Firebase DB URL, service account path, public claim base URL, laptop dashboard URL, and Pi node name.
- The hosted claim page has its own Firebase web-app config variables and must be rebuilt/redeployed when those values change.
- The Pi QR codes must always use the canonical public claim origin, which is a key architectural boundary.
12. Tooling and validation
- requirements-pi.txt, requirements-laptop.txt, and requirements-dev.txt split dependencies by runtime.
- The tests/ directory covers catalog, barcode generation, sessions, transactions, portal behavior, public claim state/history, and build/config generation.
- This suggests the repo treats each subsystem as independently testable, with Firebase state and generated artifacts being important integration points.
Main entry points: pi_checkout_gui_firebase.py Checkout app · firebase.py Firebase RTDB · index.html Claim site · config.py Runtime config
Components 21
Pi kiosk
Local checkout application running on the Raspberry Pi.
- Checkout app · Main Pi GUI entrypoint for scanning, session creation, and checkout flow.
pi_checkout_gui_firebase.py - Camera scan · Local camera preview and barcode scanning on the Pi.
- Session lifecycle · Creates checkout sessions, tracks claim state, and coordinates the QR token flow.
sasta_dmart/sessions.py - Bill writer · Builds and submits final checkout transactions to Firebase.
sasta_dmart/transactions.py - QR claim link · Generates the public claim URL that encodes the pending session token.
Laptop portal
Operator dashboard runtime for monitoring and diagnostics.
- Portal app · Operator-facing dashboard entrypoint for monitoring and diagnostics.
laptop_firebase_portal.py - Portal UI · Server-rendered dashboard package with templates and static assets.
sasta_dmart/portal/__init__.py - Templates · HTML templates for the dashboard shell and main view.
sasta_dmart/portal/templates/dashboard.html - Portal assets · Dashboard stylesheet and client script for the operator UI.
sasta_dmart/portal/static/portal.js
Public claim
Hosted customer claim site for phone-based Google sign-in.
- Claim site · Hosted customer-facing claim and history pages.
public_claim/index.html - Claim state · Browser-side state machine for QR claim and session polling.
public_claim/claim_state.mjs - Google sign-in · Customer authentication and claim authorization on the hosted site.
public_claim/app.js - History page · Signed-in purchase history view for the customer branch.
public_claim/history.html - History state · Browser-side history loading and rendering logic.
public_claim/history_state.mjs
Shared core
Reusable domain logic, Firebase access, and catalog data.
- Firebase RTDB · Shared realtime database boundary for sessions, claims, and transactions.
sasta_dmart/firebase.py - Product catalog · Source of truth for products, pricing, and barcode identity.
sasta_dmart/products.json - Catalog loader · Loads and validates catalog data used by checkout and barcode tooling.
sasta_dmart/product_catalog.py - Barcode tools · Barcode generation and catalog-upsert workflow.
sasta_dmart/barcodes.py - Runtime config · Environment-driven settings for Firebase, origins, and node identity.
sasta_dmart/config.py
Ops and rules
Rules, requirements, and deployment support artifacts.
- RTDB rules · Realtime Database access policy for client claims and transaction visibility.
docs/firebase-rtdb-rules.json - Web build · Injects Firebase web config into the hosted claim site.
public_claim/build_config.py
Connections 27
- Checkout app → Camera scan: scan items · The kiosk previews the camera and decodes barcodes during checkout.
- Checkout app → Session lifecycle: create claim · The kiosk starts pending sessions and monitors their lifecycle.
- Checkout app → QR claim link: show QR · The kiosk renders the public claim link for the pending session.
- Session lifecycle → Firebase RTDB: write session · Session tokens and claim state are stored in realtime database.
- Bill writer → Firebase RTDB: write txn · Completed bills are persisted as transaction records.
- QR claim link → Claim site: open link · The QR code directs the customer to the hosted claim origin.
- Portal app → Portal UI: serve dashboard · The laptop entrypoint renders the operator dashboard package.
- Portal UI → Templates: render view · The dashboard uses server-side templates for its main screens.
- Portal UI → Portal assets: deliver assets · Static browser assets power the operator UI behavior.
- Portal app → Firebase RTDB: read state · The dashboard reads sessions, transactions, and diagnostics from Firebase.
- Claim site → Google sign-in: sign in · The customer claim flow begins with Google authentication.
- Claim site → Claim state: run state · The browser app drives QR claim state transitions.
- Claim state → Firebase RTDB: claim session · The hosted page verifies the token and atomically claims the pending session.
- Claim site → History page: show history · The hosted site includes a separate customer purchase history page.
- History page → History state: load history · The history page uses client logic to fetch and render customer purchases.
- History state → Firebase RTDB: read purchases · History data is read from the customer-facing transaction branch.
- Catalog loader → Product catalog: load data · Catalog logic reads the product source of truth.
- Barcode tools → Catalog loader: use catalog · Barcode generation depends on validated product data and identity mapping.
- Checkout app → Catalog loader: price items · Checkout uses the shared catalog for item lookup and pricing.
- Claim site → Runtime config: web config · The hosted site is built with generated Firebase web configuration.
- Web build → Claim site: generate config · Build tooling injects deployment-specific configuration for the claim site.
- RTDB rules → Firebase RTDB: guard access · RTDB rules constrain client writes and customer-readable branches.
- Runtime config → Checkout app: env settings · The kiosk runtime is configured via environment variables.
- Runtime config → Portal app: env settings · The portal runtime is configured via environment variables.
- Runtime config → Firebase RTDB: db settings · Firebase URL and service-account settings are shared runtime inputs.
- Checkout app → RTDB rules: trust boundary · The Pi relies on Admin SDK access while client flows remain constrained by rules.
- Portal app → RTDB rules: trust boundary · The dashboard also uses trusted Firebase access outside client rules.