# tostman1/drink-pos architecture

> Architecture diagram of the GitHub repository tostman1/drink-pos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tostman1/drink-pos
- Repository: https://github.com/tostman1/drink-pos

## Overview

#### 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: [`app/routes/public.py`](https://github.com/tostman1/drink-pos/blob/main/app/routes/public.py) (Route boundaries), [`app/db/connection.py`](https://github.com/tostman1/drink-pos/blob/main/app/db/connection.py) (SQLite WAL database), [`app/services/payments.py`](https://github.com/tostman1/drink-pos/blob/main/app/services/payments.py) (Payment orchestration), [`app/index.html`](https://github.com/tostman1/drink-pos/blob/main/app/index.html) (POS pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser PWA"]
  node_pages["POS pages<br/>HTML clients<br/>[index.html]"]
  node_browser_core["API, state &amp; sync<br/>browser shared layer<br/>[api.js]"]
  node_ui["Touch UI modules<br/>browser UI"]
  node_offline["Offline install support<br/>service worker<br/>[service-worker.js]"]
end

subgraph group_api["FastAPI API"]
  node_asgi{{"ASGI application<br/>FastAPI runtime<br/>[main.py]"}}
  node_routes["Route boundaries<br/>HTTP routes<br/>[public.py]"]
  node_contracts["API contracts<br/>request/response models<br/>[requests.py]"]
  node_access["PIN and agent auth<br/>access control<br/>[agent.py]"]
end

subgraph group_domain["Domain Services"]
  node_core_services["Tabs, people &amp; orders<br/>domain services<br/>[orders.py]"]
  node_rounds_stats["Rounds &amp; reporting<br/>domain services<br/>[rounds.py]"]
  node_payments["Payment orchestration<br/>payment service<br/>[payments.py]"]
end

subgraph group_data["Persistence"]
  node_sqlite[("SQLite WAL database<br/>system of record<br/>[connection.py]")]
  node_schema["Schema &amp; migrations<br/>database lifecycle<br/>[init.py]"]
  node_recovery["Backup &amp; restore<br/>operational recovery<br/>[backup_database.py]"]
end

subgraph group_ops["Deployment"]
  node_container["Container runtime<br/>Docker / Podman"]
  node_compose["Deployment compose<br/>Podman compose<br/>[compose.yaml]"]
  node_ci["Image publishing<br/>GitHub Actions<br/>[container.yml]"]
end

node_sumup{{"SumUp Cloud API<br/>external payment provider<br/>[sumup.py]"}}

node_pages -->|"uses"| node_browser_core
node_pages -->|"renders"| node_ui
node_offline -.->|"caches app shell"| node_pages
node_browser_core -->|"API calls and polling"| node_asgi
node_asgi -->|"mounts"| node_routes
node_routes -->|"validates"| node_contracts
node_routes -->|"enforces"| node_access
node_routes -->|"invokes"| node_core_services
node_routes -->|"invokes"| node_rounds_stats
node_routes -->|"payment endpoints"| node_payments
node_core_services -->|"transactional state"| node_sqlite
node_rounds_stats -->|"queries"| node_sqlite
node_payments -->|"sessions and item closure"| node_sqlite
node_payments -->|"creates and confirms terminal payments"| node_sumup
node_schema -->|"initializes and migrates"| node_sqlite
node_recovery -.->|"backs up / restores"| node_sqlite
node_compose -->|"runs"| node_container
node_container -->|"hosts Uvicorn"| node_asgi
node_ci -->|"publishes image"| node_container

