Self-hosted 3D printer filament inventory, with accounts: each account has its own inventory, and locations can be shared between accounts.
| Area | Choice | Why |
|---|---|---|
| Backend | Rust, axum 0.8, tokio, serde, tower-http (CORS, tracing, compression) |
Small binary, low memory on a home server or Pi |
| DB access | sqlx with the PostgreSQL, SQLite and MySQL drivers, behind db::Db |
One set of queries for every database; checked by running the API tests on each in CI |
| Database | PostgreSQL 18, SQLite, or MySQL 8.0+/MariaDB 10.6+, picked by DATABASE_URL |
PostgreSQL for a server; SQLite for one container with nothing else to run; MySQL/MariaDB where one already runs |
| Scraping | reqwest (rustls) + scraper |
Pure Rust, no OpenSSL headaches in Docker |
| Frontend | SvelteKit 3 + Svelte 5 (runes) + TypeScript 6 + Tailwind 4 + Vite 8, adapter-static SPA |
Built to static files and served by the Rust binary, so deployment is one container plus a database (or none, with SQLite) |
| Errors | thiserror for domain errors, a single AppError mapped to JSON responses |
Consistent { "error": { "code", "message" } } |
| Config | env vars via dotenvy + a typed Config struct |
DATABASE_URL, BIND_ADDR, STATIC_DIR, BASE_PATH, scraper settings, optional ANTHROPIC_API_KEY; any of them from a file with NAME_FILE |
During development the SvelteKit dev server (port 5173) proxies /api to the backend (port 8080).
POST /api/filaments/parse-url runs extractors from most to least trustworthy and fills each field from the first one that finds it. It never fails because data is missing; it returns partial data, the list of missing fields, the source of every field, and plain-language warnings.
- Safety check: http(s) only; hosts that resolve to private, loopback or link-local addresses are refused (and redirects to private IP literals). A host that can't be resolved skips the fetch and falls back to URL hints.
- Fetch: browser-like user agent, 12 s timeout, 4 MB cap, 5 redirects. Captcha and access-denied pages (Amazon robot check, Cloudflare challenge, 403/429/503) are flagged as
blocked. - Shopify product JSON: stores on Shopify (Polymaker, eSUN, HATCHBOX and many more) serve
/products/<handle>.js, which gives vendor, title, the selected?variant=color, price and description. - schema.org JSON-LD
Product(including@graph,additionalProperty). - Site adapters: Amazon (title, byline brand, overview and tech-spec tables, bullets, hi-res image, price).
- Generic spec tables:
<table>rows,<dl>lists and "Key: Value" bullets. - OpenGraph and meta tags.
- Title regex: brand, material, color phrase ("Galaxy Blue"), weight, diameter.
- Visible page text regex (scripts and styles excluded): temperature ranges, speeds, drying conditions.
- Optional AI pass with structured output, Claude or an OpenAI-compatible local model as picked in Settings › AI (or
ANTHROPIC_API_KEY), only when essentials are still missing. It only fills gaps. - URL hints: brand from the store domain, material and color from the slug.
- Derived: swatch hex from the color name, canonical brand spelling, product name from a short title.
The frontend highlights fields that came from guesses (amber) or were not found (red). Nothing is saved until the user confirms.
rollcall/
├── .github/
│ ├── workflows/
│ │ ├── tests.yml # lint, backend, frontend, Docker image (amd64 + arm64), native downloads, publish
│ │ ├── scan.yml # midweek Trivy scan of the published images
│ │ ├── sync-develop.yml # fast-forwards develop after a merge into main
│ │ ├── sync-wiki.yml # copies docs/ to the wiki (main, or develop before the first release)
│ │ └── dockerhub-description.yml
│ ├── scripts/ # docs_to_wiki.py, test-native-install.sh
│ ├── ISSUE_TEMPLATE/ # bug report and feature request forms
│ └── CONTRIBUTING.md, SECURITY.md, SPONSORS.md, CODE_OF_CONDUCT.md, FUNDING.yml, dependabot.yml
├── backend/
│ ├── Cargo.toml
│ ├── migrations/
│ │ ├── postgres/ # numbered migrations, applied in order
│ │ ├── sqlite/ # the same changes for SQLite
│ │ └── mysql/ # the same changes for MySQL/MariaDB
│ ├── src/
│ │ ├── main.rs # boot: config, tracing, pool, migrate, serve
│ │ ├── config.rs # env vars (or NAME_FILE), BASE_PATH
│ │ ├── web.rs # the built frontend, served from memory with BASE_PATH filled in
│ │ ├── db.rs # Db (one pool per backend), queries and their values, migrations
│ │ ├── error.rs # AppError -> IntoResponse
│ │ ├── catalog.rs # the Open Filament Database and SpoolmanDB: download, cache, merged in-memory search
│ │ ├── backup.rs # backups: every table and photo in a zip, restorable on any database
│ │ ├── auth.rs # passwords, session cookie, API tokens, require_user middleware
│ │ ├── events.rs # live updates: announce middleware, GET /api/events (server-sent events)
│ │ ├── gcode.rs # reads each filament's grams from a slicer's G-code comments
│ │ ├── connect/ # printer connections: one background task per printer
│ │ │ ├── mod.rs # starts and restarts them, logs a print when it ends
│ │ │ ├── bambu.rs # Bambu Lab: follows the MQTT reports, finds each filament's AMS slot
│ │ │ ├── moonraker.rs # Klipper: polls Moonraker's state and print history
│ │ │ ├── prusalink.rs # Prusa: polls PrusaLink's state and job, with Digest sign-in
│ │ │ ├── http.rs # shared by both: addresses, errors, reading G-code and binary G-code
│ │ │ ├── mqtt.rs, ftps.rs # small MQTT 3.1.1 and implicit-FTPS clients
│ │ │ ├── threemf.rs # reads the grams per filament from a print's 3MF
│ │ │ └── tls.rs # TLS to printers, which sign their own certificates
│ │ ├── mcp.rs # MCP server for AI assistants (POST /api/mcp); changes only when the account allows them
│ │ ├── notify/ # notifications (ntfy, webhook, email, Home Assistant), checked after changes and every 15 minutes
│ │ │ └── homeassistant.rs # Home Assistant sensors over MQTT, with discovery
│ │ ├── routes/ # one module per resource
│ │ │ ├── mod.rs # Router assembly, /api prefix, frontend fallback, BASE_PATH
│ │ │ ├── spools.rs # CRUD, weight changes, duplicates and merging, CSV
│ │ │ ├── filaments.rs # list/get/edit, POST /filaments/parse-url
│ │ │ ├── prints.rs # slicer uploads, assigning spools, slicer presets
│ │ │ ├── lookups.rs # brands, materials, locations and sharing, printers
│ │ │ └── ... # auth, ai, backups, catalog, custom, equipment, humidity, labels, notifications, photos, projects, settings, stats, tuned
│ │ ├── models/ # FromRow structs + request/response DTOs
│ │ ├── repo/ # SQL lives here, routes stay thin
│ │ └── scraper/
│ │ ├── mod.rs # pipeline + merge + normalization
│ │ ├── draft.rs # result type, field-by-field merge with sources
│ │ ├── fetch.rs # HTTP client, SSRF guard, block detection
│ │ ├── structured.rs # JSON-LD / OpenGraph
│ │ ├── heuristics.rs # regex extraction
│ │ ├── brands.rs # domain → brand, canonical spelling
│ │ ├── colors.rs # color phrases, swatch hex guesses
│ │ ├── llm.rs # the AI step with Claude
│ │ ├── local.rs # the AI step with an OpenAI-compatible server (Ollama and others)
│ │ └── sites/ # amazon.rs, shopify.rs, spec_table.rs
│ ├── examples/parse_file.rs # run the parser on a saved page
│ └── tests/
│ ├── api.rs # end-to-end API tests, on the database TEST_DATABASE_URL names
│ └── fixtures/ # saved pages for scraper tests (no live network in CI)
├── frontend/
│ ├── package.json # #lib/* subpath import for src/lib
│ ├── vite.config.ts # SvelteKit options (adapter-static), /api proxy in dev
│ └── src/
│ ├── app.css # Tailwind
│ ├── lib/
│ │ ├── api/ # typed fetch client + types mirroring backend DTOs
│ │ ├── components/ # SpoolCard, AddSpoolModal, DuplicateMerge, LabelDesigner, the settings sections, ...
│ │ ├── state/ # live updates
│ │ └── util/ # formatting, labels, slicer presets, OpenSpool NFC tags and other helpers (+ vitest tests)
│ └── routes/ # dashboard (/), spools/[id], prints, labels, equipment, settings, login
├── Dockerfile # multi-stage: node build -> cargo build -> slim runtime
├── docker/rollcall.sh # the image's `rollcall`: runs the server as PUID:PGID
├── docker-compose.yml # postgres:18 (+ healthcheck, volume); app service under a "full" profile
├── .env.example
├── packaging/ # native install: install.sh, systemd unit, FreeBSD rc.d script, settings file, `rollcall` command
├── scripts/seed-dev.sh # sample data through the API
├── scripts/package-native.sh # packs a native download (server + web interface + packaging/)
├── docs/ # these pages (also published to the wiki)
├── CHANGELOG.md
└── README.md
See backend/migrations/postgres/, or the single-file schema for SQLite and MySQL/MariaDB. Key choices:
- Filament vs spool.
filamentsis the product (brand, material, color, manufacturer specs, scraped source).spoolsis a physical roll with its own weight, price, location and status. A second roll of the same color reuses the filament row and its specs. - Materials and locations are tables, not enums, so you can add "PLA-WOOD" or "AMS Slot 5" from the UI. Status and event kinds are a fixed list of text values, kept by a
CHECK, because code branches on them. - Weights are net grams (
NUMERIC(8,1); SQLite keeps them as numbers without a fixed scale). Tare is stored per spool so a scale weigh-in can be converted:remaining = gross - tare. - Several spools in one entry.
spools.spool_countsays how many rolls a row stands for;initial_weight_gandremaining_weight_gare totals across them, so theremaining <= initial × 1.1check still holds. The API addsspool_weight_g(one roll) andspools_left. A weigh-in measures the roll in use and adds the unopened ones as full.is_refillmarks filament sold without a spool. - Duplicates are your other entries with the same filament, refill flag and roll size (
repo::spools::duplicates).merge_spoolsadds them into one row in a transaction, moves their photos, humidity readings, prints and missing custom values, logs one correction, and deletes them. - Weight log (
spool_weight_events) records every deduction or weigh-in, written in the same transaction as the update tospools.remaining_weight_g. - Tuned overrides (
tuned_settings) are per filament per printer, with an optional "any printer" row. The spool page shows a tuned value next to the manufacturer value it overrides. - Photos (
photos) belong to exactly one spool, filament, or piece of equipment (aCHECKon PostgreSQL and SQLite; the app checks it on MySQL, which won't put aCHECKon columns whose foreign keys cascade) and are deleted with it. The image is a file named<id>.<ext>inUPLOAD_DIR; the row keeps its type, size, and caption. The type is read from the file's first bytes, and the file is served withnosniffand a sandboxing CSP. At startup, files no row names are removed. - Prints (
prints,print_slots) are what a slicer upload used, per filament slot. A logged slot points at the weight event that took its grams, so undo can give back exactly that.slicer_profilesmaps a slicer preset name to a filament. The G-code parser isbackend/src/gcode.rs. - Accounts (
users,sessions,api_tokens;0007_accounts.sql). Passwords are Argon2id hashes. A browser session is a random token in anHttpOnly,SameSite=Laxcookie, and an API token is sent asAuthorization: Bearer; the database keeps only the SHA-256 of either.auth::require_userguards every API route but/healthand/auth/*.app_settings.registration_enableddecides whether anyone but the first account can register. Changes that could remove the last admin first write the singleapp_settingsrow, so they run one at a time. - Per-account inventory (
0008_per_account_inventory.sql).locations,printers,filaments,spools,equipment,prints, andslicer_profileshave anowner_id; their unique names and codes are unique per owner. Rows from before accounts get the first admin, or, on an install with no account yet, are adopted by the first account (repo::accounts::adopt_unowned). Per-account settings are inuser_settings;app_settingsholds the defaults for new accounts.location_sharesgives another accountvieworeditaccess to a location's spools, andrepo::spool_accessbuilds the SQL that givesowner,edit,view, or NULL for a spool. Every query filters by the signed-in account; repo functions takeme. - Keys are UUIDv7, made by the app (
db::new_id), so new rows sort by creation time and index inserts stay local. They'reUUIDon PostgreSQL and 16 bytes (BLOB,BINARY(16)) on the others. - Times are UTC, set by the app (
db::now) rather than the database, so every backend stores the same values:TIMESTAMPTZ,DATETIME(6), or RFC 3339 text on SQLite. - One set of queries. They're written once, with
$1placeholders, in SQL all three databases understand (noILIKE,FILTER,RETURNING, or::casts).db::Querycollects the values and binds them with each driver's types; for MySQL,$Nbecomes?. The few statements that differ, such as upserts, come from helpers indb. Rows decode withsqlx::FromRow, anddb::DecreadsNUMERICcolumns on SQLite, which has no decimal type. - TD value (HueForge transmission distance) is stored per filament.
- Label designs (
label_templates) are JSON the labels page writes and reads (frontend/src/lib/util/labelDesign.ts); the server checks only that each is a JSON object of at most 16 KB. - Live updates need no table. After a signed-in change succeeds,
events::announcesends the first part of its path (the topic) and the tab'sX-Rollcall-Clientid to the accounts that can see it: the actor and everyone they share locations with in either direction, counted before and after the change so an unshare reaches the other account.GET /api/eventspasses on the ones for the signed-in account. They live in memory, so one Rollcall process serves them; a page that reconnects reloads everything. - Dashboard totals are counted over the spools you can see; each spool is low by its owner's threshold in
user_settings(default 200 g).