Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

SpeisePlan

A fast, mobile-only weekly meal planner for a two-person household. Plan the week in one pass, minimal taps. Server-rendered Go + templ + SQLite + Datastar, shipped as a single self-contained binary.

Develop

Requires Nix with flakes enabled. The flake devshell pins the whole toolchain (Go, templ, sqlc, goose, just, sqlite).

With direnv (recommended) the shell loads automatically on cd, so just just works:

direnv allow       # one-time, loads the flake devshell via .envrc
just seed          # wipe + insert ~16 sample recipes (dev only)
just run           # generate templ + sqlc, build, and serve on :8080
just               # list all recipes

Without direnv, enter the devshell manually first (nix develop, then just run).

Open http://localhost:8080 — built and tuned for phone width (~440px).

Configuration

All optional, via environment variables:

Variable Default Purpose
SPEISEPLAN_ADDR :8080 Listen address.
SPEISEPLAN_DATA data Writable dir for speiseplan.db and uploaded photos/.
SPEISEPLAN_PUBLIC_URL (unset) Where a phone can reach this SpeisePlan, e.g. http://speiseplan.local:8080. Only used for the QR code below.
TZ (system) Sets the "today" boundary for the 7-day plan and pruning.

Migrations run automatically on startup, and past-dated staged meals are pruned.

There is no login

SpeisePlan authenticates nobody. Anyone who can reach it can read and change the plan, and the JSON API answers any request. That is deliberate: it is built to run as a Home Assistant add-on behind ingress, where Home Assistant does the authenticating and the add-on publishes no port at all.

Anywhere else, treat it like any other unauthenticated service: keep it on a trusted network or a tailnet, or put a reverse proxy in front and add basic auth there.

Home Assistant ingress

SpeisePlan works both at the root of a host and under a path prefix, with no configuration. Home Assistant serves add-ons from /api/hassio_ingress/<token>/, strips that prefix before the request arrives, and passes it back in an X-Ingress-Path header; SpeisePlan reflects it into a <base href> and emits every URL relative to it, so assets, links, photos and Datastar's own fetches all land in the right place. The token changes per session, which is why this is read per request rather than configured.

The JSON API is the exception: it keeps emitting root-anchored paths, because its consumer talks to the app directly rather than through ingress.

Upgrading from 1.x

Passkeys, the shared SPEISEPLAN_PASSWORD and the JSON API's bearer token are all gone; SPEISEPLAN_RP_ID, SPEISEPLAN_ORIGIN, SPEISEPLAN_RP_NAME, SPEISEPLAN_INSECURE_COOKIES and SPEISEPLAN_API_TOKEN are no longer read. The migration drops the accounts, passkeys and sessions tables; recipes, photos and plans are untouched. As an add-on, SpeisePlan now appears in the Home Assistant sidebar instead of on http://<host>:8080 — the port is no longer published.

JSON API

A small read-only API lets other software read the plan — most usefully the Home Assistant integration, which turns it into sensors and image entities for dashboards and e-paper displays.

The API needs no credentials — it answers any request, so keep this instance on a network you trust. This instance.s ID, which Home Assistant keys its device on, is shown on /settings.

Endpoint Returns
GET /api/v1/info {app, version, instance_id, timezone, utc_offset_seconds, today, days}
GET /api/v1/plan?days=N The planning window (N clamped to 1–14, default 7)
GET /api/v1/recipes/{id}/photo The recipe photo as image bytes, or a QR code when there is none (?size= in px, 64–2048, default 512)

The QR code stands in for a missing photo

A display showing tonight's meal has nothing to show when the recipe has no photo yet. Rather than 404, this endpoint answers with a QR code linking to that recipe — scan it and SpeisePlan opens on your phone at that recipe with the photo controls already unfolded, one tap from the camera. Upload the photo and the same URL starts serving it.

