A guide on how to run Dub.co’s codebase locally.
apps
directory contains the code for:
web
: The entirety of Dub’s application (app.dub.co) + our link redirect infrastructure.docs
: Dub’s documentation site (dub.co/docs) – including this page you’re on right now!packages
directory contains the code for:
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.main
/apps/web/lib/middleware/root.ts.Clone the repo
Install dependencies
Optional: Install Mintlify
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 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:Client ID
and Client Secret
into your .env
file as the GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
environment variables.
apps/web
) will be available at localhost:8888 and the docs (apps/docs
) will be available at localhost:3334.