Formbricks uses PostgreSQL as its primary database and Prisma as the Object-Relational Mapping (ORM) tool. The database schema is designed to support multi-tenancy, survey management, and response collection while maintaining data isolation between organizations.

Entity Relationship Diagram

The following diagram shows the core entities and their relationships in the Formbricks database:

Core Models

Organization & Project Management

  1. Organization

    • Top-level entity for multi-tenancy
    • Contains multiple projects and team members
    • Manages billing and whitelabel settings
  2. Project

    • Groups related surveys and configurations
    • Has two environments (production/development)
    • Controls branding and display settings
  3. Environment

    • Isolates production and development resources
    • Contains surveys, contacts, and actions
    • Manages API keys and integrations

Survey Management

  1. Survey

    • Central model for questionnaires
    • Configurable with multiple questions and display rules
    • Supports multiple languages and targeting filters
  2. Response

    • Records user answers to surveys
    • Links to contact information when available
    • Supports tagging and notes for analysis
  3. ActionClass

    • Defines triggering points for surveys
    • Can be code-based or no-code configurations
    • Links surveys to specific user actions

User Management

  1. User

    • Represents system users (admins/team members)
    • Manages authentication and preferences
    • Can belong to multiple organizations
  2. Contact

    • Represents survey respondents
    • Stores attributes for targeting
    • Tracks survey displays and responses
  3. Team

    • Groups users within organizations
    • Controls project access permissions
    • Facilitates collaborative survey management

Data Isolation

The database schema ensures proper data isolation through:

  1. Organization-level isolation

    • Each organization has its own projects
    • Users can belong to multiple organizations
    • Resources are scoped to organizations
  2. Environment-level isolation

    • Separate production and development environments
    • Independent surveys, contacts, and actions
    • Isolated API keys and integrations
  3. Project-level isolation

    • Project-specific configurations
    • Separate language settings
    • Team-based access control

Schema Management

The database schema is managed through Prisma, which provides:

  • Type-safe database client
  • Automatic migration generation
  • Schema versioning
  • Data validation
  • Query optimization

For detailed information about specific models and their properties, refer to the schema.prisma file in the repository.

PostgreSQL Database Tables

Formbricks stores all data in PostgreSQL tables. Here’s a comprehensive list of all database tables and their purposes:

Table NameDescription
AccountStores third-party authentication accounts (OAuth) and their tokens
ActionClassDefines triggerable events that can launch surveys
ApiKeyStores API authentication keys for environment-specific access
ContactRecords information about user that can receive and respond to surveys
ContactAttributeStores attribute values for contacts (e.g., role, company size)
ContactAttributeKeyDefines available attribute types for contacts
DataMigrationTracks the status of database schema migrations
DisplayRecords when and to whom surveys were shown
DocumentStores processed survey responses for analysis
DocumentInsightLinks analyzed documents to derived insights
EnvironmentManages production/development environments within projects
InsightContains analyzed patterns and information from responses
IntegrationStores configuration for third-party service integrations
InviteManages pending invitations to join organizations
LanguageDefines supported languages for multi-lingual surveys
MembershipLinks users to organizations with specific roles
OrganizationTop-level container for projects and team management
ProjectGroups related surveys and environments
ProjectTeamManages team access permissions to projects
ResponseStores survey responses and associated metadata
ResponseNoteContains team member comments on survey responses
SegmentDefines groups of contacts based on attributes
ShortUrlMaps shortened URLs to their full destinations
SurveyStores survey configurations, questions, and display rules
SurveyAttributeFilterDefines targeting rules for surveys based on contact attributes
SurveyFollowUpConfigures automated actions based on survey responses
SurveyLanguageLinks surveys to their supported languages
SurveyTriggerConnects surveys to their triggering actions
TagStores labels for categorizing responses
TagsOnResponsesJunction table linking tags to responses
TeamGroups users within organizations
TeamUserLinks users to teams with specific roles
UserStores user account information and preferences
WebhookManages webhook endpoints for event notifications

Schema Reference

For detailed information about the database schema, including:

  • Complete field definitions
  • Relationships between tables
  • Enums and custom types
  • Field constraints and indices
  • JSON field structures

Please refer to the Prisma schema file in our GitHub repository.

The schema.prisma file contains extensive documentation comments for each model, making it the authoritative reference for the database structure.