Skip to the page
gužvadocs
Menu

Overview

How it works

The parts of guzva, the path of one picture from the camera to a guest's phone, and the contracts every change keeps.

guzva.ba shows guests how busy a venue is right now, with a live picture from a small camera in the room. The picture is stylised so nobody can be recognised. Owners get a panel with their statistics and settings; an admin console runs the whole fleet.

The parts

[venue Wi-Fi]
  ESP32-CAM ── HTTPS POST /v1/ingest ──┐  (the camera only ever sends; the server never calls it)
                                       v
              [netcup VPS, Debian 13]  guzva (one Go binary, systemd service)
                 ├─ ingest     receive, check, render the picture
                 ├─ public     guzva.ba/<venue>/ pages, pre-rendered to disk
                 ├─ admin      /admin/ (operator)   owner  /owner/ (venue owners)
                 ├─ sched      jobs on a timer: page refresh, alerts, mail, pruning
                 ├─ SQLite     /var/lib/guzva/guzva.db (WAL mode)
                 └─ TLS        Let's Encrypt certificates, fetched by the binary itself
PartWhat it isWhy this choice
CameraESP32-CAM board, firmware in C++ (PlatformIO)About 10 € a board, runs on USB power, enough to take one picture and send it over HTTPS
Server programGo, standard library plus 3 dependenciesOne static file to deploy, fast, easy to test, no runtime to install
DatabaseSQLite (modernc.org/sqlite, pure Go)No database server to run or secure; the whole state is one file to copy and check
Pageshtml/template + htmx, CSS from Tailwind built at compile timeServer-rendered pages load fast on cheap phones; htmx adds partial updates without a JS app
TLSgolang.org/x/crypto/acme/autocert inside the binaryNo nginx or Caddy in front; certificates renew themselves
AlertsTelegram bot message to one personFree, instant, already on the phone
EmailBrevo SMTP (out), Cloudflare routing (in)Reliable delivery without running a mail server

The path of one picture

  1. Capture. The camera takes a JPEG every 30–60 s (the venue's interval; the Jadro board posts about every 31 s).
  2. Send. It POSTs the JPEG to ingest.guzva.ba/v1/ingest over TLS, with its device token and a capture_id that is unique per picture.
  3. Check. The server checks the token, the rate limit and the size. If the same capture_id arrives twice (a retry after a lost answer), the second gets 409 with the same body as the first 201. This is called idempotency: a retry can never create a duplicate.
  4. Render. The raw JPEG is decoded in memory, turned into the stylised picture, and the raw bytes are zeroed when the function returns. The raw picture never touches the disk.
  5. Publish. The stylised latest.png and the venue's index.html are written to /var/lib/guzva/public/<venue>/ atomically (write to a temp file, then rename), so a guest never sees half a file.
  6. Serve. A guest opening guzva.ba/<venue>/ gets the pre-rendered page. With JavaScript it fetches only the new picture every 30 s.
  7. Age out. Older renders are kept in a 48-hour ring under venues/, then pruned every hour.

If a picture is bad or the camera goes quiet, the page keeps the last good picture and says STALE. It never shows garbage and never pretends an old picture is live.

The contracts (PLAN §1)

These hold for every change. Breaking one is a bug even if all tests pass.

  • Freshness: the server's receive time is the truth; the camera's clock is only a hint.
  • Idempotency: UNIQUE(venue_id, capture_id); a retry returns the same answer.
  • Never publish a failure: keep the last good picture and show STALE.
  • Privacy: raw JPEG only in RAM inside one call; stylised renders only at rest, on public routes and in logs; request bodies are never logged. Proven by tests and a disk scan in CI.
  • No biometrics (decision D9): no face detection, no person counting from faces.
  • Push only: the server never connects to a camera, so it can't be tricked into calling something inside a venue's network.

The code, by package

PackageJob
cmd/guzvamain: flags, wiring, the serve, provision and hashpw commands
internal/storeAll SQL lives here, with embedded migrations tracked by PRAGMA user_version
internal/framesIngest: checks, save, prune, disk space
internal/renderThe picture pipeline (raw JPEG in, stylised PNG out)
internal/pagesWrites the public pages to disk
internal/adminAdmin and owner consoles (this page too)
internal/authDevice tokens, sessions, rate limits
internal/alertAlert rules and the Telegram sender
internal/schedThe one timer loop that runs background jobs
internal/privacyTests that prove the privacy contract
internal/handbookThis handbook

Dependencies only point downward: store knows nothing about admin, so each package can be tested alone.