How tostman1/drink-pos works
Purpose and entry points
Drink POS is a local-network, touch-oriented beverage tab system for clubs/events. It combines a FastAPI backend, SQLite/WAL persistence, and a vanilla-JS PWA. The ASGI app is exposed from app/main.py (with application composition in app/application.py); primary pages are /, /admin, /kassa, and /self-pay, served from app/index.html, app/admin.html, app/kassa.html, and app/self-pay.html.
HTTP composition and access boundaries
Route modules separate public bookings, administrative operations, cashier payments, self-payment, debug, registry, and restricted agent APIs: app/routes/public.py, app/routes/admin.py, app/routes/payment.py, app/routes/agent.py. Request/response contracts live in app/models/requests.py and app/models/responses.py. Admin/cashier actions are PIN-protected; agent actions require a bearer or dedicated agent-token header, with deliberately narrower permissions.
Domain-service layer
Business operations are centralized in services rather than route handlers: booking/items/persons/orders are handled through app/services/items.py, app/services/people.py, and app/services/orders.py; group-round workflow and reporting use app/services/rounds.py and app/services/statistics.py. Routes validate input, call services, and return API models; services own transactional domain behavior and database-facing workflows.
Persistence, initialization, and recovery
SQLite is the system of record, intended to run in WAL mode. Connection and schema lifecycle are separated in app/db/connection.py, app/db/init.py, and app/db/schema.py. Startup creates missing tables and applies additive migrations without replacing an existing database. Backup/restore are operationally supported by app/backup_database.py and app/restore_database.py; persistent container state is mounted under /app/data.
Payment orchestration and SumUp boundary
Payment flows are implemented in app/services/payments.py, with the external SumUp Cloud API isolated in app/services/sumup.py and HTTP endpoints in app/routes/payment.py. Server-side configuration holds provider credentials and reader identity. Self-pay creates idempotent sessions keyed by browser-generated client_payment_id; pending terminal states lock the person against conflicting bookings, and only confirmed provider success closes items. Card fee and optional rounding are server-calculated.
Browser PWA clients and synchronization
The frontend is server-hosted vanilla HTML/CSS/JS, with shared API/state/sync behavior in app/static/js/api.js, app/static/js/state.js, and app/static/js/sync.js. UI-specific behavior resides below app/static/js/ui/; service-worker and manifests (app/service-worker.js, app/manifest.webmanifest) support installable/offline-oriented usage. Both normal-list and self-pay clients persist in-flight payment IDs locally and poll the backend after reload/network interruption.
Deployment and runtime infrastructure
The runtime is Python/FastAPI under Uvicorn, containerized by Dockerfile. compose.yaml is the canonical Podman deployment and preserves only the data volume; compose.synology.yaml targets Synology Container Manager. GitHub Actions builds/publishes images through .github/workflows/container.yml to GHCR. Optional automated image refresh is provided by deploy/drink-pos-update.service and deploy/drink-pos-update.timer.
Main entry points: public.py Route boundaries · connection.py SQLite WAL database · payments.py Payment orchestration · index.html POS pages
Components 18
Browser PWA
Touch clients served by the backend.
- POS pages · Public, admin, cashier, and self-pay entry pages.
app/index.html - API, state & sync · Persists in-flight payments and polls after interruption.
app/static/js/api.js - Touch UI modules
- Offline install support
app/service-worker.js
FastAPI API
HTTP composition and access boundaries.
- ASGI application · Composes the application and serves clients and APIs.
app/main.py - Route boundaries · Public, admin, cashier, self-pay, debug, registry, and agent endpoints.
app/routes/public.py - API contracts
app/models/requests.py - PIN and agent auth · Admin/cashier use PIN; agents have narrow token-based access.
app/routes/agent.py
Domain Services
Transactional business workflows.
- Tabs, people & orders · Owns booking, items, people, and order workflows.
app/services/orders.py - Rounds & reporting
app/services/rounds.py - Payment orchestration · Calculates fees/rounding, enforces idempotency, and closes confirmed items.
app/services/payments.py
Persistence
SQLite lifecycle and recovery.
- SQLite WAL database · Persistent local tab and payment state.
app/db/connection.py - Schema & migrations · Creates missing tables and applies additive migrations.
app/db/init.py - Backup & restore
app/backup_database.py
Deployment
Container runtime and image delivery.
- Container runtime · Mounts persistent state at /app/data.
Dockerfile - Deployment compose · Canonical deployment preserving only the data volume.
compose.yaml - Image publishing · Builds and publishes container images to GHCR.
.github/workflows/container.yml
Other components
- SumUp Cloud API · Terminal payment boundary.
app/services/sumup.py
Connections 19
- POS pages → API, state & sync: uses
- POS pages → Touch UI modules: renders
- Offline install support → POS pages: caches app shell
- API, state & sync → ASGI application: API calls and polling
- ASGI application → Route boundaries: mounts
- Route boundaries → API contracts: validates
- Route boundaries → PIN and agent auth: enforces
- Route boundaries → Tabs, people & orders: invokes
- Route boundaries → Rounds & reporting: invokes
- Route boundaries → Payment orchestration: payment endpoints
- Tabs, people & orders → SQLite WAL database: transactional state
- Rounds & reporting → SQLite WAL database: queries
- Payment orchestration → SQLite WAL database: sessions and item closure
- Payment orchestration → SumUp Cloud API: creates and confirms terminal payments
- Schema & migrations → SQLite WAL database: initializes and migrates
- Backup & restore → SQLite WAL database: backs up / restores
- Deployment compose → Container runtime: runs
- Container runtime → ASGI application: hosts Uvicorn
- Image publishing → Container runtime: publishes image