Skip to main content
Version: Sprint 2

Database View

The Database View describes the persistence layer of the fla-- application, including the relational schema, entity relationships, and how each table supports the application's functionality.

The database consists of two groups of tables: application tables (user_files, file_versions) that support the document management system, and authentication tables (user, account, session, verification) managed by Better-Auth.

ER Diagram​

Table Descriptions​

Application Tables​

user_files​

Stores metadata for each Turing Machine document saved by a user. Each row represents a distinct document (e.g. a saved TM configuration). The user_id foreign key links the file to its owner in the user table. When a user saves changes to a document, a new entry is created in file_versions rather than overwriting the existing file, enabling version history.

ColumnTypeDescription
idstring (PK)Unique file identifier
user_idstring (FK)Owner of the file
filenamestringDisplay name of the document
created_atdatetimeFile creation timestamp
updated_atdatetimeLast modification timestamp

file_versions​

Tracks every saved version of a user_files document. Each version records where the file is stored externally (storage_path), its MIME type, and size. The application retains only the last four versions per file, pruning older entries to limit storage growth. The actual file content is stored on an external file storage service (referenced via FILE_SERVER_URL), not in the database.

ColumnTypeDescription
idstring (PK)Unique version identifier
file_idstring (FK)Parent file in user_files
version_numberintSequential version number
storage_pathstringPath on external file storage
mime_typestringContent type (e.g. application/json)
size_bytesintFile size in bytes
created_atdatetimeVersion creation timestamp

Authentication Tables (Better-Auth)​

These tables are managed by the Better-Auth library and handle user identity, authentication sessions, and email verification.

user​

The central identity table. Each row represents a registered user of the application. The emailVerified flag is set when the user completes the email verification flow (tracked via the verification table).

ColumnTypeDescription
idstring (PK)Unique user identifier
namestringDisplay name
emailstringLogin email address
emailVerifiedbooleanWhether email has been verified
imagestringAvatar URL
createdAtdatetimeAccount creation timestamp
updatedAtdatetimeLast profile update timestamp

account​

Stores authentication provider credentials for each user. Supports multiple providers per user (e.g. Google OAuth, email/password). The providerId field identifies which authentication service the account belongs to. OAuth tokens (accessToken, refreshToken, idToken) are stored here with their expiry timestamps.

ColumnTypeDescription
idstring (PK)Unique account identifier
accountIdstringProvider-specific account ID
providerIdstringAuth provider identifier
userIdstring (FK)Associated user
accessTokenstringOAuth access token
refreshTokenstringOAuth refresh token
idTokenstringOIDC identity token
accessTokenExpiresAtdatetimeAccess token expiry
refreshTokenExpiresAtdatetimeRefresh token expiry
scopestringGranted OAuth scopes
passwordstringHashed password (email auth)
createdAtdatetimeAccount link timestamp
updatedAtdatetimeLast update timestamp
issuerstringToken issuer URL

session​

Tracks active login sessions. Each session has a unique token used for authentication and an expiresAt timestamp. The ipAddress and userAgent fields provide audit information. Expired sessions are invalidated server-side.

ColumnTypeDescription
idstring (PK)Unique session identifier
expiresAtdatetimeSession expiry timestamp
tokenstringSession authentication token
createdAtdatetimeSession creation timestamp
updatedAtdatetimeLast activity timestamp
ipAddressstringClient IP at session start
userAgentstringClient browser/device info
userIdstring (FK)Associated user

verification​

Stores email verification tokens. When a user registers, a verification record is created with a unique identifier (the email address) and a value (the verification token). The record expires after a set period, after which the user must request a new verification email.

ColumnTypeDescription
idstring (PK)Unique verification identifier
identifierstringEmail address being verified
valuestringVerification token
expiresAtdatetimeToken expiry timestamp
createdAtdatetimeRecord creation timestamp
updatedAtdatetimeLast update timestamp

Relationship Summary​

user (1) ──< (N) user_files ──< (N) file_versions
user (1) ─< (N) session
user (1) ──< (N) account
user (1) ──< (1) verification
  • A user owns many user_files (their saved TM documents).
  • Each user_file has many file_versions (version history, pruned to the last 4).
  • A user has many sessions (active logins across devices).
  • A user has many accounts (one per auth provider, e.g. Google + email/password).
  • A user has at most one pending verification record at a time.

Original Schema Diagram​

The ER diagram exported from the database design tool is available here:

Database Schema PDF