Contributing

Overview

We are so happy that you are interested in contributing to Formbricks 🤗 There are many ways to contribute to Formbricks with writing Issues, fixing bugs, building new features or updating the docs.

  • Issues: Spotted a bug? Has deployment gone wrong? Do you have user feedback? Raise an issue for the fastest response.
  • Feature requests: Raise an issue for these and tag it as an Enhancement. We love every idea. Please give us as much context on the why as possible.
  • Creating a PR: Please fork the repository, make your changes and create a new pull request if you want to make an update.
    • E2E Tests: Understand how we write E2E tests and make sure to write whenever you ship a feature here.
    • Introducing a new Question Type?: Adding a new question type to our surveys? Follow this guide to make sure you’re on the right track here.
    • How we Code at Formbricks: View this Notion document and understand the coding practises we follow so that you can adhere to them for uniformity.
    • How to create a service: Services are our Database abstraction layer where we connect Prisma (our DB ORM) with logical methods that are reusable across the server. View this document to understand when & how to write them.
  • Roadmap: Our roadmap is open on GitHub tickets and some customer and community tickets on GitHub.

If you want to speak to us before doing lots of work, please join our Discord server and tell us what you would like to work on - we're very responsive and friendly!

Contributor License Agreement (CLA)

To be able to keep working on Formbricks over the coming years, we need to collect a CLA from all relevant contributors.

Once you open a PR, you will get a message from the CLA bot to fill out the form. Please note that we can only get your contribution merged when we have a CLA signed by you.

Setup Dev Environment

We currently officially support the below methods to set up your development environment for Formbricks.

GitPod

This will open a fully configured workspace in your browser with all the necessary dependencies already installed. Click the button below to open this project in Gitpod. For a detailed guide, visit the Gitpod Setup Guide section below.

Open in Gitpod

Github Codespaces

This will open a Github VSCode Interface on the cloud for you. This setup will have the Formbricks codebase, all the dependencies installed & Formbricks running. Click the button below to configure your instance and open the project in Github Codespaces. For a detailed guide, visit the Github Codespaces Setup Guide section below.

Open in Github Codespaces

Local Machine

This will install the Formbricks codebase and all the dependencies on your local machine. Note that this method is recommended only for advanced users. If you're an advanced user, access the steps for Local Machine Setup here below.

Gitpod Guide

Building custom image for the workspace:

  • This includes : Installing yq and turbo globally before the workspace starts. This is accomplished within the .gitpod.Dockerfile along with starting upon a base custom image building on workspace-full.

Initialization of Formbricks:

  • During the prebuilds phase, we initialize Formbricks by performing the following tasks:
    1. Setting up environment variables.
    2. Installing monorepo dependencies.
    3. Installing Docker images by extracting them from the packages/database/docker-compose.yml file.
    4. Building the @formbricks/js component.
  • When the workspace starts:
    1. Wait for the web and demo apps to launch on Gitpod. This automatically opens the apps/demo/.env file. Utilize dynamic localhost URLs (e.g., localhost:3000 for signup and localhost:8025 for email confirmation) to configure NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID. After creating your account and finding the ID in the URL at localhost:3000, replace YOUR_ENVIRONMENT_ID in the .env file located in app/demo.

Web Component Initialization:

  • We initialize the @formbricks/web component during prebuilds. This involves:
    1. Installing build dependencies for the @formbricks/web#go task from turbo.json in prebuilds to save time.
    2. Starting PostgreSQL and Mailhog containers for running migrations in prebuilds.
    3. To prevent the "Init" task from running indefinitely due to prebuild rules, a cleanup docker compose down step i.e. db:down is added to turbo.json. This step is designed to halt the execution of containers that are currently running.
  • When the workspace starts:
    1. Initializing environment variables.
    2. Replacing NEXT_PUBLIC_WEBAPP_URL and NEXTAUTH_URL to take in Gitpod URL's ports when running on VSCode browser.
    3. Starting the @formbricks/web dev environment.

