Skip to main content
Version: Sprint 3

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 application tables (user_files, file_versions, contributors) for document management and sharing, 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

contributors​

Associates an invited user with a saved document. The file owner adds or removes contributor rows; owners and contributors pass the editor's collaboration access check.

ColumnTypeDescription
file_idstring (FK)Shared file in user_files
user_idstring (FK)User granted collaborative access
added_atdatetimeWhen access was granted

Authentication Tables (Better-Auth)​

These tables are managed by Better-Auth and handle user identity, OAuth accounts, sessions, and verification tokens.

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. The configured social providers are GitHub and Google. The providerId field identifies the provider; OAuth tokens and expiry timestamps are managed by Better-Auth.

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 verification tokens managed by Better-Auth. Verification records are keyed by their identifier and are not directly related to a user row by a user_id foreign key.

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) contributors >── (1) user_files
user (1) ─< (N) session
user (1) ──< (N) account
  • 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 contributors row grants a user collaborative access to a file; only the owner manages contributors.
  • A user has many sessions (active logins across devices).
  • A user has many accounts (one per auth provider, e.g. Google + email/password).
  • Verification records are managed by Better-Auth and are not linked directly to a user row in this schema.

Original Schema Diagram​

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

Database Schema PDF