Skip to main content

Database Schemas

This document describes all database schemas used in the application, including their fields and indexes.


Clients

The clients collections stores infromation about different customers

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique client identifier
codeStringNoOptional client code
nameStringYesClient name
deletedBooleanYesSoft delete flag (default: false)

Branches

The branches collection holds information about the customers' stores

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique branch identifier
clientIdStringYesID of the client this branch belongs to
codeStringNoOptional branch code
nameStringYesBranch name
deletedBooleanYesSoft delete flag (default: false)

Projects

The projects collection holds data about a stocktaking a store

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique project identifier
branchIdStringYesID of the branch this project belongs to (validated with idRegex)
teamIdStringNoTeam assigned to the project
teamManagerIdStringNoUser ID of the assigned team manager
projectManagerIdStringNoUser ID of the assigned project manager
codeStringNoOptional project code
nameStringYesProject name
stateStringYesProject state (allowed values: initiated,running,closed,published,archived; default: initiated)
effectiveDateDateNoEffective start date
startDateDateNoActual start date
endDateDateNoEnd date (must be later than startDate if both are set)
closedAtDateNoWhen the project was closed
miscObjectYesArbitrary metadata (blackbox, defaults to {})
deletedBooleanYesSoft delete flag (default: false)
emailProcessedBooleanNoWhether email notification about customer deliverables has been sent
matchDataVerifiedEmailSentBooleanNoWhether notification email for invalid customer data was sent
notPaidBooleanNoIndicates if this was a not paid project

Indexes

  • deleted + startDate + endDate - Supports queries filtering by active/deleted state and project timeline ranges
  • branchId - Optimizes lookups of projects belonging to a specific branch
  • deleted + state + emailProcessed - Supports filtering projects by lifecycle state and email-processing workflow status

Users

The users collection stores user account information and profiles.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique user identifier
usernameStringYesUnique username
emailsArrayNoArray of email objects
emails[].addressStringYesEmail address
emails[].verifiedBooleanYesWhether email is verified
createdAtDateYesAccount creation date
profileObjectYesUser profile information
profile.firstNameStringNoUser's first name
profile.lastNameStringNoUser's last name
profile.preferedLanguageStringNoPreferred language (default: 'en')
profile.birthdayDateNoUser's birthday
profile.genderStringNoGender ('Male' or 'Female')
profile.organizationStringNoOrganization name
profile.websiteStringNoWebsite URL
profile.bioStringNoBiography
profile.countryObjectNoCountry information
profile.country.nameStringYesCountry name
profile.country.codeStringYesISO country code (2 letters)
profile.miscObjectNoMiscellaneous profile data
profile.forceChangeBooleanNoForce password change flag
servicesObjectNoAuthentication services data (blackbox)
teamIds[string]ArrayNoArray of team IDs the user belongs to
heartbeatDateNoLast activity timestamp
deletedBooleanYesSoft delete flag (default: false)
currentProjectIdStringNoCurrently active project ID
typeStringYesUser type: 'full' or 'temp' (default: 'full')
lastLogInDateNoLast login timestamp
projectIdStringNoAssociated project ID for temp users

Indexes

  • teamIds - Indexed for querying users by team membership
  • deleted + username - Indexed for querying active users by username
  • projectId + username + deleted (partial filter: projectId exists)
    • Used for querying users within a specific project

Text Indexes

  • username + profile.firstName + profile.lastName - Full-text search on user names

Matches

The matches collection stores product match information. Collections are dynamically created per project.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique match identifier
codeStringYesMatch code (indexed)
typeStringYesMatch type (indexed)
locationCodeStringNoLocation code
productCodeStringNoProduct code
lotCodeStringNoLot code
serialCodeStringNoSerial code
descriptionStringNoProduct description
extra1StringNoExtra field 1
extra2StringNoExtra field 2
extra3StringNoExtra field 3
extra4StringNoExtra field 4
extra5StringNoExtra field 5
priceNumberYesProduct price (default: 0)
messageStringNoAdditional message
alternateCodesStringNoAlternate product codes
zoneCodeStringNoZone code
divisionStringNoDivision
productGroupStringNoProduct group
batchIntegerYesBatch number (default: 1)
createdAtDateYesCreation timestamp (auto-set)

Note: Documents expire after 15 days (TTL index on createdAt).

Indexes

  • type + code - Indexed for querying matches by type and code
  • productCode + lotCode - Indexed for querying by product and lot

TTL Index

  • createdAt - Documents expire after 15 days

Scans

The scans collection stores scan records created during zone sessions.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique scan identifier
sessionIdStringYesCurrent zone session ID
originalSessionIdStringYesOriginal zone session ID when scan was created
orderIntegerYesScan order within session
matchCodeStringYesMatch code from matches collection
countNumberYesQuantity scanned
modifiedAtDateYesLast modification timestamp
needsVerificationBooleanNoWhether scan requires verification
isVerifiedBooleanYesWhether scan has been verified
addMarkerBelowBooleanYesMarker placement flag
verifyReasonStringNoReason for verification requirement
matchObjectYesMatch data from match database (blackbox)
deletedBooleanYesSoft delete flag (default: false)
revisions[object]ArrayNoRevision history array
projectIdStringYesProject ID
priceNumberNoPrice from match
piecesNumberNoNumber of pieces
zoneCodeStringNoZone code
sourceStringNoScan source

Indexes

  • projectId + originalSessionId + order - Indexed for querying scans by project and original session
  • projectId + sessionId + deleted - Indexed for querying scans by current session
  • projectId + deleted + count (descending) - Indexed for querying scans by quantity
  • projectId + matchCode + deleted - Indexed for querying scans by match code
  • projectId + revisions.sessionId - Indexed for querying scans by revision session
  • projectId - General project index