Demo Component Initialization:

  • Similar to the web component, the demo component is also initialized during prebuilds. This includes:
    1. Installing build dependencies for the formbricks/demo#go task from turbo.json in prebuilds to save time.
    2. Caching hits and replaying builds from the @formbricks/js component.
  • When the workspace starts:
    1. Initializing environment variables.
    2. Replaces NEXT_PUBLIC_FORMBRICKS_API_HOST to take in Gitpod URL's ports when running on VSCode browser.
    3. Starting the @formbricks/demo dev environment.

Github Prebuilds Configuration:

  • This configures Github Prebuilds for the master branch, pull requests, and adding comments. This helps automate the prebuild process for the specified branches and actions.

VSCode Extensions:

  • This includes a list of VSCode extensions that are added to the configuration when using Gitpod. These extensions can enhance the development experience within Gitpod.

1. Browser Redirection

After clicking the one-click setup button, Gitpod will open a new tab or window. Please ensure that your browser allows redirection to successfully access the services:

2. Authorizing in Gitpod

Gitpod Auth Page
  • This is the Gitpod Authentication Page. It appears when you click the "Open in GitPod" button and Gitpod needs to authenticate your access to the workspace. Click on 'Continue With Github' to authorize your GitPod session.

3. Creating a New Workspace

Gitpod New workspace Page
  • After authentication, Gitpod asks to create a new workspace for you. This page displays the configurations of your workspace. - You can use either choose either VS Code Browser or VS Code Desktop editor with the 'Standard Class' for your workspace class. - If you opt for the VS Code Desktop, follow the following steps 1. Gitpod will prompt you to grant access to the VSCode app. Once approved, install the GitPod extension from the VSCode Marketplace and follow the prompts to authorize the integration. 2. Change the WEBAPP_URL and the NEXTAUTH_URL to https://localhost:3000

4. Gitpod preparing the created Workspace

Gitpod Preparing workspace Page
  • Gitpod is preparing your workspace with all the necessary dependencies and configurations. You will see this page while Gitpod sets up your development environment.

5. Gitpod running the Workspace

Gitpod Running Workspace Page
  • Once the workspace is fully prepared, voila, it enters the running state. You can start working on your project in this environment.

Ports and Services

Here are the ports and corresponding URLs for the services within your Gitpod environment:

  • Port 3000:

    • Service: Demo App
    • Description: This port hosts the demo application of your project. You can access and interact with your application's demo by navigating to this port.
  • Port 3001:

    • Service: Formbricks website
    • Description: This port hosts the Formbricks website, which contains documents, pricing, blogs, best practices, and concierge service.
  • Port 3002:

    • Service: Formbricks In-product Survey Demo App
    • Description: This app helps you test your app & website surveys. You can create and test user actions, create and update user attributes, etc.
  • Port 5432:

    • Service: PostgreSQL Database Server
    • Description: The PostgreSQL DB is hosted on this port.
  • Port 1025:

    • Service: SMTP server
    • Description: SMTP Server for sending and receiving email messages. This server is responsible for handling email communication.
  • Port 8025:

    • Service: Mailhog

Accessing port URLs

  1. Direct URL Composition:
  • You can access the dedicated port URL by pre-pending the port number to the workspace URL.
  • For example, if you want to access port 3000, you can use the URL format: 3000-yourworkspace.ws-eu45.gitpod.io.
  1. Using gp CLI:
  • Gitpod provides a convenient command, gp url, to quickly retrieve the URL for a specific port.
  • Simply use the command followed by the desired port number. For example, to get the URL for port 3000, run: gp url 3000.
  1. Listing All Open Port URLs:
  • If you prefer to see a list of all open port URLs at once, you can use the gp ports list command.
  • Running this command will display a list of ports along with their corresponding URLs.
  1. Viewing All Ports in Panel:
  • Gitpod also offers a user-friendly 'Ports' tab in the Gitpod panel.
  • Click on the 'Ports' tab to view a list of all open ports and their respective URLs.
Gitpod Ports tab

These URLs and port numbers represent various services and endpoints within your Gitpod environment. You can access and interact with these services by the Port URL for the respective service.


Github Codespaces Guide

  1. After clicking the one-click setup button, you will be redirected to the Github Codespaces page. Review the configuration and click on the 'Create Codespace' button to create a new Codespace.
