Update to fit stack

This commit is contained in:
2026-11-17 22:16:18 +01:00
parent 1366d6b69d
commit 950f22df70
10 changed files with 141 additions and 127 deletions
+55 -27
View File
@@ -1,9 +1,9 @@
# Finance: a self-hosted dashboard for ING, Revolut, investments, gold and debts
# Spendr: a self-hosted dashboard for ING, Revolut, investments, gold and debts
```
browser ──https──▶ Traefik ──forward-auth──▶ authentik (login, MFA)
browser ──https──▶ Traefik (existing) ──authentik@docker──▶ Authentik (existing, auth.dv3.app)
│
└──▶ finance (FastAPI) ──▶ Postgres
└──▶ spendr (FastAPI) ──▶ spendr-db (Postgres)
│
├─ Yahoo Finance (stocks/ETFs, gold spot, FX)
├─ CoinGecko (crypto)
@@ -23,30 +23,58 @@ browser ──https──▶ Traefik ──forward-auth──▶ authentik (logi
| **Joint account** | Give the ING shared account a "your share %" (e.g. 50) and its spending is scaled in the totals. |
| **Live numbers** | Every 30 s (and whenever you come back to the tab) the page fetches `/api/live`. Changed totals, prices and P/L count up or down and flash green or red, with no reload. *Refresh prices* runs in place. When new transactions arrive, a "new data · reload" hint appears so charts can be redrawn. |
| **Dark mode** | Auto (follows the system), Light or Dark toggle in the sidebar, remembered per browser. |
| **Mobile** | Desktop-first layout. On phones the sidebar turns into a scrolling top bar and tables scroll sideways. |
| **Mobile** | Desktop-first layout. On phones there's a bottom tab bar and a slide-out menu, and tables scroll sideways. |
## Setup
## Setup (DV3 server)
1. **DNS**: point `finance.home.lan` and `auth.home.lan` (or your own names) at the Docker host, e.g. in Pi-hole, AdGuard or your router.
2. **Configure**
This stack uses the Traefik and Authentik you already run. It only adds two containers: `spendr` and `spendr-db`.
```bash
mkdir -p ~/docker/spendr && cd ~/docker/spendr
# copy the contents of this folder here (compose.yaml, .env.example, app/, secrets/)
cp .env.example .env
nano .env # set SPENDR_DB_PASSWORD: openssl rand -base64 32 | tr -d '\n/+='
sudo docker compose up -d --build
```
- **DNS / TLS**: `spendr.dv3.app` gets its certificate from the existing `letsencrypt` resolver, like your other services.
- **Login**: the router uses `authentik@docker`. Your domain-level forward-auth provider (cookie domain `dv3.app`) protects it with no extra setup. Optional: create an Authentik application `spendr` and bind a policy or group if only certain users should get in.
- **Why forward auth and not OIDC**: the app has no login of its own, so forward auth is the right fit (see your conventions).
- **Sign out**: the sidebar button goes to `https://auth.dv3.app/outpost.goauthentik.io/sign_out` (set via `SIGN_OUT_URL` in `compose.yaml`).
- **Komodo / Gitea**: see *Deploy with Gitea + Komodo* below (recommended).
## Deploy with Gitea + Komodo (GitOps)
Same flow as YoteInvest: push to Gitea, then Komodo redeploys.
1. **Gitea**: create an empty repo `Mitchell/Spendr` on git.dv3.app (no README), then from the unzipped folder:
```bash
cp .env.example .env
# fill in hostnames + three secrets: openssl rand -base64 48 | tr -d '\n'
mkdir -p authentik/data authentik/certs authentik/custom-templates secrets
docker compose up -d --build
cd spendr
git init -b main && git add . && git commit -m "Spendr: initial version"
git remote add origin https://git.dv3.app/Mitchell/Spendr.git
git push -u origin main
```
3. **authentik first run**: open `https://auth.home.lan/if/flow/initial-setup/` and create the admin user. Turn on TOTP or a passkey for it, because this app holds your bank data.
4. **Protect the app in authentik** (Admin → Applications → *Create with provider*):
- Provider type: **Proxy Provider** → **Forward auth (single application)**
- External host: `https://finance.home.lan`
- Then go to **Outposts → authentik Embedded Outpost → edit** and add the application.
- Optional: bind a policy or group so only you (and your partner, if you like) can open it.
5. Open `https://finance.home.lan`. You should be sent to the authentik login and then back to the app.
`.gitignore` keeps `.env` and the Enable Banking key out of the repo.
2. **Secrets folder on the NUC** (only needed for Enable Banking):
```bash
sudo mkdir -p /etc/komodo/secrets/spendr
sudo cp enablebanking.pem /etc/komodo/secrets/spendr/ # later, once you have it
```
3. **Komodo → Stacks → New stack** `spendr`:
- Source: **Git Repo** → provider `git.dv3.app`, repo `Mitchell/Spendr`, branch `main`. The file is `compose.yaml`, so no File Paths needed.
- Turn on **Run Build** (the app image is built from `./app`), so a push also rebuilds the image.
- **Environment** (secrets live here, not in the repo):
```
SPENDR_DB_PASSWORD=<openssl rand -base64 32 | tr -d '\n/+='>
SECRETS_DIR=/etc/komodo/secrets/spendr
PG_VOLUME=spendr-db
EB_APP_ID=
```
- Deploy.
4. **Auto-deploy on push**: copy the stack's webhook URL (`/listener/github/...`). In Gitea, open repo → Settings → Webhooks → *Gitea*, choose JSON, set the secret to `KOMODO_WEBHOOK_SECRET`, and paste the URL.
5. Open `https://spendr.dv3.app`. Authentik asks you to log in, then you land on the dashboard.
### TLS
By default Traefik serves a self-signed certificate, so the browser shows a warning. You have two options:
- **mkcert** (LAN only): `mkcert "*.home.lan"`, save the files as `traefik/certs/local.crt` / `local.key`, then uncomment `traefik/dynamic/tls.yml`.
- **Let's Encrypt DNS challenge** (if you own a domain): uncomment the resolver in `traefik/traefik.yml` and set `CF_DNS_API_TOKEN` (or use another provider). This works even when the hosts are only reachable on your LAN.
`PG_VOLUME` pins the database volume name, so renaming or recreating the stack never orphans your data.
## Getting data in
@@ -57,19 +85,19 @@ By default Traefik serves a self-signed certificate, so the browser shows a warn
First go to **Settings → Accounts** and add the IBANs of all three accounts (Revolut's too). Transfers between them are then recognised, and the shared account gets its share %.
**Automatic sync (Enable Banking, free for your own accounts):**
1. Sign up at enablebanking.com → *Applications* → create one (Production). Set the redirect URL to `https://finance.home.lan/eb/callback`.
1. Sign up at enablebanking.com → *Applications* → create one (Production). Set the redirect URL to `https://spendr.dv3.app/eb/callback`.
2. Save the downloaded private key as `secrets/enablebanking.pem` and put the app id in `.env` → `EB_APP_ID`.
3. In their control panel, use **Link accounts** for ING and Revolut. Free "restricted mode" only returns accounts you linked there.
4. `docker compose up -d`, then go to Settings → *Connect* (ING / NL, then Revolut; Revolut may be listed under LT).
4. `sudo docker compose up -d`, then go to Settings → *Connect* (ING / NL, then Revolut; Revolut may be listed under LT).
5. The app syncs every `EB_SYNC_HOURS`. Bank consent (PSD2) expires after 90–180 days, so you'll need to click *Connect* again now and then. The expiry date is shown in Settings.
CSV and API imports share the same dedupe key (account + date + amount + n-th of that day), so you can mix them.
## Operations
- **Backup**: `docker compose exec finance-db pg_dump -U finance finance | gzip > finance-$(date +%F).sql.gz`. Back up `authentik-db` the same way.
- **Logs**: `docker compose logs -f finance`
- **Not exposed**: the app has no published port. It is only reachable through Traefik and authentik. Keep it that way.
- **Backup**: `sudo docker compose exec spendr-db pg_dump -U spendr spendr | gzip > spendr-$(date +%F).sql.gz`. Never run `docker compose down -v`, because it deletes the database volume.
- **Logs**: `sudo docker compose logs -f spendr`
- **Not exposed**: the app has no published port. It is only reachable through Traefik and Authentik. Keep it that way.
- Prices refresh every `PRICE_REFRESH_MINUTES`. Yahoo's endpoint is unofficial. If a ticker fails, the holding shows "price error" and you can set a manual price.
- The schema is created on start (`create_all`). Add Alembic if you start changing models.