Skip to content

Data model

The domain model lives in packages/shared/src/index.ts; tables are in apps/api/src/db/schema.ts. This page summarizes it. The file itself is the source of truth.

Field Type Notes
id ID
name string
prefix string Used for codes: laptop → laptop_001
tracking Tracking serial (one by one) · stock (by quantity)
unit string Stock unit: pcs, kg, m…
minQty number? Stock: total below this is low stock
icon, category, description string
fields FieldDef[] Label schema
slots Slot[] Expected components
nextNumber number Next code number; never decremented

FieldDef: key, label, type (text · number · select · date · boolean), optional options, unit, required.

Slot: id, typeId, optional label, optional qty (unset = any number).

Field Type Notes
id ID
typeId ID
code string laptop_001
name string?
qty number Always 1 for serial types
status Status operational · attention · maintenance · faulty · retired
parentId ID | null Item it is installed in
slotId ID? Slot of the parent it fills
custodianId ID?
location string?
labels Record<string, string | number | boolean> Keyed by FieldDef.key
watchers ID[]

name, kind (pdf · image · sheet · text · archive · other), size, optional description, and a scope:

type DocScope =
| { kind: 'item'; itemId: ID }
| { kind: 'type'; typeId: ID }
| { kind: 'variant'; typeId: ID; field: string; value: string }

target ({ kind: 'item' | 'type'; id }), authorId, body, via (web · email · qr), optional replyTo.

Field Notes
itemId
fromId Custodian when it started; unset = from stock
toId Recipient
requestedBy Who started it. The other side confirms.
status pending · accepted · declined · cancelled
note, responseNote
checked, missing Component IDs confirmed present / reported missing
condition Status confirmed by the receiver

Both are stored as data (kind plus IDs), never as rendered sentences, so they display in the viewer’s language. Activity kinds: created, status, assigned, unassigned, comment, document, labels, custody, handover, type, stock, transferred (moved to or from another workspace; data has the other workspace’s name and the code).

action (delete · restore), entity (item · type · doc · comment · user), label (code or name at the time), actorId, reason, and a snapshot with everything needed to restore.

id, name, slug (unique, fixed at creation, used in /w/<slug>/ URLs). Every type, item, document, comment, activity, handover, notification, agent token and audit entry belongs to one workspace; deleting a workspace deletes them. Type prefixes and item codes are unique per workspace. Account deletes are audit entries without a workspace.

An account has name, email, isAdmin (instance admin) and status (active · invited · disabled). A membership gives an account a role (admin · editor · viewer) in one workspace. In the app state, User is a member of the open workspace with their role there.