4.1 KiB · text History 7f67051

recourse

A Rust web application: axum + htmx + minijinja, sea-orm on Postgres, and Argon2 session auth with invite-only registration, plus a RabbitMQ worker pipeline.

Front-end is server-rendered HTML with Tailwind + DaisyUI; htmx handles boosted navigation and live partial updates — no SPA build step.

Generated from the neiam-htmx cargo-generate template.

Stack

Concern Choice
HTTP axum 0.8
Hypermedia htmx (hx-boost, polling), axum-htmx
Templating minijinja (embedded at build time)
Database Postgres via sea-orm (UUIDv7 keys)
Migrations sea-orm-migration (auto-run on boot)
Auth Argon2 password hashing, cookie sessions, invite tokens
Background jobs RabbitMQ via lapin (competing-consumer workers)
Styling Tailwind CSS + DaisyUI + FontAwesome
Metrics Prometheus at /metrics

Binaries

  • webservice — the HTTP server.
  • queue-worker — background job consumer (run as many as you like).
  • registration-token — CLI to mint/list invite tokens (bootstrap the first user).

Quick start (local dev)

Prereqs: Rust, just, Node.js (for the asset build), and Docker/Podman (for Postgres + RabbitMQ).

# 1. Build front-end assets (CSS/JS/webfonts)
just deps
just assets

# 2. Start Postgres + RabbitMQ
just infra

# 3. Run the web server (auto-runs migrations on boot)
just serve                     # -> http://localhost:3999

# 4. In another terminal, run a worker
just worker

# 5. Mint an invite so you can register, then open the printed URL
just invite

Registration is invite-only by default. Set REGISTRATION_ENABLED=true to let anyone with a valid invite token self-serve, or keep it off and hand out links from the in-app Invites page.

The notes demo

/notes is a demo resource wired through the whole stack: creating a note writes a row, publishes a ProcessNote job to RabbitMQ, and the worker stamps processed_at. The note page polls a small htmx fragment until it flips from processing… to processed — no page reload.

Delete src/handlers/notes.rs, src/entities/notes.rs, src/workers/example.rs, the notes migration, and templates/notes/ when you start modelling your own domain.

Configuration

All via environment variables (defaults suit local compose.yml):

Variable Default Purpose
DATABASE_URL postgres://app_user:app_password@localhost:5433/app Postgres DSN
AMQP_URL amqp://app_user:app_password@localhost:5674/%2f RabbitMQ URL
BIND_ADDRESS 0.0.0.0:3999 Listen address
AUTO_MIGRATE true Run migrations on webservice boot
REGISTRATION_ENABLED false Allow public self-registration
SESSION_DURATION_HOURS 24 Session lifetime
REGISTRATION_TOKEN_DURATION_DAYS 7 Default invite lifetime
WORKER_PREFETCH 4 Unacked messages per worker
WORKER_MAX_ATTEMPTS 5 Retries before a job is dropped

Containers

just up      # build + run postgres, rabbitmq, webservice, worker
just logs    # tail the webservice
just invite-in-pod
just down

Layout

src/
  bin/            webservice, queue-worker, registration-token
  config.rs       env-driven configuration
  lib.rs          AppState + minijinja environment
  entities/       sea-orm models (users, sessions, invites, notes)
  auth/           password hashing, sessions, invite tokens, user ops
  middleware/     cookie-session auth layers
  handlers/       axum handlers (auth + notes demo)
  queue/          RabbitMQ publisher + consumer + messages
  workers/        job handlers
migration/        sea-orm migrations
templates/        minijinja templates (excluded from generation templating)
assets/           Tailwind/esbuild sources + vendored fonts
tests/            template render smoke tests

Regenerating entities after a schema change

sea-orm-cli generate entity -u "$DATABASE_URL" -o src/entities