Skip to content

Latest commit

 

History

History
225 lines (184 loc) · 14.4 KB

stack.md

File metadata and controls

225 lines (184 loc) · 14.4 KB

CARE Anywhere: the stack and how it runs on each OS

CARE Anywhere packages CARE as a download-and-run app for Linux, macOS and Windows, without Docker. Each OS gets its own build. Everything CARE needs ships inside the download, and one launcher starts it.

Status markers below:

  • Verified: built and checked by CI on Linux, macOS and Windows.
  • Open: a known gap.

What runs

The user starts the launcher, a desktop app (CARE Anywhere.app on macOS, care-anywhere.exe on Windows, care-anywhere on Linux). Its window shows the status dashboard while it starts CARE's services; Open CARE opens CARE in the user's browser. The window can be minimized like any other; CARE keeps running. Closing it, or Stop CARE, stops CARE. With -headless there is no window, and the dashboard is at http://127.0.0.1:27099.

By default everything listens only on 127.0.0.1. When the user sets a network name (see below), the web app and file storage also listen on the local network.

flowchart LR
    browser[Browser] -->|:27100| web[CARE web app<br/>in the launcher]
    web -->|/api, /admin, /health| api[CARE API<br/>Django + Waitress]
    browser -->|presigned uploads :27104| s3[File storage<br/>in the launcher]
    api --> pg[(Postgres :27102)]
    api --> redis[(Cache + task queue<br/>in the launcher :27103)]
    api --> s3
    worker[Celery worker] --> redis
    beat[Celery beat] --> redis
    worker --> pg
    dash[Dashboard :27099] -.-> launcher[Launcher]
    launcher -. starts and stops .-> pg & api & worker & beat
Loading
Part What it is Runs as
Launcher Go program (launcher/), one binary per OS; its window uses the OS's web view (webview_go: WebKit on macOS, WebView2 on Windows, WebKitGTK on Linux) The program the user starts
Dashboard Status of every service, logs, sign-in details, Stop button; CARE's palette, font and logo Inside the launcher, port 27099, shown in its window
CARE web app care_fe built once into static files; the launcher serves them and forwards /api, /admin, /staticfiles and /health to Django, so the browser sees one address Inside the launcher, port 27100
Cache and task queue Redis-compatible server (miniredis) Inside the launcher, port 27103
File storage S3-compatible server (gofakes3), files kept in the data folder Inside the launcher, port 27104
Database PostgreSQL 17.5: theseus-rs builds on macOS and Windows; on Linux the server from zonky (self-contained) plus theseus' pg_dump/pg_restore Separate process, port 27102
CARE API Core at patches/core/REVISION plus patches/core/, served by Waitress Python process, port 27101
Background tasks Celery worker, --pool=solo Python process
Scheduled tasks Celery beat Python process
Python python-build-standalone 3.13 via uv, with dependencies in app/site-packages, precompiled at build time Used by the three Python processes
Network name <name>.local over mDNS: macOS's own mDNSResponder (through dns-sd -P) on macOS, an mDNS responder (pion/mdns) inside the launcher elsewhere When set
Backups pg_dump plus uploaded files and keys, zipped daily Inside the launcher
PDF engine care_fullbleed_pdf plugin instead of WeasyPrint Inside the CARE API and worker

Running the cache, task queue, file storage and web server inside the launcher means only Postgres and Python ship as separate programs.

How CARE is configured

The launcher passes settings to core as environment variables, so no core files are edited:

Setting Value
DJANGO_SETTINGS_MODULE config.settings.deployment, with SSL redirect off (local HTTP)
DATABASE_URL Bundled Postgres, postgres database, generated password
REDIS_URL, CELERY_BROKER_URL The launcher's Redis-compatible server
BUCKET_*, FILE_UPLOAD_BUCKET, FACILITY_S3_BUCKET The launcher's S3-compatible server
DJANGO_SECRET_KEY, JWKS_BASE64 Generated on first run, kept in secrets.json in the data folder
ADDITIONAL_PLUGS care_fullbleed_pdf
CSRF_TRUSTED_ORIGINS http://127.0.0.1:27100, http://localhost:27100, and http://<name>.local and http://<name>.local:27100 when a network name is set
BUCKET_EXTERNAL_ENDPOINT http://<name>.local:27104 when a network name is set, so other devices can use upload and download links
PYTHONDONTWRITEBYTECODE 1: nothing is written inside the app at runtime (it would break the macOS signature)

