How lostmind84/openscale works
Purpose and Entry Points
OpenScale is a self-service grocery weighing station: select a product on a touchscreen, acquire weight, price it, generate EAN-13, and print a label. It is a standalone Go binary with embedded client and administration UIs. CLI composition and operational commands live in cmd/openscale/main.go, cmd/openscale/serve.go, and cmd/openscale/service.go; serve hosts the station and HTTP UI/API.
Composition Root and Runtime Boundary
The CLI loads configuration, data directories, drivers, persistence, station workers, and web server. Configuration and platform-specific paths/services are separated from business logic in cmd/openscale/config.go, internal/platform/paths.go, and internal/platform/service.go. The production runtime is Go without cgo, cross-compiled for Windows, Linux, and Linux ARM64; Node/Svelte is build-time only.
Domain and Station Orchestration
internal/domain/ contains stable business types and rules: products, measurements, tare/safeguards, pricing, barcode generation, label templates, and configuration contracts (internal/domain/product.go, internal/domain/pricing.go, internal/domain/prepare.go). internal/station/ is the application core: it coordinates catalog snapshots, weight events, manual entry, print requests, idempotency, failure handling, and background workers (internal/station/station.go, internal/station/hub.go, internal/station/workers.go). This is the principal boundary between HTTP/hardware adapters and domain decisions.
Weigh-to-Label Flow
A client UI/API request identifies a product; station logic obtains a stable scale measurement or permitted manual weight, applies tare and safeguards, computes price, creates the EAN-13/label payload, records the result, and dispatches printing. HTTP endpoints and streaming state are in internal/web/server.go, internal/web/command.go, and internal/web/stream.go. Scale adapters are registered behind a driver interface, with serial and replay implementations in internal/scale/registry.go, internal/scale/serial/scale.go, and internal/scale/gramxfoc/gramxfoc.go. This allows real GRAM serial hardware, absent/replay modes, and isolated new driver additions.
Printing Pipeline
The printing subsystem transforms domain label data into layout/render output and delivers bytes through configured transports. Core service/driver selection is in internal/printing/service.go and internal/printing/registry.go; SATO-oriented SBPL encoding is in internal/printing/sbpl/sbpl.go; physical delivery supports TCP, files, device files, and Windows spooler via internal/printing/transport/transport.go and internal/printing/transport/winspool_windows.go. PDF and raster paths support preview/diagnostics independently of hardware.
Catalog and Local Persistence
Each station owns its SQLite-backed operational state, catalog, journals, imports, quarantine, and technical metadata. Storage and migrations are in internal/store/store.go, internal/store/migrations/0001_initial.sql, and internal/store/catalog.go. Catalog ingestion is staged: source discovery/fetch, parsing, assembly/qualification, findings/quarantine, then atomic catalog availability (internal/catalog/importer/importer.go, internal/catalog/assemble.go, internal/catalog/quarantine.go). Supported sources include Odoo CSV, local drop folders with deletion-as-acknowledgment, and WebDAV (internal/catalog/csvodoo/csvodoo.go, internal/catalog/localdrop/localdrop.go, internal/catalog/webdav/webdav.go).
Web Interfaces and Operations
Embedded static client/admin assets are served by internal/web/embed.go; source Svelte applications are in web/src/main.ts and web/src/admin/mount.ts. The client consumes catalog and station state; the admin surface controls configuration, catalog, hardware, journal, diagnostics, and updates through server handlers such as internal/web/admin.go and internal/web/update.go. Diagnostics gather machine, hardware, service, and redacted support reports (internal/diag/doctor.go, internal/diag/report.go). Update logic discovers GitHub releases, stages verified artifacts, and coordinates safe application (internal/update/github.go, internal/update/stager.go, internal/update/service.go).
Deployment and External Dependencies
There is no central backend: weighing works offline once installed. External interactions are local serial ports, network/device/spool printing, optional WebDAV catalog access, and GitHub Releases for updates. Windows installation creates a dedicated account, service, scheduled kiosk task, and hardening through deploy/windows/install.ps1 and deploy/windows/openscale-kiosk.xml; Debian uses systemd units and bootstrap scripts in deploy/linux/bootstrap.sh and deploy/linux/openscale.service. Kiosk supervision and recovery are isolated in internal/kiosk/supervisor.go and internal/kiosk/rescue.go.
Main entry points: server.go HTTP server & commands · station.go Station orchestration · serve.go Serve command · main.go CLI composition
Components 20
Station Runtime
- CLI composition · Loads runtime dependencies and runs station commands.
cmd/openscale/main.go - Serve command · Hosts the station HTTP UI and API.
cmd/openscale/serve.go - Config & platform · Resolves configuration, platform paths, and services.
cmd/openscale/config.go - HTTP server & commands · Exposes station commands and streaming state.
internal/web/server.go - Embedded client/admin UI · Build-time Svelte interfaces served by the Go binary.
internal/web/embed.go - Station orchestration · Coordinates weigh, price, label, journal, idempotency, and workers.
internal/station/station.go - Domain rules · Products, safeguards, pricing, EAN-13, and label preparation.
internal/domain/prepare.go
Hardware & Output
- Scale driver registry · Selects registered scale implementations.
internal/scale/registry.go - GRAM serial scale
internal/scale/gramxfoc/gramxfoc.go - Printing service · Selects print drivers and dispatches label output.
internal/printing/service.go - SBPL renderer · Encodes SATO-oriented print bytes.
internal/printing/sbpl/sbpl.go - Print transports · Delivers through TCP, files, devices, or Windows spooler.
internal/printing/transport/transport.go
Catalog & Storage
- SQLite operational store · Owns catalog, journals, imports, quarantine, and metadata.
internal/store/store.go - Catalog import pipeline · Discovers, parses, qualifies, quarantines, and atomically publishes catalogs.
internal/catalog/importer/importer.go - Catalog sources · Odoo CSV, local drop folders, and WebDAV.
internal/catalog/csvodoo/csvodoo.go
Operations
- Diagnostics & reports · Collects hardware, service, and redacted support information.
internal/diag/doctor.go - Safe updater · Finds releases, verifies artifacts, stages, and applies updates.
internal/update/service.go - Kiosk supervision · Supervises kiosk operation and recovery.
internal/kiosk/supervisor.go - OS deployment services · Installs Windows kiosk/service or Debian systemd runtime.
deploy/windows/install.ps1
Other components
- Scale, printer & network · Serial scale, print endpoints, optional WebDAV, and GitHub Releases.
Connections 24
- CLI composition → Serve command: runs
- CLI composition → Config & platform: initializes
- Serve command → HTTP server & commands: hosts
- Serve command → Station orchestration: starts
- HTTP server & commands → Embedded client/admin UI: serves
- Embedded client/admin UI → HTTP server & commands: commands and state
- HTTP server & commands → Station orchestration: weigh and admin commands
- Station orchestration → Domain rules: applies rules
- Station orchestration → Scale driver registry: reads measurements
- Station orchestration → Printing service: dispatches labels
- Station orchestration → SQLite operational store: reads catalog and records results
- Scale driver registry → GRAM serial scale: selects driver
- GRAM serial scale → Scale, printer & network: serial I/O
- Printing service → SBPL renderer: renders labels
- SBPL renderer → Print transports: print bytes
- Print transports → Scale, printer & network: delivers output
- Catalog sources → Catalog import pipeline: catalog input
- Catalog import pipeline → SQLite operational store: publishes catalog and findings
- Catalog sources → Scale, printer & network: WebDAV access
- HTTP server & commands → Diagnostics & reports: admin diagnostics
- HTTP server & commands → Safe updater: admin updates
- Safe updater → Scale, printer & network: GitHub releases
- OS deployment services → Kiosk supervision: installs and supervises
- OS deployment services → Serve command: runs as service