click node_pages "https://github.com/tostman1/drink-pos/blob/main/app/index.html"
click node_browser_core "https://github.com/tostman1/drink-pos/blob/main/app/static/js/api.js"
click node_offline "https://github.com/tostman1/drink-pos/blob/main/app/service-worker.js"
click node_asgi "https://github.com/tostman1/drink-pos/blob/main/app/main.py"
click node_routes "https://github.com/tostman1/drink-pos/blob/main/app/routes/public.py"
click node_contracts "https://github.com/tostman1/drink-pos/blob/main/app/models/requests.py"
click node_access "https://github.com/tostman1/drink-pos/blob/main/app/routes/agent.py"
click node_core_services "https://github.com/tostman1/drink-pos/blob/main/app/services/orders.py"
click node_rounds_stats "https://github.com/tostman1/drink-pos/blob/main/app/services/rounds.py"
click node_payments "https://github.com/tostman1/drink-pos/blob/main/app/services/payments.py"
click node_sumup "https://github.com/tostman1/drink-pos/blob/main/app/services/sumup.py"
click node_sqlite "https://github.com/tostman1/drink-pos/blob/main/app/db/connection.py"
click node_schema "https://github.com/tostman1/drink-pos/blob/main/app/db/init.py"
click node_recovery "https://github.com/tostman1/drink-pos/blob/main/app/backup_database.py"
click node_container "https://github.com/tostman1/drink-pos/blob/main/Dockerfile"
click node_compose "https://github.com/tostman1/drink-pos/blob/main/compose.yaml"
click node_ci "https://github.com/tostman1/drink-pos/blob/main/.github/workflows/container.yml"

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_pages,node_browser_core,node_ui,node_offline toneBlue
class node_asgi,node_routes,node_contracts,node_access toneAmber
class node_core_services,node_rounds_stats,node_payments toneMint
class node_sqlite,node_schema,node_recovery toneRose
class node_container,node_compose,node_ci toneIndigo
class node_sumup toneNeutral
```

## Components

### Browser PWA

Touch clients served by the backend.

- [POS pages](https://github.com/tostman1/drink-pos/blob/main/app/index.html): HTML clients · Public, admin, cashier, and self-pay entry pages. · `app/index.html`
- [API, state & sync](https://github.com/tostman1/drink-pos/blob/main/app/static/js/api.js): browser shared layer · Persists in-flight payments and polls after interruption. · `app/static/js/api.js`
- **Touch UI modules**: browser UI
- [Offline install support](https://github.com/tostman1/drink-pos/blob/main/app/service-worker.js): service worker · `app/service-worker.js`

### FastAPI API

HTTP composition and access boundaries.

- [ASGI application](https://github.com/tostman1/drink-pos/blob/main/app/main.py): FastAPI runtime · Composes the application and serves clients and APIs. · `app/main.py`
- [Route boundaries](https://github.com/tostman1/drink-pos/blob/main/app/routes/public.py): HTTP routes · Public, admin, cashier, self-pay, debug, registry, and agent endpoints. · `app/routes/public.py`
- [API contracts](https://github.com/tostman1/drink-pos/blob/main/app/models/requests.py): request/response models · `app/models/requests.py`
- [PIN and agent auth](https://github.com/tostman1/drink-pos/blob/main/app/routes/agent.py): access control · Admin/cashier use PIN; agents have narrow token-based access. · `app/routes/agent.py`

### Domain Services

Transactional business workflows.

- [Tabs, people & orders](https://github.com/tostman1/drink-pos/blob/main/app/services/orders.py): domain services · Owns booking, items, people, and order workflows. · `app/services/orders.py`
- [Rounds & reporting](https://github.com/tostman1/drink-pos/blob/main/app/services/rounds.py): domain services · `app/services/rounds.py`
- [Payment orchestration](https://github.com/tostman1/drink-pos/blob/main/app/services/payments.py): payment service · Calculates fees/rounding, enforces idempotency, and closes confirmed items. · `app/services/payments.py`

### Persistence

SQLite lifecycle and recovery.

- [SQLite WAL database](https://github.com/tostman1/drink-pos/blob/main/app/db/connection.py): system of record · Persistent local tab and payment state. · `app/db/connection.py`
- [Schema & migrations](https://github.com/tostman1/drink-pos/blob/main/app/db/init.py): database lifecycle · Creates missing tables and applies additive migrations. · `app/db/init.py`
- [Backup & restore](https://github.com/tostman1/drink-pos/blob/main/app/backup_database.py): operational recovery · `app/backup_database.py`

### Deployment

Container runtime and image delivery.

- [Container runtime](https://github.com/tostman1/drink-pos/blob/main/Dockerfile): Docker / Podman · Mounts persistent state at /app/data. · `Dockerfile`
- [Deployment compose](https://github.com/tostman1/drink-pos/blob/main/compose.yaml): Podman compose · Canonical deployment preserving only the data volume. · `compose.yaml`
- [Image publishing](https://github.com/tostman1/drink-pos/blob/main/.github/workflows/container.yml): GitHub Actions · Builds and publishes container images to GHCR. · `.github/workflows/container.yml`

### Other components

- [SumUp Cloud API](https://github.com/tostman1/drink-pos/blob/main/app/services/sumup.py): external payment provider · Terminal payment boundary. · `app/services/sumup.py`

## Connections

- 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
