No description
  • Rust 70.9%
  • TypeScript 23.9%
  • CSS 3.1%
  • Python 1.6%
  • Dockerfile 0.3%
  • Other 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Brian 0dbf3fa5aa
All checks were successful
Build and Deploy / test-frontend (push) Successful in 14s
Build and Deploy / test-backend (push) Successful in 2m15s
Build and Deploy / build (push) Successful in 1m35s
Build and Deploy / deploy (push) Successful in 9s
Rebuild the backend in Rust as a drop-in replacement
The FastAPI service is replaced by an axum + sqlx server with the same
routes, the same JSON byte for byte, the same validation messages and the
same schema. Migrations keep Alembic's alembic_version table and revision
ids, so an existing database is picked up as-is. Session cookies stay
itsdangerous-compatible and passwords stay argon2-cffi hashes, so nobody is
signed out by the upgrade.

Two old bugs are fixed rather than copied: reassigning a job now returns
the new assignee, and backfill audit entries record the real count instead
of -1.

The pytest suite is ported to Rust (unit tests plus HTTP tests against a
real server per test). CI runs fmt, clippy and cargo test against Postgres,
and the image build now uses buildx with a registry layer cache so the Rust
dependencies are not recompiled on every push. The deploy step also gets
the fixes from medsync's pipeline: a failed stack lookup reports
Portainer's error instead of "no such stack", and docs-only pushes skip CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 15:28:00 -06:00
.forgejo/workflows Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
docker Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
scripts Worklog: recurring job tracking with two-way expense settlement 2026-08-03 12:07:09 -06:00
src Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
tests/api Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
web Trade the front page's Late list for a week of what got done 2026-09-04 10:50:15 -06:00
.dockerignore Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
.env.example Worklog: recurring job tracking with two-way expense settlement 2026-08-03 12:07:09 -06:00
.gitignore Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
Cargo.lock Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
Cargo.toml Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
docker-compose.portainer.yml Publish the Portainer stack on 8079 2026-08-03 14:32:15 -06:00
docker-compose.yml Worklog: recurring job tracking with two-way expense settlement 2026-08-03 12:07:09 -06:00
Dockerfile Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
README.md Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00
rustfmt.toml Rebuild the backend in Rust as a drop-in replacement 2026-10-03 15:28:00 -06:00

Worklog

A shared account book for two people. A manager schedules work — one-off or recurring — and a worker logs when it actually got done. Alongside that, money moves in both directions: the worker fronts expenses to be reimbursed, and the manager bills the worker for things like rent. Either side can be applied against the other, so this month's reimbursement can come off next month's rent without anyone keeping a running total in their head.

Both roles see the same ledger and the same reports, and either can export a filtered period to a spreadsheet. The manager can also put documents on a shared shelf — a contract, a policy — for the worker to read.

Built for a phone, installable to the home screen, deployed as a Portainer stack.


What it does

Work

  • Jobs that happen once, or daily / weekly / monthly / quarterly / yearly, with intervals ("every other Tuesday") and month-day anchors ("the last day").
  • Month-end clamps rather than skips: a job anchored on the 31st falls on 28 February, it does not vanish from short months.
  • A worker's Today screen shows what is late, what is due, and what is done, with one-tap completion, optional time and notes, and backdating.
  • Work that was never on the schedule can be logged too, so reports stay honest.

Money

  • Entries in two directions: owed to worker (reimbursements) and owed by worker (charges). Recurring charges like rent bill themselves on the day they fall due, never in advance.
  • The manager records payments with the method, the date, and a note.
  • Offsets apply one balance against the other. Both sides move together as a linked pair, and reversing one reverses both.
  • Receipts can be photographed straight from the phone.

Documents

  • The manager uploads a contract, a policy, a site map; everyone signed in can read it. Reading is open, uploading is not.
  • PDFs and photos open in a tab, with a Save a copy alongside. Anything a browser would not render is sent as a download.
  • What lands on disk is a server-generated name with an extension taken from the accepted type, never from the filename the browser sent.

Reports

  • Filter by date range, job, person, and direction.
  • Export to .xlsx (multi-sheet: completed work, outstanding work, expenses, payments) or .csv.
  • Every timestamp is written in the reader's own timezone and in UTC.

Admin

  • The first account created is automatically the administrator; it then creates everyone else.
  • Every create, change and delete is recorded in an activity log, including who did it and from where. Password hashes and secrets are redacted.
  • All settings live in the database behind the admin login — see below.

Configuration