Zones

The zones collection stores zone/work area information.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique zone identifier
projectIdStringYesProject ID (not indexed)
codeStringYesZone code
warehouseCodeStringYesWarehouse code
divisionStringNoDivision
remarksStringNoZone remarks
errorVerifyFunctionStringNoVerify function error message
errorTransformScansStringNoTransform scans error message
flags[string]ArrayNoZone flags array
priorityStringNoZone priority
extra1StringNoExtra field 1
extra2StringNoExtra field 2
extra3StringNoExtra field 3
extra4StringNoExtra field 4
extra5StringNoExtra field 5
statusStringYesZone status (default: 'undefined')
deletedBooleanYesSoft delete flag (default: false)
scanSessionsIntegerNoNumber of scan sessions (auto-updated by hooks)
isVerifiedBooleanNoWhether zone is verified
metaObjectNoMetadata object (blackbox)
clientZoneCodeStringNoClient-specific zone code

Status Values:

  • undefined
  • scan.plan, scan.busy, scan.ready
  • verify.plan, verify.busy, verify.ready
  • export.plan, export.busy, export.ready
  • blocked

Indexes

  • projectId + deleted + code - Indexed for querying zones by project and code
  • projectId + deleted + status - Indexed for querying zones by project and status

Zone Sessions

The zoneSessions collection stores session records for scanning, verification, and export operations on zones.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique session identifier
uuidStringYesUnique session UUID
zoneIdStringYesZone ID
typeStringYesSession type: 'scan', 'verify', 'zone-verify', 'export', 'change-request'
deviceCodeStringNoDevice code used for session
createdAtDateYesSession creation timestamp
startedAtDateNoSession start timestamp
closedAtDateNoSession close timestamp
userIdStringYesUser ID who created the session
flags[string]ArrayNoSession flags array
busyBooleanNoWhether session is currently busy
deletedBooleanYesSoft delete flag (default: false)
projectIdStringYesProject ID
jobIdStringNoAssociated job ID (for export sessions)
revisions[object]ArrayNoRevision history array
previousZoneIdStringNoPrevious zone ID (for moved sessions)
retryHistoryArrayNoRetry history for zone-verify sessions
retryHistory[].countNumberYesRetry attempt count
retryHistory[].createdAtDateYesRetry timestamp
countNumberNoSession count

Indexes

  • userId - Indexed for querying sessions by user
  • projectId + busy - Indexed for querying active/busy sessions by project
  • projectId + zoneId + uuid (unique, partial filter: uuid exists) - Indexed for unique session lookup
  • projectId + userId + closedAt - Indexed for querying user sessions by project
  • projectId + zoneId - Indexed for querying sessions by zone
  • projectId + deleted + type - Indexed for querying sessions by type (used for statistics)

Registrations

The registrations collection stores user registration information for projects.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique registration identifier
projectIdStringYesProject ID
usernameStringYesUsername (unique per project)
passwordStringNoHashed password
deletedBooleanYesSoft delete flag (default: false)
roleStringYesProject role (from roles.project enum)
typeStringYesRegistration type: 'full' or 'temp'
isClientBooleanYesWhether registration is for a client user (default: false)
firstNameStringNoUser's first name
lastNameStringNoUser's last name
teamIds[string]ArrayNoArray of team IDs
createdAtDateYesRegistration creation date (default: now)
modifiedAtDateNoLast modification timestamp
modifiedByStringYesUser ID who last modified
metaObjectNoMetadata object (blackbox)
revisions[object]ArrayNoRevision history array

Indexes

  • username - Indexed for querying registrations by username (used by registration jobs)
  • projectId - Indexed for querying registrations by project
  • projectId + username (unique) - Indexed for unique username lookup per project

Text Indexes

  • username + firstName + lastName - Full-text search on registration names

Assets

The assets collection stores file assets (images) associated with projects, branches, clients, or global settings.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique asset identifier
metaObjectYesAsset metadata
meta.fileNameStringYesOriginal file name
meta.objectIdStringNoID of associated object (project/branch/client)
meta.objectLevelStringYesObject level: 'projectId', 'branchId', 'clientId', or 'global'
meta.uploaded_atDateYesUpload timestamp
meta.uploaded_byStringYesUser ID who uploaded the asset

Note: This collection uses ostrio:files package. Additional fields are managed by the package (size, type, path, etc.).

Accepted File Types:

  • image/png
  • image/jpg
  • image/svg+xml

Max File Size: 5 MB

Indexes

  • meta.objectLevel + meta.objectId - Indexed for querying assets by object level and ID

Stock

The stock collection stores stock/inventory information for projects.

Schema Fields

FieldTypeRequiredDescription
_idStringYesUnique stock identifier
projectIdStringYesProject ID (indexed)
matchObjectYesMatch data object (blackbox)
expectedNumberYesExpected quantity
actualNumberYesActual quantity (default: 0)
zoneIds[string]ArrayNoArray of zone IDs
verifiedBooleanYesWhether stock is verified (default: false)
differenceNumberYesDifference between expected and actual (default: 0)
differencePriceNumberYesPrice difference (default: 0)

Indexes

  • projectId - Indexed for querying stock by project

Notes

Index Notation

  • Text Indexes: Full-text search indexes for text search operations
  • TTL Indexes: Time-to-live indexes that automatically expire documents

Query Performance

When querying collections, use indexed fields in your query filters to ensure optimal performance. Composite indexes support queries that use the indexed fields in the order they appear in the index.

Soft Deletes

Most collections use a deleted boolean field for soft deletes. When querying, you may need to filter by deleted: false to exclude deleted documents, unless you have permission to view deleted items.