- C 88.7%
- HTML 7.8%
- CSS 2.2%
- JavaScript 0.7%
- Makefile 0.3%
- Other 0.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Deletes the Django app and moves the C code from c/ to the repository root. CI tests and builds from the root; the image name, Portainer stack and data volume are unchanged. The Python-generated reference values in tests/fixtures/vectors.json stay, keeping data from the old version readable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
| .forgejo/workflows | ||
| assets | ||
| src | ||
| tests | ||
| third_party | ||
| tools | ||
| .dockerignore | ||
| .gitignore | ||
| docker-compose.portainer.yml | ||
| docker-compose.yml | ||
| Dockerfile | ||
| Makefile | ||
| README.md | ||
StreamerFinance
Simple bookkeeping for a streaming / YouTube channel: log what comes in (YouTube, Patreon, Kick, PayPal donations, …) and what goes out (hardware, software, editors), and see where you stand.
- Dashboard – income after fees, expenses, profit; income by platform, expenses by category, last 12 months.
- Add income – platform, gross amount and fees taken, so you see what you actually received and what the platforms cost you.
- Add expense – category, vendor, amount, optional receipt photo/PDF. "Duplicate" re-uses an entry for monthly bills (editor, subscriptions).
- Transactions – search/filter everything, download as CSV.
- Year summary – category × month grid for tax time, plus a CSV of the year.
- Import – upload a PayPal or Patreon CSV export (or any CSV with a date and an amount), review every row, then import. See below.
- Scan receipt – upload a screenshot (e.g. an Amazon order on your phone), a photo of a receipt, or a PDF invoice. Claude reads it and pre-fills the expense; you check and correct it before anything is saved. Needs a Claude API key (below).
- Single sign-on – optional "Sign in with Authentik" (OIDC). See below.
- Backups – nightly encrypted Borg backups to a remote server. See below.
- Admin & settings (account menu) – business name, currency, categories, platforms and users. Categories/platforms can be renamed, reordered or deactivated without losing history.
Importing CSVs
Import in the top bar. Pick the platform, upload its export, review, import.
- PayPal: Activity → Statements → Activity report → Balance affecting, CSV. Donations become income (PayPal's fee recorded as a fee); payments you sent (e.g. to an editor) become expenses. Withdrawals, transfers, holds, pending and other-currency rows are skipped by default, and each row says why.
- Patreon: Creator dashboard → Income → Payouts → Documents. Per-patron exports can be combined into one income entry per month on the review page.
- Anything else: the first upload of a new file layout asks you to match columns (date, amount, fees, …). The mapping is remembered by header row, so the next file skips straight to review. Saved mappings are under Admin → Import profiles.
- Duplicates: every imported row is fingerprinted (by transaction ID when the file has one), so overlapping exports only bring in new rows.
- Undo: Import → Past imports → Undo deletes everything one upload created.
Receipt scanning
Two scanners, set up under Admin & settings → Settings. Configure either or both; with both, the scan page lets you pick per upload and the review page can re-read the same image with the other one, which is handy for comparing.
| Claude API | Ollama (local) | |
|---|---|---|
| Setup | API key from platform.claude.com | Server URL + a vision model, e.g. ollama pull qwen3-vl:30b |
| Model | claude-opus-5-5 |
whatever you configure |
| Image leaves your network | yes (Anthropic's API) | no |
| PDFs | yes | no (screenshot the invoice) |
| Cost | per-token API billing | free |
- Saving the Ollama settings checks the server is reachable and the model
lists
visionin its capabilities (a text-only model likeqwen3-coderis rejected). - The API key is stored encrypted with a key derived from
secret.key; if that file is lost, enter the key again. - Both scanners share one prompt and one JSON schema. Claude uses structured
outputs plus server-side fallback (a rare safety-classifier false positive
retries on another model); Ollama uses its
formatschema, and answers are normalised either way. - The review page flags things to check: a different currency, no total found, "doesn't look like a receipt", and existing expenses with the same amount within a week (possible duplicates).
- The uploaded file becomes the expense's receipt. Unsaved scans are deleted after a day. Admin → Receipt scans lists each scan's scanner, model, time taken and token counts, for comparing.
- iPhone HEIC photos aren't supported; screenshots (PNG) and JPEG photos are.
- A local model may take a minute to load on its first scan; requests may take up to 5 minutes.
Running it
docker compose up -d
Open http://localhost:8080. The first visit asks you to create the owner account. Add more people under Admin & settings → Users.
Everything lives in the streamerfinance-data volume: the SQLite database,
uploaded receipts and secret.key. Back up the whole volume.
Environment variables are container wiring only (see docker-compose.yml):
| Variable | Purpose |
|---|---|
STREAMERFINANCE_PORT |
Host port (default 8080) |
STREAMERFINANCE_INSECURE_COOKIES |
true when reached over plain HTTP. Set false behind an HTTPS reverse proxy. |
STREAMERFINANCE_TRUSTED_ORIGINS |
Only if the proxy rewrites the Host header, e.g. https://finance.example.com |
Behind a reverse proxy, forward Host and X-Forwarded-Proto.
Single sign-on (Authentik)
Sign in with Authentik (or any OpenID Connect provider) alongside passwords.
- In Authentik, create an OAuth2/OpenID Provider: client type
Confidential, a Signing Key selected (e.g. the self-signed
certificate), and a strict redirect URI of
https://<your-host>/login/sso/callback/. The exact URI is shown in the app under Admin & settings → Settings → Single sign-on. - Create an Application using that provider. Bind a policy/group to it to control who may use it.
- In the app, Admin & settings → Settings → Single sign-on: paste the provider's OpenID Configuration Issuer URL, client ID and client secret. Saving checks the issuer is reachable. The secret is stored encrypted.
- Each person signs in with their password once and connects Authentik from the account menu → Single sign-on. After that, Sign in with Authentik on the sign-in page works for them.
Accounts are matched by Authentik's permanent user ID, never by email: Authentik lets people change their own email by default, so matching on it would let anyone who sets their email to yours sign in as you. If you'd rather have accounts created automatically, turn on Create accounts on first SSO sign-in (new accounts are regular, non-admin users; restrict who gets in with the Authentik application's policy bindings). SSO-created accounts can set a password later from the account menu.
The redirect URI is built from the request, so behind a reverse proxy the
proxy must pass Host and X-Forwarded-Proto: https.
Backups (Borg)
Account menu → Backups (staff only). Encrypted, deduplicated, incremental backups to any Borg repository over SSH (your own server, BorgBase, rsync.net, Hetzner Storage Box).
- Enter the repository, e.g.
ssh://borg@backup.example.com:22/./streamerfinance. - Generate a passphrase and store a copy somewhere else (password manager). The backups can't be read without it.
- Generate an SSH key and add the public key line to
~/.ssh/authorized_keyson the backup server (or your provider's key list). - Create repository (once, for a new repository), then Test connection.
- Turn on the daily schedule and pick the hour (shown in your local time, stored in UTC), and set retention (default 7 daily, 4 weekly, 12 monthly).
Each archive holds a consistent snapshot of the database (taken with SQLite's
backup API while the app keeps running, so no downtime), the uploads/
folder (receipts and imports) and secret.key (which decrypts the stored API
keys and passphrase). The server's SSH host key is trusted on first connection
and checked on every later one; the SSH key and passphrase are stored
encrypted and only ever written to disk in a temporary folder during a run.
The app runs the schedule itself: every five minutes it checks whether
today's backup is due. docker exec streamerfinance /app/streamerfinance backup
runs one by hand.
Restoring from Borg
On any machine with borg installed:
export BORG_PASSPHRASE='the passphrase'
borg list ssh://borg@backup.example.com:22/./streamerfinance
mkdir restore && cd restore
borg extract ssh://borg@backup.example.com:22/./streamerfinance::streamerfinance-20261001T090000Z-42
Then put it into the app's data volume, with the app stopped:
docker stop streamerfinance
docker run --rm -v streamerfinance-data:/data -v "$PWD":/restore alpine sh -c '
rm -f /data/streamerfinance.db-wal /data/streamerfinance.db-shm
cp /restore/snapshot/streamerfinance.db /data/streamerfinance.db
cp /restore/secret.key /data/secret.key
rm -rf /data/uploads && cp -a /restore/uploads /data/uploads
chown -R 1000 /data'
docker start streamerfinance
(In Portainer the volume is named after the stack, e.g.
streamerfinance_streamerfinance-data; docker volume ls shows it.)
Deployment (Portainer)
Pushes to main run .forgejo/workflows/build-deploy.yml: tests, then build and
push git.thenymans.com/brian/streamerfinance:latest (and :<sha>), then
redeploy the Portainer stack named streamerfinance from
docker-compose.portainer.yml. Changes to *.md files alone don't trigger it;
Actions → Build and Deploy → Run workflow runs it by hand.
One-time setup:
- In the Forgejo repo, Settings → Actions → Secrets: add
REGISTRY_USER,REGISTRY_PASSWORD(token withwrite:package) andPORTAINER_TOKEN(same values as the other projects). - Push once so the image exists in the registry (the deploy step will fail on this first run because the stack doesn't exist yet; that's expected).
- In Portainer, Stacks → Add stack → Web editor, name it
streamerfinance, pastedocker-compose.portainer.yml, and deploy. - Open
http://<host>:8093and create the owner account.
From then on every push to main deploys itself. The published port defaults
to 8093; override it with a STREAMERFINANCE_PORT variable on the stack.
Behind an HTTPS reverse proxy, also set STREAMERFINANCE_INSECURE_COOKIES=false.
Stack variables set in Portainer are kept on every deploy.
Building and testing
C (gnu11) with libmicrohttpd, libcurl, OpenSSL 3, SQLite, jansson, zlib and
libwebp; the stb image headers are vendored in third_party/. Templates,
CSS/JS, the schema and the common-password list are compiled into the binary
from assets/.
docker build -t sf-c-dev -f tests/Dockerfile.dev tests # once
docker run --rm -v "$PWD":/src -w /src -u "$(id -u):$(id -g)" sf-c-dev make test
docker run --rm -v "$PWD":/src -w /src -u "$(id -u):$(id -g)" sf-c-dev \
sh -c 'make clean && make SANITIZE=1 test' # ASan + UBSan + leak checks
To run it locally, make then
STREAMERFINANCE_DATA_DIR=data STREAMERFINANCE_DEBUG=1 build/streamerfinance --port 8000
(local data goes in ./data/, git-ignored). Other commands:
build/streamerfinance migrate, backup [--scheduled | --run ID | --mark-interrupted],
changepassword USERNAME.
The tests run the whole request stack in-process with the network mocked
(Claude, Ollama, the OIDC provider), plus a real Borg backup into a local
repository. tests/fixtures/vectors.json holds reference values computed by
the original Python/Django version of this app (password hashes, Fernet
tokens, session cookies, CSV parsing and import fingerprints, money and date
parsing); they keep data written by either version readable by this one.
How it's built
Server-rendered pages, one small JS file, SQLite. The app started as a Django app and this C version kept its data formats: Django's database schema, PBKDF2 password hashes, signed database sessions, CSRF tokens and admin log, so a volume from the Python version runs unchanged.
src/web.c |
HTTP server and middleware: sessions, CSRF, auth, messages, first-run redirect, browser time zone, security headers, static files |
src/tpl.c |
a Django-template-compatible engine running the templates in assets/templates/ |
src/forms.c |
form rendering and validation, password validators |
src/views.c, auth_views.c, import_views.c, scan_views.c, sso.c, backup.c, admin.c |
the pages |
src/importers.c |
the CSV importer (rows → preview → dedupe) |
src/receipt_ai.c |
Claude and Ollama clients, image preparation |
src/crypto.c |
Fernet, PBKDF2, session signing, CSRF masking, JWT/JWK checks, SSH keys |
src/db.c, models.c, reports.c |
SQLite, settings, delete rules, dashboard and year-summary queries |
- Money is integer cents in the code and a decimal column in the database,
never float. Amounts are always positive;
kindsays which direction. - Time: timestamps are stored in UTC. The browser reports its timezone in a cookie so "today" and "this month" match the viewer, and timestamps are converted to local time in the browser. Transaction dates are plain calendar dates (the day the money moved).
- Receipts are served only to signed-in users, never as public files.
Growing later
The model is deliberately simple, but it leaves room to grow:
- More categories/platforms (sponsorships, merch, Twitch, Ko-fi, …): add them in the admin, no code needed.
- Merch / inventory: new tables and pages; sales can still post into
finance_transactionso the dashboard keeps working. - Direct API sync: YouTube (Analytics API, estimated revenue) and PayPal
(Transaction Search API) can be pulled automatically; the import pipeline in
src/importers.c(rows → preview → dedupe) is the place to feed them in. - Double-entry accounting: each
Categorybecomes an account and eachTransactionbecomes a pair of ledger lines (plus a fees line). Existing data migrates in one pass. - Sales tax / VAT, multiple currencies, bank reconciliation: add fields or
tables, with a schema step in
db_migrate(src/db.c).