There is deliberately almost nothing to configure by environment variable. Currency, timezone, schedule horizon, overdue grace, SMTP and session lifetime are all edited in the app under Admin → Settings, stored in the database, and take effect immediately without a redeploy.

The environment carries only what is needed to reach the database:

Variable Required Purpose
POSTGRES_PASSWORD yes Used between the app and its own database. Any long random string.
APP_PORT no Host port to publish. Default 8079. Drop it when using a reverse proxy network.
INSECURE_COOKIES no true only when reaching the app over plain HTTP. Drops the Secure flag from the session cookie. Leave false behind HTTPS.

The session signing key is generated on first start and stored in the database, so there is no secret to invent, paste, or lose.


Deploying with Portainer

CI builds the image and redeploys the stack on every push to master, so day-to-day updating is just a push. The stack is created by hand once.

One-time setup

  1. In Portainer: Stacks → Add stack, name it worklog (the deploy job finds it by that name), build method Web editor.
  2. Paste in docker-compose.portainer.yml from this repository.
  3. Under Environment variables, add:
    • POSTGRES_PASSWORD — letters and digits only. It is interpolated into a connection URL, where @ : / would break parsing.
    • APP_PORT — e.g. 8079 (8080 is already in use on this host)
    • INSECURE_COOKIES — true only if you reach it over plain HTTP
  4. Deploy the stack.

Then add these secrets to the repository in Forgejo (Settings → Actions → Secrets):

Secret What it is
REGISTRY_USER Forgejo username, for pushing and pulling the image
REGISTRY_PASSWORD A Forgejo token with package read/write
PORTAINER_TOKEN A Portainer API key (My account → Access tokens)

First boot creates the schema. Open the app and the setup screen asks you to create the administrator account.

The pipeline

.forgejo/workflows/build-and-deploy.yml runs on every push to master:

  1. test-backend — cargo fmt, clippy, then cargo test against a real Postgres service container. The ledger and recurrence code lean on TIMESTAMPTZ, arrays and ON CONFLICT, so SQLite would not exercise them.
  2. test-frontend — npm ci && npm run build, to surface a TypeScript error as a TypeScript error rather than a buried Docker build failure.
  3. build — one image (React SPA compiled in stage 1, the Rust server in stage 2, both in a slim Debian runtime), tagged :latest and :<sha>, pushed to git.thenymans.com/brian/worklog. Built with buildx, whose layer cache lives in the registry as worklog:buildcache, so the Rust dependencies compile once rather than on every push.
  4. deploy — tells the Portainer host to pull the new image, then PUTs the stack. It finds the stack by name, and reuses the environment variables already stored on it, so passwords stay managed in the Portainer UI and are never pushed from CI.

The deploy job sends docker-compose.portainer.yml straight from the repository, so there is one copy of the compose file rather than a duplicate pasted into the workflow. Edit it here and the change ships on the next push.

It finds the stack by name and then reads the endpoint ID, the environment variables and the stack type off the stack itself, so there is nothing to keep in sync by hand. Both stack types work: a plain compose stack gets the file above pushed to it, and a git-backed stack is redeployed from the repository instead — for that one, set its compose path in Portainer to docker-compose.portainer.yml, since the default docker-compose.yml builds from source rather than pulling the image.

If Portainer refuses a deploy, the job prints its response body. A bare exitcode 22 means a curl -f swallowed the message, which this no longer does.

Deploying without CI

docker-compose.yml (as opposed to docker-compose.portainer.yml) builds from source instead of pulling the image. Point a Portainer Repository stack at it, or run docker compose up -d --build on the host.

Behind your existing reverse proxy

The stack publishes a port by default so it works out of the box. If something already terminates HTTPS on this host, switch to that instead:

  1. Create the shared network once, if you have not already: docker network create proxy
  2. In docker-compose.yml, uncomment the proxy network at the bottom and under app, then remove the ports: block from app.
  3. Point your proxy at app:8000 on that network.

Traefik — uncomment the labels: block on app and set your hostname.

Nginx Proxy Manager — add a proxy host with Forward Hostname app, Forward Port 8000, and NPM's container on the proxy network. Turn on Websockets Support; it is harmless here and avoids surprises later.

Caddy — worklog.example.com { reverse_proxy app:8000 }.

The app already trusts X-Forwarded-*, so client addresses appear correctly in the activity log. Leave INSECURE_COOKIES unset (false) once HTTPS is in front.


Backups