That link has to work from a phone, so it is built from SPEISEPLAN_PUBLIC_URL (the add-on's public_url option) — the app cannot know its own address, and a Home Assistant ingress URL carries a per-session token that would be stale by the time anyone scanned it. With the variable unset the endpoint 404s as before.

has_photo in the plan JSON says which of the two you are getting; photo_url is always present either way, so a renderer never needs a conditional.

/api/v1/plan always returns exactly N day entries, empty ones included, so callers can index by offset:

{
  "generated_at": "2026-09-12T18:03:11+02:00",
  "timezone": "Europe/Berlin",
  "today": "2026-09-12",
  "days": [
    {"offset": 0, "date": "2026-09-12", "weekday": "Friday", "meals": [
      {"id": 12, "recipe_id": 7, "name": "Lasagne", "minutes": 45, "tag": "pasta",
       "day": "2026-09-12", "url": "https://example.com/lasagne",
       "image": "/photos/7.webp?v=1757000000", "image_external": false,
       "has_photo": true, "photo_url": "/api/v1/recipes/7/photo",
       "updated_at": "2026-09-12T08:30:00Z"}
    ]}
  ],
  "unassigned": [],
  "meals": []
}

A day can hold more than one meal — there are no breakfast/lunch/dinner slots. unassigned holds meals staged without a day yet, and meals is every assigned meal flat and ordered.

/api/v1/recipes/{id}/photo serves locally stored and externally hosted photos alike: external URLs are fetched server-side (scheme allowlist, image/* only, 5 MB cap, 10s timeout), so clients never have to classify image themselves and the token never reaches a third-party host.

The API is read-only: it exposes no way to change the plan.

The instance ID lives in speiseplan.db, and a backup carries it along — restore one and Home Assistant keeps talking to the same device. Point it at a database that never belonged to this instance (a hand-copied file, a fresh install) and the ID differs, so Home Assistant treats it as a new device.

Backup and restore

Settings → Backup hands you one zip holding everything that lives outside the binary: the database and every uploaded photo, plus a backup.json naming the version, schema and instance ID it came from. The database inside is written with VACUUM INTO, so it is a consistent snapshot with the write-ahead log already folded in — safe to take while the plan is in use, and complete in a way that copying speiseplan.db out from under a running SpeisePlan is not.

Settings → Restore takes one back. It replaces everything: recipes, ingredients, the planned week, the photos and the instance ID. There is no merge, and nothing that was here before survives — hence the typed confirmation. A backup from an older SpeisePlan is migrated on the way in, so a 1.x archive restores onto 2.x without any manual step; one from a newer SpeisePlan is refused rather than half-understood.

Nothing is swapped under the running process. The archive's database is unpacked beside the live one, migrated and integrity-checked there, and only then copied in through a single ATTACH transaction; the photos follow with one directory rename. A restore that fails at any point leaves the existing data exactly as it was, and no restart is needed after one that succeeds.

curl -OJ http://localhost:8080/backup                      # same archive the button gives you
curl -F archive=@speiseplan-backup-2026-09-14.zip \
     -F confirm=RESTORE http://localhost:8080/restore      # and the way back

Both endpoints are as unauthenticated as everything else here — see there is no login. Behind Home Assistant ingress that is Home Assistant's business; on a published port, anyone who can reach it can already rewrite the plan a recipe at a time, and restore only makes that quicker. If that matters on your network, put a reverse proxy in front and add basic auth there.

Build & deploy

Everything except the SQLite db and uploaded photos is embedded in the binary (static assets, fonts, templates), so deployment is one file plus a data dir.

just build                       # -> ./speiseplan
# or a fully static cross build:
CGO_ENABLED=0 go build -o speiseplan ./cmd/speiseplan

Copy speiseplan to an always-on machine (home server / mini PC) and run it:

SPEISEPLAN_DATA=/var/lib/speiseplan ./speiseplan

It responds to SIGINT/SIGTERM with a graceful shutdown. speiseplan version prints the build.

Releases & self-update (bare-binary deploys)

Releases are cut with GoReleaser on a tag push: the release GitHub Actions workflow builds linux/darwin × amd64/arm64 binaries and publishes a GitHub release. Each binary bakes in its version and owner/repo (from GITHUB_REPOSITORY), so a versioned build auto-updates on startup from GitHub releases and re-execs the new binary.

git tag v1.3.0 && git push --tags     # -> Actions builds + publishes the release
goreleaser check                       # validate .goreleaser.yaml locally
goreleaser release --snapshot --clean  # local dry-run build

At runtime, SPEISEPLAN_UPDATE_REPO overrides the baked repo, SPEISEPLAN_UPDATE_TOKEN authenticates (private repos / rate limits), SPEISEPLAN_UPDATE_HOST targets GitHub Enterprise, and SPEISEPLAN_UPDATE=off disables updates. Updating is best-effort — a failed check just logs and keeps the current version running. The Docker image is a dev build and does not self-update (update it via image pulls).

Run as a systemd service

The bare binary runs cleanly under systemd. Keep the binary and data under one writable dir (/var/lib/speiseplan) so auto self-update can rewrite it in place; the re-exec after an update keeps the same PID, so systemd isn't disturbed.

# 1. dedicated user + dir
sudo useradd --system --home /var/lib/speiseplan --shell /usr/sbin/nologin speiseplan
sudo mkdir -p /var/lib/speiseplan/data
sudo chown -R speiseplan:speiseplan /var/lib/speiseplan

# 2. get the binary (self-update needs a versioned RELEASE build, not a dev build).
#    Download the latest release for this machine from GitHub:
REPO=ajfriesen/SpeisePlan
TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | head -1 | cut -d'"' -f4)
ARCH=$(uname -m); [ "$ARCH" = x86_64 ] && ARCH=amd64; [ "$ARCH" = aarch64 ] && ARCH=arm64
curl -fsSL "https://github.com/$REPO/releases/download/$TAG/speiseplan_${TAG#v}_linux_$ARCH.tar.gz" | tar xz
#    (or build it yourself in the repo: `just build` -> ./speiseplan; this is a
#     "dev" build that won't self-update)

# install it where the service user can rewrite it (so self-update works)
sudo install -o speiseplan -g speiseplan -m 0755 speiseplan /var/lib/speiseplan/speiseplan

# 3. config (root-owned secret); start from example.env, drop the Docker-only
#    keys (SPEISEPLAN_PORT / PUID / PGID). SPEISEPLAN_DATA is set by the unit.
sudo install -m 0600 example.env /etc/speiseplan.env
sudo editor /etc/speiseplan.env        # set USERS, UPDATE_REPO, TZ…

# 4. unit + start
sudo cp deploy/speiseplan.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now speiseplan
journalctl -u speiseplan -f

The example unit (deploy/speiseplan.service) runs as the speiseplan user with ProtectSystem=strict and ReadWritePaths=/var/lib/speiseplan. Put it behind your TLS-terminating reverse proxy (proxy → 127.0.0.1:8080); set SPEISEPLAN_ADDR=127.0.0.1:8080 in the env file to bind only locally.

Docker

cp example.env .env       # edit TZ / PUID+PGID
mkdir -p data             # bind-mounted at /data, owned by your user
docker compose build
docker compose up -d      # serves on http://<host>:${SPEISEPLAN_PORT}

Import a Mealie export (see below) into the same data volume:

docker compose run --rm import -wipe   # from ./recipes (unpacked export)

Reachable from both phones (Tailscale)

The two of you don't edit at the same time, so v1 needs no live sync — it just needs to be reachable. Simplest path:

  1. Install Tailscale on the server and both phones.
  2. Run SpeisePlan on the server (binary or docker compose up -d).
  3. From a phone on the tailnet, open http://<server-tailscale-name>:8080.
  4. Add to Home Screen — the web app manifest + icons make it launch full-screen like a native app.

No public internet exposure required. SpeisePlan has no login of its own, so everyone on the tailnet can use it — which is usually the point.

Import from Mealie

Export your Mealie recipes and unpack them into recipes/ (each recipe as recipes/<slug>/<slug>.json, with optional <slug>/images/). Then:

just import -- -wipe      # imports recipes/ into ./data, clearing any sample seed first

-wipe starts from a clean slate; without it, re-runs skip recipes whose name already exists. Ingredients, method, source URL, cook time (best-effort, incl. German), the first category/tag, and photos are all mapped over.

Status

Complete: plan/week views, tap-to-stage (scroll-safe), day assignment, recipe detail (edit + ingredients + method), photos (URL or upload), Mealie import, backup/restore, and a deployable single binary / Docker image. See mise-build-plan.md for the original spec and the documented v1 non-goals (live cross-device sync, shopping list).

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages