Skip to content

Database Schema

The database is PostgreSQL 16, accessed via Prisma 5. All model definitions live in packages/database/prisma/models/.

Core entities

User

Global user account, managed by better-auth. One user can belong to multiple tenants.

FieldTypeDescription
idStringCUID primary key
emailStringUnique email address
nameStringDisplay name
emailVerifiedBooleanWhether email has been verified
imageString?Avatar URL
lastLoginAtDateTime?Last login timestamp
createdAtDateTimeAccount creation time

Tenant

A workspace that contains users, projects, invoices, and time entries.

FieldTypeDescription
idStringCUID primary key
nameStringWorkspace display name
logoString?Logo URL
themeStringUI theme colour (default: blue)
featuresJson?Feature flag configuration (FeatureSettings)
emailSettingsJson?IMAP email sync configuration
countsJson?Cached aggregate counts

The features JSON follows this shape:

typescript
type FeatureSettings = {
  projects?: boolean        // default: true
  vehicles?: boolean        // default: true
  zones?: boolean           // requires projects
  tasks?: boolean           // requires projects
  invoices?: boolean        // requires projects
  hoursOverview?: boolean   // default: true
  emailSync?: boolean       // default: true
  punchClock?: boolean      // default: false
  approvalWorkflow?: boolean // default: true
}

TenantUser

A user's identity within a specific tenant. Each user gets a separate TenantUser record per tenant they belong to.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
userIdStringFK to User
nameStringDisplay name within this tenant
archivedBooleanSoft-delete flag
vehicleIdString?Assigned vehicle
automationsJson?Per-user automation configuration

Entry

A logged time entry.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
tenantUserIdStringFK to TenantUser (who logged it)
projectIdString?FK to Project (optional)
taskIdString?FK to Task (optional)
startDateTimeStart time
endDateTimeEnd time
durationIntDuration in minutes
pauseMinutesIntBreak time deducted in minutes
commentString?Admin-visible comment
userCommentString?Worker's own comment
approvedBooleanWhether entry is approved
rejectedBooleanWhether entry was rejected
archivedBooleanSoft-delete flag

Invoice

An invoice document uploaded by a worker or received via email sync.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
nameStringInvoice display name
typeString?Invoice type/category
statusStringProcessing status (default: nouveau)
linkString?File URL (presigned or permanent)
amountHtFloat?Amount excluding VAT
amountTvaFloat?VAT amount
amountTtcFloat?Total amount including VAT
numberString?Invoice number
dateDateTime?Invoice date
datePaidDateTime?Date the invoice was paid
descriptionString?Description of work
commentString?Admin comment
ocrContentString?Raw OCR-extracted text
checkedBooleanReviewed by admin
approvedBooleanApproved for payment
markedAsPaidBooleanMarked as paid
archivedBooleanSoft-delete flag

Project

A project or cost centre that time entries and invoices can be attributed to.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
nameStringProject name
zoneInt?Zone number for grouping
responsibleIdString?FK to TenantUser (project manager)
startDateTime?Project start date
endDateTime?Project end date
archivedBooleanSoft-delete flag

TaskList / Task

Task lists group tasks; projects reference a task list. Workers select tasks when logging time.

ModelKey fields
TaskListid, tenantId, name, archived
Taskid, taskListId, name, order

Vehicle

A vehicle that can be assigned to a user for fuel/maintenance invoice tracking.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
nameStringVehicle name/plate
archivedBooleanSoft-delete flag

ApiKey

An API key scoped to a tenant, used for programmatic access.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
nameStringHuman-readable label
keyHashStringSHA-256 hash of the key
keyPrefixStringFirst 8 characters for display
revokedBooleanWhether the key is revoked
expiresAtDateTime?Expiry date (null = never)
lastUsedAtDateTime?Last usage timestamp

Webhook / WebhookDelivery

Outbound webhook subscriptions and their delivery history.

FieldTypeDescription
idStringCUID primary key
tenantIdStringFK to Tenant
urlStringDestination URL
secretString?HMAC signing secret
eventsString[]List of subscribed event names
activeBooleanWhether the webhook is active

Database extensions

  • pg_trgm — Trigram index extension for full-text search. searchVector columns on Entry, Invoice, Project, and TenantUser are populated automatically.

TT Time Tracker — Internal Documentation