Aller au contenu principal

inventory

The web inventory includes item slide-outs, stock, locations and printable sticker templates. Print requests are consumed by the devices service (mock printer driver).

Runs in the apps compose profile on port 8085; the gateway routes /v1/inventory to it. OpenAPI: API reference (services/inventory/openapi.yaml).

Role: owner of everything physical in the makerspace: tools, machines and consumables, the location tree of each site, consumable stock, maintenance plans, issues and QR labels. Inventory is the owner of item status: borrowing never writes it, it publishes checkout/return events that inventory applies.

Limits: no borrowing logic (sheets, borrowers), no file storage (photos are files IDs), no purchases (stock increases come from movements with a free reference), no label printer driver (print jobs are routed through devices). Training requirements are indicative only.

Model​

  • Item (kind = tool | consumable | machine): name, description, category, brand, model, serial, site_id, location_id, project_id, required training type IDs, photos (file IDs), tags, purchase info (price, date, supplier), custom fields. Status: available, borrowed, in_maintenance, out_of_service, lost. Event sourced (aggregate item).
  • Consumable extras: unit (piece, m, g, kg, ml, l, sheet), quantity, low_stock_threshold, unit_cost. Stock movements in | out | adjust (reason, project, reference); a movement making the stock negative is refused (except adjust). Project cost = sum of out movements × unit cost.
  • Low stock: emitted once per downward crossing of the threshold, only when the site setting low_stock_alerts is enabled (disabled by default).
  • Short code: A- + 8 Crockford base32 symbols (40 random bits). QR content is INVENTORY_PUBLIC_URL/q/<code>; codes are normalised (case, prefix) on resolution.
  • Locations: tree per site with a materialised path (subtree queries); node types are configurable per site. Items attach to any node. Moving a node rewrites the paths of its subtree in the same transaction.
  • Maintenance plans: on one item, every N days and/or every N uses (use count is incremented on each checkout), optional assignee. A job opens one task per due plan; completing it resets the counters.
  • Issues: reported on an item (title, description, photos), status open → in_progress → resolved. The reporter may edit their own issue (not the assignee). Photos are files owned by the issue ARN atl:inventory:<site>:issue/<id> (purpose issue): report the issue, upload the photos, then PATCH its photos.
  • History: per-item timeline merged from the event store (edits, moves, status/custody, stock, maintenance, issues).
  • Deletion: soft delete, purge after INVENTORY_PURGE_DELAY; ?force=true purges immediately and requires admin mode. A purge removes the item state, its event stream and its maintenance plans; issues are kept.

Authorization​

ARNs: atl:inventory:<site>:item/<id>, …:location/<id>, …:maintenance/<id>, …:issue/<id>, plus …:stock/<id> and …:label/<id> for stock and label permissions. Parents: atl:settings:<site>:site/<site> and, for project-owned items, atl:projects:<site>:project/<id>. Lists use authz Lookup scopes (sites, projects, IDs) as MongoDB filters; an empty scope returns 403.

Issue photos (files delegate): inventory.issue.read/update do not exist, so the files service delegates issue photo checks to POST /internal/v1/attachments/authorize ({owner, parents, action}, caller X-Atl-Principal required; 204 allowed, 403 denied, 404 unknown owner). Read: the reporter or inventory.item.read on the issue item. Write: the reporter or inventory.issue.handle, or inventory.issue.report while the issue is open. /internal/... routes are not routed by the gateway.

Dependencies​

  • Services: authz (ConnectRPC Check, LookupResources through authzclient), borrowing (consumes its sheet events only).
  • Infrastructure: MongoDB (replica set, transactions), Kafka.
  • Libraries: authzclient, httpx, principal, pagination, problem, eventstore, outbox, audit, cloudevent, mongox, kafkax, lease, csvx, arn, ids, config. See libraries.

Inputs and outputs​

All routes are under /v1/inventory and require authentication. "scope" means the list is filtered with the Lookup scope of the permission. Bulk actions (update, move, status, delete, restore) take up to 500 unique IDs, authorize and apply each item separately and answer 200 with one {id, ok, error} result per item (error = problem code).

