omarchy is gone, but the citadel deployment still set BTCDATA_URL=http://192.168.50.42:4102 and ran standalone on its own compose network. Every request that proxies to btcdata failed with httpx.ConnectError: All connection attempts failed. btcdata now runs on citadel too, so attach btcprice to the external btc-network there and reach it by service name at http://btcdata:4102. deploy-citadel.sh creates the network on the remote if missing, as btcdata's own deploy script already does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TRkiLhK5qhkZjP2adxpA3e
3.6 KiB
CLAUDE.md
Bitcoin price tracker UI — Python FastAPI web application. Serves the HTML/Tailwind UI and proxies live price data from btcdata over WebSocket.
Build & Development Commands
make run— Start dev server on port 4000; creates.venvand installsrequirements.txton first run (thevenvtarget, keyed offrequirements.txt)cp .env.example .env— optional;.envis-included, so a missing one is not fatalmake run-local— Same, but withBTCDATA_URL=$BTCDATA_LOCAL_URLmake tailwind— Watch Tailwind CSS for changesmake test— Runspytest tests/, but there is notests/directory yet and pytest is not inrequirements.txtmake venv— Bootstrap the virtualenv without starting the server
Docker
Docker runs alongside local dev on different ports:
| Service | Local dev | Docker |
|---|---|---|
| btcprice | localhost:4000 | localhost:4041 (container port 4040) |
| btcdata | localhost:4100 | localhost:4102 |
docker compose up -d here starts btcprice only. Both projects attach to the external
btc-network (docker network create btc-network once), and btcdata must be started from
../btcdata. Inside the network btcprice reaches it at http://btcdata:${DOCKER_BTCDATA_PORT:-4102}.
Note: Dockerfile bakes in a stale ENV BTCDATA_URL=http://btcdata:4101; compose always
overrides it, so it only matters if the image is run outside compose. ENV PORT is likewise
unused — the port in CMD is hardcoded.
Deployment
./deploy-citadel.sh — build locally for the remote's arch, docker save | ssh docker load,
docker compose up -d --no-build in /home/pmp/apps/btcprice on citadel (192.168.50.195).
Mirrors ../elprice/deploy-citadel.sh; no registry.
docker-compose.citadel.yml→ remotedocker-compose.yml;.env.citadel→ remote.env.- btcdata also runs on citadel, so both attach to the external
btc-networkthere andBTCDATA_URLishttp://btcdata:4102(service name, not a LAN address). The deploy script creates the network on the remote if it is missing. - Live at http://192.168.50.195:4041.
Architecture
- Framework: FastAPI
- Server: Uvicorn
- Templates: Inline HTML strings + HTMX (WebSocket extension)
- Styling: Tailwind CSS v4
- Data backend: btcdata (separate service at
BTCDATA_URL, defaulthttp://localhost:4100) - No database — all data comes from btcdata
btcdata connection
The browser connects only to btcprice: ws-connect="/ws/price" and ws-connect="/ws/strike".
Each endpoint runs _ws_proxy, which opens an upstream WebSocket to btcdata's /api/price/ws
and /api/strike/ws, converts each JSON message to an HTML fragment (price_json_to_html,
strike_json_to_html) and forwards it. BTCDATA_URL is the single point of contact;
_btcdata_ws_url rewrites its scheme to ws/wss.
Source Layout
btcprice acts as a WebSocket proxy between the browser and btcdata:
- Browser connects via HTMX WebSocket to
/ws/priceor/ws/strike - btcprice proxies to btcdata's
/api/price/wsor/api/strike/ws - JSON from btcdata is transformed into HTML fragments (in
price_json_to_html/strike_json_to_html) - HTMX swaps the HTML into the DOM by matching element IDs (
price-display,strike-display)
Key Conventions
- Numbers use Danish locale formatting (dots for thousands, commas for decimals) via
da_fmt() - Price changes are color-coded: green (up), red (down), gray (unchanged)
- All HTML is built as string concatenation in Python — no template engine