New Github Codespace
  1. This will start loading the Codespace. Keep in mind this might take a few minutes to complete depending on your internet connection and the instance availability.
Loading Github Codespace
  1. Once the Codespace is loaded, you will be redirected to the VSCode editor. You can start working on your project in this environment.

  2. Monitor the logs in the terminal and once you see the following, you are good to go!

The WebApp is running

@formbricks/web:dev:    Next.js 13.5.6
@formbricks/web:dev:   - Local:        http://localhost:3000
@formbricks/web:dev:   - Environments: .env
@formbricks/web:dev:   - Experiments (use at your own risk):
@formbricks/web:dev:      · serverActions
@formbricks/web:dev:
@formbricks/web:dev:   Ready in 9.4s
  1. Right next to the Terminal, you will see a Ports tab, click on it to see the ports and their respective URLs. Now access the Forwarded Address for port 3000 and you should be able to visit your Formbricks App!
Github Codespace Ports

Now make the changes you want to and see them live in action!


Local Machine Setup

To get the project running locally on your machine you need to have the following development tools installed:

  • Node.JS (we recommend v20)
  • pnpm
  • Docker (to run PostgreSQL / MailHog)
  1. Clone the project & move into the directory:

Git clone Formbricks monorepo

git clone https://github.com/formbricks/formbricks && cd formbricks
  1. Install Node.JS packages via pnpm. Don't have pnpm? Get it here

Install dependencies via pnpm

pnpm install
  1. Create a .env file based on .env.example. It's already preset to work with the local development setup but you can also change values if needed.

Define environment variables

cp .env.example .env
  1. Generate & set some secret values mandatory for the ENCRYPTION_KEY & NEXTAUTH_SECRET in the .env file. You can use the following command to generate the random string of required length:

Set value of ENCRYPTION_KEY

sed -i '/^ENCRYPTION_KEY=/c\ENCRYPTION_KEY='$(openssl rand -hex 32) .env
sed -i '/^NEXTAUTH_SECRET=/c\NEXTAUTH_SECRET='$(openssl rand -hex 32) .env
  1. Make sure you have Docker & docker-compose installed and running on your machine. Then run the following command to start the Formbricks dev setup:

Start Formbricks Dev Setup

pnpm go

This starts the Formbricks main app (plus all its dependencies) as well as the following services using Docker:

  • A postgres container for hosting your database,
  • A mailhog container that acts as a mock SMTP server and shows received mails in a web UI (forwarded to your host's localhost:8025)
  • Demo App at http://localhost:3002
  • Landing Page at http://localhost:3001

You can now access the Formbricks app on http://localhost:3000. You will be automatically redirected to the login. To use your local installation of formbricks, create a new account.

For viewing the emails sent by the system, you can access mailhog at http://localhost:8025

Build

To build all apps and packages and check for build errors, run the following command:

Build Formbricks stack

pnpm build

Troubleshooting

Here you'll find help with frequently recurring problems

"The app doesn't work after doing a prisma migration"

This can happen but fear not, the fix is easy: Delete the application storage of your browser and reload the page. This will force the app to re-fetch the data from the server:

Demo App Preview

"I ran 'pnpm i' but there seems to be an error with the packages"

If nothing helps, run pnpm clean and then pnpm i again. This solves a lot.

"I get a full-screen error with cryptic strings"

This usually happens when the Formbricks Widget wasn't correctly or completely built.

Build js library first and then run again

pnpm build --filter=@formbricks/js

// Run the app again
pnpm dev

My machine struggles with the repository

Since we're working with a monorepo structure, the repository can get quite big. If you're having trouble working with the repository, try the following:

Only run the required project

pnpm dev --filter=@formbricks/web...

However, in our experience it's better to run pnpm dev than having two terminals open (one with the Formbricks app and one with the demo).

Uncaught (in promise) SyntaxError: Unexpected token !DOCTYPE ... is not valid JSON

Uncaught promise

This happens when you're using the Demo App and delete the Person within the Formbricks app which the widget is currently connected with. We're fixing it, but you can also just logout your test person and reload the page to get rid of it.

Logout Person

Was this page helpful?