Everything worth keeping is in two volumes: pgdata (the database) and uploads (receipt photographs and shared documents).

# Database
docker compose exec -T db pg_dump -U worklog worklog | gzip > worklog-$(date +%F).sql.gz

# Receipts and documents
docker run --rm -v worklog_uploads:/data -v "$PWD":/backup alpine \
    tar czf /backup/worklog-uploads-$(date +%F).tar.gz -C /data .

Restore the database into a fresh stack with:

gunzip -c worklog-2026-08-03.sql.gz | docker compose exec -T db psql -U worklog worklog

Running it locally

cp .env.example .env          # set POSTGRES_PASSWORD, and INSECURE_COOKIES=true
docker compose up --build

Then open http://localhost:8080.

Development without Docker

docker run -d --name worklog-devdb -e POSTGRES_DB=worklog -e POSTGRES_USER=worklog \
    -e POSTGRES_PASSWORD=devpass -p 55432:5432 postgres:17-alpine

# fish: set -x DATABASE_URL ... ; bash: export DATABASE_URL=...
DATABASE_URL=postgresql://worklog:devpass@localhost:55432/worklog \
INSECURE_COOKIES=true \
    cargo run                                   # API on :8000, migrates on start

cd web && npm install && npm run dev            # UI on :5173, proxying /api

worklog migrate applies migrations and exits; worklog healthcheck is what the container's HEALTHCHECK runs.

To fill an instance with a realistic scenario (a plain HTTP client, so any Python with httpx will do):

uv run --with httpx scripts/demo_seed.py http://127.0.0.1:8000

Tests

cargo test

Unit tests (recurrence, validation, wire formats, password and cookie compatibility) need nothing. The HTTP tests in tests/api/ start a real server per test, each on its own database cloned from a migrated template, so they need the dev Postgres above. They default to postgresql://worklog:devpass@localhost:55432/postgres; point TEST_DATABASE_URL elsewhere if yours differs. Databases they create are named worklog_test_* and dropped afterwards.


How it is put together

The server is Rust (axum, sqlx, Postgres). It replaced an earlier FastAPI implementation as a drop-in: same routes, same JSON byte for byte, same validation messages, same schema, and sessions and passwords carry over.

src/
  main.rs         serve | migrate | healthcheck
  api/            route modules, one per area
  models.rs       table rows, and their audit snapshots
  validate.rs     request validation, worded as before
  recurrence.rs   schedule expansion; the clamping rules live here
  scheduling.rs   materialises rules into task and expense rows
  ledger.rs       all balance arithmetic, in exact decimals
  export.rs       xlsx and csv writers
  audit.rs        the activity log
  settings.rs     database-backed configuration
  security.rs     argon2 hashing and signed session cookies
  migrate.rs      schema migrations, tracked in alembic_version
  context.rs      one request's transaction, actor and session
tests/api/        HTTP tests against a real server and database
web/              React + TypeScript SPA, built into the image

A few decisions worth knowing about:

  • Task occurrences are materialised, not computed. Recurrence rules are expanded into real rows across a rolling horizon, so filtering, reporting and export are ordinary SQL. Editing a schedule re-syncs future dates but never removes an occurrence that has work logged against it.
  • Recurring charges are not generated ahead. A rent template only creates an expense once its date arrives; otherwise next quarter's rent would show up in today's balance as money already owed.
  • Completion is derived, never stored. A task is done because a work log points at it. There is no status column to drift out of step.
  • Offsets are pairs. Applying one balance to another writes a settlement on each side sharing an offset_group_id, so both balances move together and reversal is atomic.
  • The transaction commits before the response is sent, so a client that reads back its own write straight away always sees it. A refused request drops its transaction, taking any partial writes with it.
  • Migrations keep Alembic's bookkeeping. The schema was first built by Alembic, and alembic_version is still the record of where a database is. Each migration in src/migrate.rs carries its original revision id, so a database built by the Python service is picked up as-is. A new migration is appended with a fresh id and the previous head as its down.
  • Sessions and passwords are wire-compatible with the old service. Hashes are argon2id with argon2-cffi's parameters and cookies are itsdangerous tokens, so the upgrade signed nobody out.
  • A document is deleted, not deactivated. Jobs and expenses are retired rather than removed because work logs and settlements point at them; nothing points at a document, so there is no history for a soft delete to protect. The activity log keeps the record of what was removed and by whom.
  • Times are stored in UTC throughout, and converted for display using each user's own timezone — which also decides what "today" means on their agenda.