MethodPathPermission
GET/itemsinventory.item.read (scope); include_deleted also needs inventory.item.read_all
POST/itemsinventory.item.create
GET/items/:idinventory.item.read
PATCH/items/:idinventory.item.update (also on the new project when changed)
PUT/items/:id/statusinventory.item.update
POST/items/:id/moveinventory.item.update (+ inventory.item.create on the target site)
DELETE/items/:idinventory.item.delete (?force=true: admin mode)
POST/items/:id/restoreinventory.item.delete
GET/items/:id/historyinventory.item.read
GET, POST/items/:id/movementsinventory.item.read / inventory.stock.adjust
GET/label-templatesinventory.item.read scope; cursor-paginated physical formats
GET/items/:id/label.svg?template=inventory.item.read; mini, small, medium (default), large
POST/items/:id/print-labelinventory.label.print (202, publishes the print request)
POST/items/bulkper item: inventory.item.update (update, move, status; + inventory.item.create on the target site for a cross-site move) or inventory.item.delete (delete, restore; force: admin mode)
POST/items/import, /consumables/importinventory.item.create on every row (CSV formats)
GET/items/export.csv, /consumables/export.csvinventory.item.read (scope)
POST/locations/importinventory.location.create on every site of the file
GET/locations/export.csvinventory.location.read (scope)
GET/resolve/:codeinventory.item.read on the resolved item
GET/projects/:id/costsinventory.item.read (scope)
GET, PUT/sites/:site/settingsinventory.item.read / inventory.item.update on item/* of the site
GET/locationsinventory.location.read (scope)
POST/locationsinventory.location.create
GET, PATCH, DELETE/locations/:idinventory.location.read / update / delete
POST/locations/:id/moveinventory.location.update
GET, POST/sites/:site/location-typesinventory.location.read / inventory.location.update
PATCH, DELETE/location-types/:idinventory.location.update
GET, POST/maintenance/plansinventory.item.read (scope) / inventory.maintenance.manage
GET/maintenance/plans/:idinventory.item.read on the item
PATCH, DELETE/maintenance/plans/:idinventory.maintenance.manage
GET/maintenance/tasksinventory.item.read (scope)
POST/maintenance/tasks/:id/completeinventory.maintenance.manage
GET/issuesinventory.item.read (scope)
POST/issuesinventory.issue.report
GET/issues/:idinventory.item.read on the item
PATCH/issues/:idreporter, or inventory.issue.handle
PUT/issues/:id/statusinventory.issue.handle
POST/internal/v1/attachments/authorize (internal, not under /v1/inventory)see issue photos above
KindNameNotes
RPC outauthz.v1.AuthzService/Check, LookupResourcespermission checks and list scopes
Kafka outinventory.item.v1created, updated, moved, status_changed, deleted, restored, purged
Kafka outinventory.stock.v1moved, low (keyed by item ID)
Kafka outinventory.location.v1created, updated, moved, deleted (subject and key = location ID, see below)
Kafka outinventory.maintenance.v1plan_created, plan_updated, plan_deleted, task_due, task_completed
Kafka outinventory.issue.v1reported, updated, status_changed
Kafka outinventory.label.v1print_requested (item, short code, QR URL, template, copies, printer)
Kafka outaudit.records.v1inventory.item.create/update/status_change/move/delete/restore/custody/purge, inventory.stock.in/out/adjust, inventory.label.print, inventory.location.create/update/delete/move/type_create/type_update/type_delete, inventory.settings.update, inventory.maintenance.plan_create/plan_update/plan_delete/task_due/task_complete, inventory.issue.report/update/status_change, exports inventory.item.export, inventory.location.export
Kafka infinance.purchase.v1 (INVENTORY_PURCHASE_TOPIC), group inventory-purchasesfinance.purchase.received: one stock in movement per received line with an item (reference purchase:<purchase>:<line>:<receipt_seq>, legacy events without receipt_seq keep purchase:<purchase>:<line>; idempotent on redelivery; quantity in item units, quantity_milli preferred), weighted average unit_cost (euros, from unit_cost_cents); unknown, deleted or non-consumable items are skipped
Kafka inborrowing.sheet.v1 (INVENTORY_CUSTODY_TOPIC), group inventory-custodychecked_out → borrowed (+1 use), items_returned → available; idempotent per sheet, unknown or deleted items and malformed events (or more than 500 items) are skipped

Location events carry IDs and structural fields only (no description, no PII), in the same transaction as the write and its audit record:

TypeData
inventory.location.createdid, site_id, parent_id, type, name, depth
inventory.location.updatedid, site_id, changed (name, type, description, or ancestors), type, name
inventory.location.movedid, site_id, root_id, from_parent_id, to_parent_id, depth
inventory.location.deletedid, site_id, parent_id

A move publishes one moved event per node of the moved subtree (root_id is the node that was moved, the parents are those of the root), and a rename publishes updated with changed: [ancestors] for every descendant, so consumers that denormalise the ancestor path (search) refresh each node. Locations have no soft delete. Node types and site settings changes are audited but publish no domain event. Background jobs (purge of soft deleted items every INVENTORY_PURGE_INTERVAL, maintenance task generation every INVENTORY_MAINTENANCE_INTERVAL) run on one replica at a time through a MongoDB lease. Events go through the outbox (CQRS, Kafka).

Data (MongoDB inventory)​

CollectionKey fieldsIndexes
itemsitem state, version, short_code, location_path, search_terms, low_stock, custody, use_count, deleted_at, purge_atunique partial short_code; partial purge_at; site_id, location_path, location_id, kind, status, category, tags, project_id, search_terms, deleted_at (each + _id); partial low_stock
locationssite_id, parent_id, type, name, name_key, path, depthunique (site_id, parent_id, name_key); path; site_id, parent_id, search_terms (+ _id)
location_typessite_id, key, name, orderunique (site_id, key); (site_id, order)
site_settings_id = site, low_stock_alerts—
maintenance_plansitem_id, site_id, every_days, every_uses, assignee_id, next_due_at, open_task(item_id, _id), (site_id, _id), unique partial open_task.id, next_due_at, every_uses
issuesitem_id, site_id, status, reported_by, assignee_id, photositem_id, site_id, status, project_id (each + _id)
eventsevent log (items, plans, issues)eventstore indexes + data.item_id, (type, data.project_id), aggregate_id
outboxpending Kafka messages—
locksleases of the outbox relay and of the inventory-purge and inventory-maintenance jobs (pkg/lease)—

Search uses search_terms (normalised tokens of name, brand, model, serial, short code, tags); every list sorts on _id with cursor pagination.

Configuration​

VariableDefaultDescription
HTTP_ADDR:8085Listen address (compose sets :8085)
METRICS_ADDR:9185Prometheus listener
PRINCIPAL_PUBLIC_KEYrequiredVerifies X-Atl-Principal
AUTHZ_URLhttp://localhost:8081authz ConnectRPC endpoint
KAFKA_BROKERSlocalhost:19092Outbox relay and custody consumer
MONGO_URI, MONGO_DATABASEmongodb://localhost:27017/?directConnection=true, inventoryMongoDB
INVENTORY_PUBLIC_URLhttps://atelier-maker.frBase of QR code URLs (/q/<code>); compose: http://localhost:3000
INVENTORY_SITESparis,strasbourgSites whose default location types (room, furniture, shelf, bin) are seeded at startup
INVENTORY_PURGE_DELAY24hSoft delete → purge delay
INVENTORY_PURGE_INTERVAL1hPurge job period
INVENTORY_MAINTENANCE_INTERVAL15mMaintenance task generation period
INVENTORY_CUSTODY_TOPICborrowing.sheet.v1Topic of borrowing checkout/return events
INVENTORY_PURCHASE_TOPICfinance.purchase.v1Topic of finance purchase events (received stock)

Plus the common APP_ENV, LOG_LEVEL, OTEL_EXPORTER_OTLP_ENDPOINT (see environment variables).