A guide on how to run Dub’s codebase locally.
apps
directory contains the code for:
web
: The entirety of Dub’s application (app.dub.co) + our link redirect infrastructure.packages
directory contains the code for:
cli
: A CLI for easily shortening URLs with the Dub API.email
: Dub’s email application with function to send emails and templates.embeds
: A package used embed Dub’s referral dashboard.prisma
: Prisma Configuration for Dub’s web-app.stripe-app
: The Stripe app for dub conversions.tailwind-config
: The Tailwind CSS configuration for Dub’s web app.tinybird
: Dub’s Tinybird configuration.tsconfig
: The TypeScript configuration for Dub’s web app.ui
: Dub’s UI component library.utils
: A collection of utility functions and constants used across Dub’s codebase.app.dub.co
workspackages
directory, specifically the @dub/ui
and @dub/utils
packages.
All of the code for the web app is located in here: main
/apps/web/app/app.dub.co. This is using the Next.js route group pattern.
There’s also the API server, which is located in here: main
/apps/web/app/api
When you run pnpm dev
to start the development server, the app will be available at http://localhost:8888. The reason we use localhost:8888
and not app.localhost:8888
is because Google OAuth doesn’t allow you to use localhost subdomains.
main
/apps/web/lib/middleware/link.ts
Clone the repo
Install dependencies
Build internal packages
Set up environment variables
.env.example
file from ./apps/web
to .env
:.env
file with your own values as you progress through the setup.Create Tinybird Workspace
admin
Auth Token. Paste this token as the TINYBIRD_API_KEY
environment variable in your .env
file.Install Tinybird CLI and authenticate
packages/tinybird
directory.Install the Tinybird CLI with pip install tinybird-cli
(requires Python >= 3.8).Run tb auth
and paste your admin
Auth Token.Publish Tinybird datasource and endpoints
tb push
to publish the datasource and endpoints in the packages/tinybird
directory. You should see the following output (truncated for brevity):Set up Tinybird API base URL
TINYBIRD_API_URL
environment variable in your .env
file.Create Upstash database
Set up Upstash Redis environment variables
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
from the REST API section into your .env
file.QSTASH_TOKEN
, QSTASH_CURRENT_SIGNING_KEY
, and QSTASH_NEXT_SIGNING_KEY
from the Request Builder section into your .env
file.Optional: Set up Ngrok tunnel
ngrok
, and then run the following command to start an Ngrok tunnel at port 8888
:https
URL and paste it as the NEXT_PUBLIC_NGROK_URL
environment variable in your .env
file.Spin up the docker-compose stack
apps/web
directory and run the following command to start the Docker Compose stack:Set up database environment variables
.env
file:@planetscale/database
SDK.DATABASE_URL
value.Generate Prisma client and create database tables
apps/web
directory and run the following command to generate the Prisma client:Create PlanetScale database
Set up PlanetScale environment variables
DATABASE_URL
into your .env
file.Generate Prisma client and create database tables
apps/web
directory and run the following command to generate the Prisma client:docker compose up
as part of the database setup, you
can skip this step. Mailhog is included in the Docker Compose configuration
and should already be running.Pull Mailhog Docker image
Start Mailhog container
apps/web
) will be available at localhost:8888.
<shortlink-key>
with the shortlink key you’ve created.