A selfhosted management tool for yarn enthusiasts. Keep track of your inventory, match your collection with available recipes. Get an overview over the status of each yarn roll, is it allocated to a currently active project, is it used, or is it free to start that new exciting project you have been considering.
  • Go 58.6%
  • TypeScript 34.2%
  • CSS 6.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Theis Randeris Mathiassen 8f200819c0
All checks were successful
/ build (release) Successful in 2m6s
feat: changed to podman build in CI tools (#119)
Reviewed-on: #119
2026-10-17 22:33:21 +00:00
.forgejo/workflows feat: changed to podman build in CI tools (#119) 2026-10-17 22:33:21 +00:00
backend feat: improved bad user experience, if no size was selected for recipes (#118) 2026-10-17 22:19:31 +00:00
docs feat: improved bad user experience, if no size was selected for recipes (#118) 2026-10-17 22:19:31 +00:00
frontend feat: improved bad user experience, if no size was selected for recipes (#118) 2026-10-17 22:19:31 +00:00
.env.example feat: major rework to authentication/authorization (#44) 2026-07-15 19:36:49 +00:00
.gitignore fix: search by using explicit indexing ($%[1]d) so all three ILIKEs reuse the same parameter (#97) 2026-09-19 21:59:06 +00:00
docker-compose.override.yml feat: major rework to authentication/authorization (#44) 2026-07-15 19:36:49 +00:00
docker-compose.yml fix: broken docker compose file (#45) 2026-07-18 12:41:13 +00:00
LICENSE Initial commit 2026-06-28 10:14:53 +00:00
README.md feat: improved safety, rate limiting and race condition (#115) 2026-10-17 21:46:54 +00:00
review.md feat: improve ui design (#59) 2026-07-19 10:53:35 +00:00

yarnman

A selfhosted management tool for yarn enthusiasts. Keep track of your inventory, match your collection with available recipes. Get an overview over the status of each yarn skein: free, allocated to a project, or used.

Yarn lifecycle

Each physical skein is tracked individually:

  • free — in stash (optionally at a storage location)
  • allocated — reserved for a project (in progress)
  • used — marked consumed on a project; still owned; still counts toward recipe coverage

Consuming yarn marks progress without removing allocation coverage or destroying owned stock. History is recorded in an append-only event log (GET /api/v1/yarn/:id/events, GET /api/v1/projects/:id/events).

Projects are soft-deleted (archived): in-progress yarn returns to free; used yarn stays linked for history. Moving free or allocated skeins changes only their location. Returns and project archival preserve the current location; consumption clears it. Use Manage skeins in the yarn list to select individual skeins and move or clear locations.

Upgrade (Docker Compose)

Schema migrations run automatically when the API container starts.

# 1. Backup
docker compose exec -T db pg_dump -U postgres yarnman > backup-$(date +%F).sql

# 2. Pull and restart
docker compose pull
docker compose up -d

# 3. Check logs if needed
docker compose logs api

No manual multi-step migration tools are required.

Inventory API

Inventory computation stays on the server. All recipe inventory endpoints accept an optional ?size=... and require an owned recipe; missing, global, and other users' recipes return 404.

  • GET /api/v1/inventory/summary: inventory totals and active, non-archived projects.
  • GET /api/v1/inventory/suggest-recipe/:recipe_id: independent ranked alternatives for each requirement, including dissimilar yarn. This does not claim the recipe can be made. Scores average relative midpoint/density differences over specified dimensions. Missing required measurements produce error_score: null and sort after scored candidates; perfect matches retain a score of 0.
  • GET /api/v1/inventory/recipe-availability/:recipe_id: measurement-compatible stock assigned across the entire recipe, without counting any free skein twice. match-recipe/:recipe_id is retained as an alias for this endpoint, with the new stricter eligibility and unique-assignment semantics.

Eligibility requires overlapping gauge and needle ranges for every specified dimension, and meters per 50 g within 10% when both recipe length and weight are specified. A missing range bound is open-ended (as in the UI's ≥/≤ labels); scoring uses the known bound as its representative value. Missing/invalid required candidate measurements are ineligible; a requirement without measurable specs is unverifiable, not automatically matched. Brand, name, color, and fiber are not eligibility constraints. This is a measurement heuristic, not a guarantee of substitution suitability or sufficient total meterage: quantities are still skein counts, not meterage-normalized quantities.

Availability returns matches and missing, including partial coverage and its assigned rolls. Requirement available_qty is the preview's assigned count, capped at qty_needed. Roll available_qty is actual free stock; assigned_qty is its contribution to that requirement. The maximum-flow preview maximizes covered skeins, not the number of fully covered requirements or fit score. It does not reserve stock; allocation must still revalidate availability. Size overrides change required quantities, falling back to base quantities when no override exists; size-specific length/weight are not used as yarn density.

Backend authentication

Authentication lives in backend/internal/auth. HTTP handlers (handler.go and oidc_handler.go) handle requests, responses, redirects, and cookies; services (logic.go, oidc_logic.go, and refresh.go) handle credentials, account linking, and sessions. SQL is isolated in store.go and refresh_store.go. Access-token signing remains in tokens.go, and expiring OIDC state is in oidc_state.go. Password and OIDC login share session issuance and cookie handling.

OIDC callbacks require a short-lived HttpOnly browser-binding cookie as well as one-time server-side state and nonce validation. With COOKIE_SECURE=true, the binding cookie uses the host-only __Host- prefix; production must use HTTPS. The login start and callback must use the same host. Starting another OIDC login in the same browser replaces the earlier pending browser binding, so only the latest attempt can complete. In-progress OIDC logins must be restarted after deploying this change; established sessions remain valid.

Password login and OIDC account linking share the same per-IP rate limit, and a linking token can be consumed by only one link/separate request. Database failures during refresh/revocation return server errors rather than being reported as ordinary invalid credentials. Logout clears browser cookies even if server-side revocation fails, but returns an error and logs the failure in that case.

The frontend shares one refresh promise across proactive and reactive refreshes and uses an origin-wide Web Lock to serialize refresh requests across tabs. Web Locks require a supported browser and a secure context (HTTPS or localhost); without them, only same-tab requests are coordinated. Custom API clients must also serialize refreshes and use the replacement cookie before refreshing again. The server deliberately retains strict refresh-token reuse detection, with no replay grace period: reuse revokes all active refresh tokens for that user. Reload existing tabs after deployment so every tab uses the refresh coordinator.

Backend tests

From backend/, run go test ./... and go vet ./....

Fiber's PostgreSQL integration tests are opt-in:

TEST_DATABASE_URL=postgres://postgres:password@localhost:5432/yarnman_test?sslmode=disable \
  go test -count=1 -run TestFiberPostgres ./internal/fiber

Use a disposable PostgreSQL database with permission to create schemas. The tests apply the migrations in an isolated schema and roll back all test changes.

Skein integration tests use the same variable and create/drop their own isolated schema with all application migrations:

TEST_DATABASE_URL=postgres://postgres:password@localhost:5432/yarnman_test?sslmode=disable \
  go test -count=1 -run TestSkeinPostgres ./internal/skein

Inventory integration tests use the same isolated-schema setup:

TEST_DATABASE_URL=postgres://postgres:password@localhost:5432/yarnman_test?sslmode=disable \
  go test -count=1 -run TestInventoryPostgres ./internal/inventory

Auth unit tests include signed OIDC callback tokens, account-linking guards, refresh-token rotation/reuse, and HTTP/cookie behavior. Run them with the race detector using go test -race ./internal/auth. Auth PostgreSQL integration tests use the same isolated-schema setup:

TEST_DATABASE_URL=postgres://postgres:password@localhost:5432/yarnman_test?sslmode=disable \
  go test -count=1 -run TestAuthPostgres ./internal/auth

Frontend checks

From frontend/, run npm test, npm run lint, and npm run build.