Database Schema

Depict AI uses SQLModel (a combination of SQLAlchemy and Pydantic) to define its database schema. Tables are created automatically on backend startup via init_db().


Entity Relationship Overview

User ──────────────────────────────────────────────┐
 │                                                  │
 │ many-to-many (ProjectUserLink)                   │
 ▼                                                  │
Project ──► MinIOConfig                            │
 │                                                  │
 │ one-to-many                                      │
 ▼                                                  │
Data (Image/Video/Frames) ◄──── author_id ─────────┘
 │
 │ one-to-many
 ▼
Annotation ──► AnnotationLabel
               AnnotationChange (history)

Tables

user

Stores authenticated users (created on first login via Clerk).

Column Type Description
id Integer PK Auto-generated
username String (unique, indexed) Display name
email String (unique, indexed) Email address
permission Enum Global permission level
oauth_provider String (nullable) clerk, google, microsoft, github
oauth_id String (nullable) External provider user ID

Permission levels:

Value Description
view only Read-only access
edit Can create and edit annotations
edit & delete Can also delete data
can certify Can mark annotations as certified

project

A logical grouping of images and annotations.

Column Type Description
id Integer PK Auto-generated
name String (unique, indexed) Project name
description String (nullable) Optional description
owner_id FK → user.id Project creator
created_at Datetime (nullable) Creation timestamp
status Enum active, deleted, archived

Many-to-many join table between user and project.

Column Type
project_id FK → project.id (PK)
user_id FK → user.id (PK)

minioconfig

Stores per-project MinIO credentials for object storage access.

Column Type Description
id Integer PK Auto-generated
project_id FK → project.id (unique) One config per project
endpoint String MinIO server URL
bucket_name String Target bucket
access_key String Access key ID
secret_key String Secret access key ⚠️ stored in plaintext — encrypt in production
use_ssl Boolean Enable TLS
last_sync Datetime (nullable) Timestamp of last sync

data

Represents an individual media item (image, video, or frame sequence).

Column Type Description
id Integer PK Auto-generated
type Enum image, frames, video
location String Path, URL, or API reference
author_id FK → user.id (nullable) Uploader
creation_date Datetime (nullable) Upload timestamp
project_id FK → project.id Owning project

annotation

Stores individual annotations. One Data record can have multiple annotations (e.g., multiple bounding boxes on one image).

Column Type Description
id Integer PK Auto-generated
status Enum Annotation lifecycle status
history_status Enum current or history (for versioning)
x1, y1, x2, y2 Integer (nullable) Bounding box coordinates
keypoints String/JSON (nullable) {"nodes": [...], "edges": [...]}
mask_segments String/JSON (nullable) Array of polygon point arrays
polygon String/JSON (nullable) Flat array of polygon points

Annotation statuses:

Value Description
to review Newly created, pending review
human annotation Verified by a human annotator
ml annotation Generated by an AI model
rejected Marked as incorrect
certified Final, approved annotation

Database Initialization

On backend startup, src/backend/db/database.py calls SQLModel.metadata.create_all(engine) which creates any missing tables without dropping existing data.

For production migrations (schema changes), use Alembic or recreate the database and restore from backup.