The web app gets its API address at runtime: the launcher serves /runtime-env.js (care_fe's runtime-configuration hook) pointing at the address the page was loaded from.

First run and every start

On first run the launcher:

  1. Creates the data folder and generates the secret key, signing keys, database password and admin password.
  2. Creates the database with initdb (password authentication, UTF-8, no Unix socket).

On every start it starts the cache, task queue and file storage; starts Postgres with pg_ctl; runs migrate, sync_permissions_roles, sync_valueset and creates the admin user if missing; then starts the CARE API, the Celery worker and beat, and finally the web app. Each step waits for the previous one to be healthy. Closing the window, the dashboard's Stop button or Ctrl+C stops them in reverse order.

Data folder:

Linux macOS Windows
~/.local/share/care-anywhere ~/Library/Application Support/CARE Anywhere %LOCALAPPDATA%\CARE Anywhere

It holds postgres/, files/, logs/, secrets.json, settings.json and the beat schedule. It lives outside the app folder, so a new version doesn't touch the data.

Network name and mDNS

The dashboard asks for a network name, such as clinic, until one is set. Saving it restarts CARE so that:

  • clinic.local is announced over mDNS with this computer's address, so phones, tablets and other computers on the same network can open http://clinic.local;
  • the web app listens on port 80 as well as 27100 when the OS allows it. Linux keeps ports below 1024 for root, and another web server may already hold 80; then the address is http://clinic.local:27100;
  • the web app and file storage (port 27104) listen on every network interface;
  • the dashboard, database, API, cache and task queue stay on 127.0.0.1.

File storage serves other devices only for requests with a valid, unexpired AWS Signature V4 presigned URL, which is what CARE's API hands to browsers for uploads and downloads. Programs on this computer are trusted, as they can read the data folder anyway. This computer only turns the network name off again.

On macOS the app's own multicast replies are blocked by Local Network privacy, so the name is announced by macOS's mDNSResponder (dns-sd -P) instead. The address is read when CARE starts: after the computer moves to another network, restart CARE Anywhere.

Not handled: Windows may ask once to allow the launcher through its firewall; networks that block multicast (some guest Wi-Fi) won't resolve .local names; there's no HTTPS.

Backups

The user picks a backup folder (the OS's folder picker, or a typed path), for example on a USB drive. Once a day while CARE is running, and on Back up now, the launcher writes one ZIP, encrypted with age as it's written (nothing unencrypted reaches the backup folder):

In the ZIP What
database.dump pg_dump -Fc of CARE's database, taken while CARE runs
files/ Uploaded files
secrets.json Keys and passwords of this install, needed to restore
README.txt Restore steps with the bundled pg_restore

Backups are named care-anywhere-backup-<date>-<time>.zip.age; the newest 14 are kept, counting unencrypted .zip backups from earlier versions, which aren't deleted otherwise.

  • Backup key. Each install generates an age post-quantum key (ML-KEM-768 + X25519, AGE-SECRET-KEY-PQ-1…) on first run, or on its first start after updating, and keeps it in secrets.json. The window shows it with Show and Copy, and asks the user to keep a copy away from the computer: without it the backups can't be opened.

  • What it protects. A lost or stolen USB drive or a shared backup folder. The key stays on this computer, which already holds the data unencrypted, so encryption adds nothing there.

  • Opening a backup. age -d -i key.txt -o backup.zip <backup>.zip.age with the standard age tool. HOW-TO-RESTORE.txt is written next to the backups with this and the restore steps.

  • Restoring is in the window: Restore from a backup takes a backup file and its key (empty means this computer's key), and also accepts unencrypted .zip backups from earlier versions. The launcher:

    1. opens and unpacks the backup into restore/ in the data folder, taking only database.dump, secrets.json and files/, and only paths inside that folder;
    2. backs up the current data (to the backup folder, or backups/ in the data folder), and stops if that fails;
    3. stops CARE, starts only PostgreSQL, and restores the dump into a new database care_restore. If that fails, it's dropped and nothing has changed;
    4. renames postgres to care_replaced and care_restore to postgres in one transaction, swaps in the backup's files, and takes the backup's secrets.json (admin password, Django and sign-in keys), keeping this computer's database password;
    5. drops the replaced database and files, which are in the safety backup, and starts CARE, whose setup step migrates a backup from an older CARE.

    The log is logs/restore.log. README.txt in each backup still describes restoring by hand.

Per-OS differences

Linux macOS Windows
Download .tar.gz .dmg with CARE Anywhere.app .zip
Start ./care-anywhere CARE Anywhere.app care-anywhere.exe (windowed; child processes get no console windows)
Window needs WebKitGTK 4.1 Built in WebView2 runtime (built into Windows 11 and most Windows 10)
Postgres binaries zonky linux-amd64 zonky darwin-arm64v8 zonky windows-amd64
python-magic Core's wheel, includes libmagic Core's wheel, includes libmagic python-magic-bin 0.4.14 from PyPI, includes libmagic.dll
Stopping child processes Interrupt signal, then kill after 15 s Same Kill (Windows has no interrupt signal for child processes); Postgres stops via pg_ctl stop everywhere
Folder picker zenity or kdialog if installed, else type the path Finder (osascript) Windows folder dialog (PowerShell)
First-launch warning None Signed ad hoc, not notarized: blocked until Open Anyway or xattr -dr com.apple.quarantine SmartScreen warns about unsigned programs

Each OS's bundle is built on that OS by GitHub Actions, so nothing is cross-compiled.

Known problems

  • WeasyPrint needs Pango. Core imports WeasyPrint at startup, and WeasyPrint loads Pango when imported. A temporary core patch makes the import optional, and the fullbleed plugin renders PDFs. Verified. Upstream issue drafted in docs/issue-optional-weasyprint.md, not filed.
  • python-magic on Windows. Fixed by python-magic-bin (see above). Its libmagic dates from 2017, so a few file types may be detected differently than on Linux and macOS.
  • Translations. Core ships only .po files and its start scripts compile them with GNU gettext. The build compiles them with Babel instead, so no machine needs gettext.
  • psycopg. The bundle installs psycopg[binary] instead of core's psycopg[c]. Verified.
  • Cache and queue are in memory (open). The launcher's Redis-compatible server keeps nothing on disk: tasks still queued when CARE stops are lost, and the cache starts empty. Bundling Valkey or Redis would fix this at the cost of another binary per OS.
  • File storage trusts this computer. Requests from 127.0.0.1 aren't signature-checked; requests from other devices must carry a valid presigned signature.
  • Not notarized or signed by a publisher (open). The macOS app is signed ad hoc, so Gatekeeper still asks once; notarization needs an Apple Developer ID ($99 a year). Windows SmartScreen warns until the program is signed (Microsoft Trusted Signing, about $10 a month).
  • mDNS isn't tested in CI. GitHub's runner VMs don't deliver multicast, so the .local lookup test runs only on real machines (it passes on macOS; the app itself was checked on macOS 26). CI does check that the web app is reachable on the runner's network address and that file storage refuses unsigned requests.
  • PDF fonts on macOS and Windows (open). The fullbleed plugin looks for fonts in /usr/share/fonts and /usr/local/share/fonts, which exist only on Linux. Elsewhere PDFs use non-embedded base fonts that cannot show non-Latin text. Fix: ship fonts in the bundle and set FULLBLEED_FONT_DIRS.
  • Orphaned processes (open). If the launcher crashes, its child processes keep running. Postgres is reused on the next start; the other processes block their ports until killed.
  • Size. About 190–210 MB to download. Python dependencies are about 300 MB unpacked; Postgres is about 30 MB on macOS, more on Windows, and about 130 MB on Linux (zonky's server).

Building

.github/workflows/build.yml runs on every push:

  1. frontend (Linux): scripts/build-frontend.sh builds care_fe at frontend/REVISION. The bundle jobs also run the launcher's Go tests (signature checks, names, mDNS).
  2. bundle (Linux, macOS, Windows): scripts/build-bundle.sh assembles the bundle, then scripts/smoke-test.sh starts it with a fresh data folder, waits for every service, checks the web app, API health, admin sign-in and the Celery worker; makes a backup and checks the ZIP; sets a network name and checks the web app on the runner's network address and that file storage refuses unsigned requests; takes screenshots and stops it. scripts/window-screenshot.sh then opens the launcher window and captures it.
  3. release (pushes to main): replaces the nightly pre-release with the three bundles.

.github/workflows/check.yml separately checks PDF rendering without WeasyPrint.