# blade47/dub Wiki ## Technical docs: dub API URL: https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/api/api-overview # dub API **Version:** inferred **147** endpoints detected from `(inferred from code)` ## Endpoints ### Admin | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/admin/analytics` | Get analytics for admin | | `POST` | `/api/admin/ban` | Ban a user and their associated workspaces | | `GET` | `/api/admin/commissions` | Get commissions for admin | | `POST` | `/api/admin/domains/refresh` | Refresh domain on Vercel | | `POST` | `/api/admin/domains/register-premium` | Register premium domain | | `POST` | `/api/admin/domains/renew` | Renew domain | | `GET` | `/api/admin/domains/search-availability` | Search domain availability | | `GET` | `/api/admin/events` | Get events for admin | | `PATCH` | `/api/admin/fraud-alerts/{fraudAlertId}` | Update fraud alert status | | `POST` | `/api/admin/impersonate` | Impersonate user or workspace | | `DELETE` | `/api/admin/links/ban` | Ban link | | `GET` | `/api/admin/links/count` | Count links | | `GET` | `/api/admin/links` | Get admin links | | `POST` | `/api/admin/partners/{partnerId}/generate-veriff-session` | Generate Veriff session | | `PATCH` | `/api/admin/partners/{partnerId}/network-status` | Update partner network status | | `POST` | `/api/admin/partners/{partnerId}/platforms` | Add or update partner platform | | `GET` | `/api/admin/partners/{partnerId}` | Get admin partner details | | `PATCH` | `/api/admin/partners/{partnerId}` | Update partner country | | `GET` | `/api/admin/partners/{partnerId}/shared-platforms` | Get shared platforms | | `POST` | `/api/admin/partners/{partnerId}/verify-identity` | Verify partner identity | | `POST` | `/api/admin/partners/delete-account` | Delete partner account | | `GET` | `/api/admin/partners/fraud` | Get fraud alerts | | `GET` | `/api/admin/partners/network` | Get network partners count or list | | `GET` | `/api/admin/partners/trusted` | Get trusted partners | | `POST` | `/api/admin/partners/trusted` | Mark partner as trusted | | `DELETE` | `/api/admin/partners/trusted` | Remove partner trusted status | | `GET` | `/api/admin/payouts/paypal` | Get pending PayPal payouts | | `GET` | `/api/admin/payouts` | Get admin payouts and timeseries | | `GET` | `/api/admin/payouts/stablecoin` | Get stablecoin payouts | | `PATCH` | `/api/admin/programs/{programId}` | Update marketplace program details | | `DELETE` | `/api/admin/programs/{programId}` | Remove program from marketplace | | `POST` | `/api/admin/programs/delete` | Completely delete a program | | `GET` | `/api/admin/programs/recent` | Get recent programs | | `GET` | `/api/admin/programs` | Get marketplace programs | | `POST` | `/api/admin/programs` | Add program to marketplace | | `PATCH` | `/api/admin/programs` | Reorder marketplace programs | | `GET` | `/api/admin/programs/sales` | Get top programs by sales | | `POST` | `/api/admin/reset-login-attempts` | Reset user login attempts | | `GET` | `/api/admin/revenue` | Get admin revenue timeseries | | `POST` | `/api/admin/slack-support-invite` | Send Slack Connect invite | | `POST` | `/api/admin/workspaces/disable` | Disable a workspace | | `POST` | `/api/admin/workspaces/restore` | Restore a workspace | ### Webhooks | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/appsflyer/webhook` | AppsFlyer Webhook Handler (GET) | | `HEAD` | `/api/appsflyer/webhook` | AppsFlyer Webhook Handler (HEAD) | ### Audit Logs | Method | Path | Description | |--------|------|-------------| | `POST` | `/api/audit-logs/export` | Export audit logs to CSV | ### Auth | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/auth/saml/authorize` | SAML Authorize (GET) | | `POST` | `/api/auth/saml/authorize` | SAML Authorize (POST) | | `POST` | `/api/auth/saml/callback` | SAML Callback | | `POST` | `/api/auth/saml/token` | SAML Token | | `GET` | `/api/auth/saml/userinfo` | SAML User Info | | `POST` | `/api/auth/saml/verify` | Verify SAML connection for workspace | ### Bounties | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/bounties/{bountyId}` | Get a bounty | | `PATCH` | `/api/bounties/{bountyId}` | Update a bounty | | `DELETE` | `/api/bounties/{bountyId}` | Delete a bounty | | `POST` | `/api/bounties/{bountyId}/submissions/{submissionId}/approve` | Approve a submission | | `POST` | `/api/bounties/{bountyId}/submissions/{submissionId}/reject` | Reject a submission | | `GET` | `/api/bounties/{bountyId}/submissions` | Get all submissions for a bounty | | `POST` | `/api/bounties/{bountyId}/sync-social-metrics` | Sync social metrics for a bounty | | `GET` | `/api/bounties/count/submissions` | Get total bounty submissions count | | `GET` | `/api/bounties` | Get all bounties for a program | | `POST` | `/api/bounties` | Create a bounty | ### Campaigns | Method | Path | Description | |--------|------|-------------| | `POST` | `/api/campaigns/{campaignId}/duplicate` | Duplicate an existing campaign | | `GET` | `/api/campaigns/{campaignId}/events/count` | Get campaign events count | | `GET` | `/api/campaigns/{campaignId}/events` | Get campaign events | | `POST` | `/api/campaigns/{campaignId}/preview` | Send preview email for a campaign | | `GET` | `/api/campaigns/{campaignId}` | Get an email campaign | | `PATCH` | `/api/campaigns/{campaignId}` | Update an email campaign | | `DELETE` | `/api/campaigns/{campaignId}` | Delete a campaign | | `GET` | `/api/campaigns/{campaignId}/summary` | Get campaign summary | | `GET` | `/api/campaigns/count` | Get campaigns count | | `GET` | `/api/campaigns` | Get all campaigns | | `POST` | `/api/campaigns` | Create campaign | ### Cloudflare | Method | Path | Description | |--------|------|-------------| | `POST` | `/api/cloudflare/webhook/r2-object-created` | R2 Object Created Webhook | ### Commissions | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/commissions/{commissionId}` | Get commission by ID | | `PATCH` | `/api/commissions/{commissionId}` | Update commission | | `GET` | `/api/commissions/analytics` | Get commission analytics | | `PATCH` | `/api/commissions/bulk` | Bulk update commission status | | `GET` | `/api/commissions/count` | Get commissions count | | `GET` | `/api/commissions/export` | Export commissions | | `GET` | `/api/commissions` | Get all commissions | | `POST` | `/api/commissions` | Create manual commission | ### Cron | Method | Path | Description | |--------|------|-------------| | `POST` | `/api/cron/aggregate-clicks` | Aggregate click events | | `POST` | `/api/cron/bounties/notify-partners` | Notify partners about new bounty | | `GET` | `/api/cron/bounties/queue-sync-social-metrics` | Queue social metrics sync | | `POST` | `/api/cron/bounties/sync-social-metrics` | Sync social metrics for a bounty | | `POST` | `/api/cron/bounties/upsert-draft-submissions` | Upsert draft bounty submissions | | `POST` | `/api/cron/campaigns/broadcast` | Broadcast campaigns | | `GET` | `/api/cron/campaigns/queue-scheduled` | Queue scheduled campaigns | | `POST` | `/api/cron/cleanup/declined-invites` | Cleanup declined invites | | `POST` | `/api/cron/cleanup/demo-embed-partners` | Cleanup demo embed partners | | `POST` | `/api/cron/cleanup/e2e-tests` | Cleanup E2E test data | | `POST` | `/api/cron/cleanup/expired-fraud-groups` | Cleanup expired fraud groups | | `POST` | `/api/cron/cleanup/expired-tokens` | Cleanup expired tokens | | `POST` | `/api/cron/cleanup/link-retention` | Cleanup links based on retention days | | `POST` | `/api/cron/cleanup/orphaned` | Cleanup orphaned records | | `POST` | `/api/cron/cleanup/rejected-applications` | Cleanup rejected program applications | | `POST` | `/api/cron/cleanup/unenrolled-partners` | Cleanup unenrolled partners | | `POST` | `/api/cron/commissions/referrals/backfill` | Backfill referral commissions | | `POST` | `/api/cron/commissions/referrals/create` | Create referral commission | | `POST` | `/api/cron/commissions/referrals/queue` | Queue referral commissions for payout | | `POST` | `/api/cron/discount-codes/create` | Drain shim for discount code creation ~~deprecated~~ | | `POST` | `/api/cron/discount-codes/disable` | Disable discount code | | `POST` | `/api/cron/disposable-emails` | Sync disposable and Tremendous prohibited email domains | | `GET` | `/api/cron/domains/renewal-payments` | Create payment intents for domain renewals | | `GET` | `/api/cron/domains/renewal-reminders` | Send domain renewal reminders | | `POST` | `/api/cron/domains/renewal-succeeded` | Renew domains for a given invoice | | `POST` | `/api/cron/domains/transfer` | Transfer domain between workspaces | | `POST` | `/api/cron/domains/update` | Update links associated with a domain update | | `GET` | `/api/cron/domains/verify` | Check domain verification status | | `POST` | `/api/cron/email-domains/update` | Update Resend domain click tracking | | `GET` | `/api/cron/email-domains/verify` | Verify email domains | | `POST` | `/api/cron/export/commissions` | Export commissions worker | | `POST` | `/api/cron/export/customers/partner` | Export partner customers worker | | `POST` | `/api/cron/export/customers` | Export workspace customers worker | | `POST` | `/api/cron/export/events/partner` | Export partner events worker | | `POST` | `/api/cron/import/csv` | Import links from CSV | | `POST` | `/api/cron/import/firstpromoter` | Import from FirstPromoter | | `POST` | `/api/cron/import/lemonsqueezy` | Import from Lemon Squeezy | | `POST` | `/api/cron/import/partnerstack` | Import from PartnerStack | | `POST` | `/api/cron/import/rebrandly` | Import from Rebrandly | | `POST` | `/api/cron/import/rewardful` | Import from Rewardful | | `POST` | `/api/cron/import/short` | Import from Short.io | ### General | Method | Path | Description | |--------|------|-------------| | `POST` | `/api/cron/export/events/workspace` | Process large event exports | | `POST` | `/api/cron/export/links` | Process large link exports | | `POST` | `/api/cron/export/partners` | Process large partner exports | | `POST` | `/api/cron/export/payouts` | Process large payout exports | | `POST` | `/api/cron/framer/backfill-leads-batch` | Backfill framer leads batch | | `POST` | `/api/cron/fraud/release-all-hold-commissions` | Release all hold commissions | | `POST` | `/api/cron/fraud/release-hold-commissions` | Release hold commissions | ### cron | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/cron/fraud/summary` | Fraud events summary cron | | `POST` | `/api/cron/fraud/summary` | Fraud events summary cron | | `POST` | `/api/cron/fx-rates` | FX rates update cron | | `POST` | `/api/cron/groups/create-default-links` | Create default links cron | | `POST` | `/api/cron/groups/remap-default-links` | Remap default links cron | | `POST` | `/api/cron/groups/update-default-links` | Update default links cron | | `POST` | `/api/cron/import/bitly` | Import links from Bitly | | `POST` | `/api/cron/import/tapfiliate` | Import Tapfiliate data | | `POST` | `/api/cron/import/tolt` | Import Tolt data | | `POST` | `/api/cron/invoices/retry-failed` | Retry failed invoice | | `POST` | `/api/cron/links/{linkId}/complete-tests` | Complete link AB tests | | `POST` | `/api/cron/links/delete` | Delete unclaimed demo link | | `POST` | `/api/cron/links/invalidate-for-partners` | Invalidate partner links cache | | `POST` | `/api/cron/messages/notify-partner` | Notify partner of unread messages | | `POST` | `/api/cron/messages/notify-program` | Notify program of unread messages | | `POST` | `/api/cron/network/calculate-program-similarities` | Calculate program similarities | | `POST` | `/api/cron/partner-platforms` | Update verified partner platforms | ### embed | Method | Path | Description | |--------|------|-------------| | `GET` | `/api/embed/referrals/token` | Get referrals embed token | --- ## Technical docs: Overview URL: https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/getting-started/overview
Relevant source files The following files were used as context for generating this wiki page: - [apps/web/lib/dub.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/dub.ts) - [apps/web/lib/middleware/link.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/middleware/link.ts) - [apps/web/ui/placeholders/features-section.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/ui/placeholders/features-section.tsx) - [apps/web/scripts/dev/data.json](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/scripts/dev/data.json) - [apps/web/middleware.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/middleware.ts) - [apps/web/app/app.dub.co/dashboard/slug/ee/program/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/app.dub.co/(dashboard)/%5Bslug%5D/(ee)/program/page.tsx) - [apps/web/app/ee/app.dub.co/embed/referrals/quickstart.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/(ee)/app.dub.co/embed/referrals/quickstart.tsx) - [apps/web/app/domain/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/%5Bdomain%5D/page.tsx) - [packages/stripe-app/src/utils/constants.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/stripe-app/src/utils/constants.ts) - [apps/web/app/ee/partners.dub.co/dashboard/referrals/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/(ee)/partners.dub.co/(dashboard)/referrals/page.tsx) - [packages/hubspot-app/src/app/app-hsmeta.json](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/hubspot-app/src/app/app-hsmeta.json) - [apps/web/app/domain/disabled/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/%5Bdomain%5D/disabled/page.tsx) - [packages/utils/src/constants/main.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/utils/src/constants/main.ts) - [apps/web/app/app.dub.co/onboarding/onboarding/steps/welcome/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/welcome/page.tsx) - [packages/email/src/templates/broadcasts/dub-product-update-mar26.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/email/src/templates/broadcasts/dub-product-update-mar26.tsx) - [apps/web/app/ee/partners.dub.co/dashboard/programs/programSlug/enrolled/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/%5BprogramSlug%5D/(enrolled)/page.tsx) - [apps/web/app/api/dub/webhook/route.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/api/dub/webhook/route.ts) - [apps/web/ui/layout/sidebar/dub-partners-popup.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/ui/layout/sidebar/dub-partners-popup.tsx) - [apps/web/lib/webhook/sample-events/link-clicked.json](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/webhook/sample-events/link-clicked.json) - [apps/web/ui/placeholders/cta.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/ui/placeholders/cta.tsx) - [packages/utils/src/constants/dub-domains.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/utils/src/constants/dub-domains.ts) - [apps/web/app/ee/app.dub.co/new-program/slug/program/new/overview/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/(ee)/app.dub.co/(new-program)/%5Bslug%5D/program/new/overview/page.tsx) - [packages/ui/src/nav/content/product-content.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/ui/src/nav/content/product-content.tsx) - [apps/web/lib/auth/track-dub-lead.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/auth/track-dub-lead.ts) - [packages/ui/src/nav/content/solutions-content.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/ui/src/nav/content/solutions-content.tsx) - [apps/web/app/app.dub.co/onboarding/onboarding/steps/products/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/products/page.tsx) - [apps/web/scripts/dub-wrapped.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/scripts/dub-wrapped.ts) - [apps/web/app/app.dub.co/dashboard/slug/links/page.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/app.dub.co/(dashboard)/%5Bslug%5D/links/page.tsx) - [packages/cli/src/index.ts](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/cli/src/index.ts) - [packages/email/src/templates/broadcasts/dub-product-update-summer26.tsx](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/email/src/templates/broadcasts/dub-product-update-summer26.tsx)
## Overview Dub is a comprehensive open-source link management and attribution platform engineered for modern marketing teams and high-scale applications. It provides robust infrastructure for shortening and dispatching URLs, capturing real-time click and conversion analytics, and running automated [Partner Programs](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/partner-programs/partner-programs) with customizable affiliate rewards. The custom domain home page `apps/web/app/domain/page.tsx` renders a branded welcome experience and features section for custom domains; see [Link Dispatch](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/link-attribution/link-dispatch) for link routing and resolution mechanisms. The partner program enrolled page `apps/web/app/ee/partners.dub.co/dashboard/programs/programSlug/enrolled/page.tsx` renders performance metrics and referral links for affiliates; see [Partner Programs](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/partner-programs/partner-programs) for details on enrollment and program participation. Sources: [packages/hubspot-app/src/app/app-hsmeta.json:5](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/hubspot-app/src/app/app-hsmeta.json#L5-L5), [apps/web/app/domain/page.tsx:18](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/%5Bdomain%5D/page.tsx#L18-L18) ## Platform scope and primary capabilities ### Core Product Modules and Capabilities Dub functions as a unified engine combining advanced URL management, real-time analytics, and automated partner marketing infrastructure. The platform organizes its core capabilities around three foundational product pillars: [Link Dispatch](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/link-attribution/link-dispatch) via [Domain Management](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/link-attribution/domain-management), [Analytics Dashboard](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/analytics-pipeline/analytics-dashboard) telemetry, and [Partner Programs](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/partner-programs/partner-programs) with automated [Commission Engine](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/billing-and-payouts/commission-engine) payouts. Marketing teams utilize custom domains such as `dub.sh` along with pre-configured branded slugs including `chatg.pt`, `spti.fi`, `git.new`, `cal.link`, `amzn.id`, `ggl.link`, and `fig.page` to establish trust and improve click-through rates. Sources: [packages/utils/src/constants/main.ts:1](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/utils/src/constants/main.ts#L1-L1), [packages/utils/src/constants/dub-domains.ts:3-134](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/utils/src/constants/dub-domains.ts#L3-L134), [packages/ui/src/nav/content/product-content.tsx:42-55](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/ui/src/nav/content/product-content.tsx#L42-L55) The platform exposes its capabilities through structured navigation components and feature suites that span link shortening, audience analytics, and partner management. | Product Module | Core Functionality | Primary Target Domain / Route | | :--- | :--- | :--- | | **Dub Links** | Short links with personalization, device targeting, geo-targeting, link cloaking, and password protection | `/links` | | **Dub Analytics** | Instant telemetry covering geolocation, device, browser, and referrer data streams | `/analytics` | | **Dub Partners** | Automated affiliate program management, partner onboarding, and revenue attribution | `/partners` | | **Dub Integrations** | External tool connections and data synchronization across ecosystem apps | `/integrations` | | **Dub API & MCP** | Programmatic access via public REST endpoints and AI agent connectivity | `/docs/api-reference/introduction` | Sources: [apps/web/ui/placeholders/features-section.tsx:66-103](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/ui/placeholders/features-section.tsx#L66-L103), [packages/ui/src/nav/content/product-content.tsx:13-82](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/ui/src/nav/content/product-content.tsx#L13-L82) > [!NOTE] > When new users complete account onboarding, the platform prompts them to define their primary intent via the product selection step, routing them toward link management, analytics tracking, or partner program creation depending on their business objectives. Sources: [apps/web/app/app.dub.co/onboarding/onboarding/steps/products/page.tsx:5-15](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/products/page.tsx#L5-L15) ## Monorepo subsystems and application topology ### Architecture and Shared Packages Dub is organized as a Turborepo monorepo encompassing web applications, specialized marketplace integrations, developer utilities, and email templates. The primary web surface executes on Next.js with a Node.js middleware runtime defined in `apps/web/middleware.ts`, which inspects incoming requests and routes them across administrative, partner portal, and link-dispatch handlers. ```typescript export const config = { runtime: "nodejs", matcher: [ /* * Match all paths except for: * 1. /api/ routes * 2. /_next/ (Next.js internals) * 3. /_proxy/ (proxies for third-party services) * 4. Metadata files: favicon.ico, sitemap.xml, robots.txt, manifest.webmanifest */ "/((?!api/|_next/|_proxy/|favicon.ico|sitemap.xml|robots.txt|manifest.webmanifest).*)", ], }; ``` Sources: [apps/web/middleware.ts:20-32](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/middleware.ts#L20-L32) > [!WARNING] > The Next.js middleware explicitly bypasses `/api/`, `/_next/`, `/_proxy/`, and static metadata files (`favicon.ico`, `sitemap.xml`, `robots.txt`, `manifest.webmanifest`) via its matcher configuration to ensure low-latency request handling for link redirects. Sources: [apps/web/middleware.ts:20-32](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/middleware.ts#L20-L32) ### Developer Tooling and Marketplace Extensions The monorepo bundles dedicated integration packages and command-line utilities. The `packages/cli` package implements a Commander.js-based terminal interface (`dub`) supporting commands for authentication, configuration, domain management, short link creation, and link listing. ```typescript const program = new Command() .name("dub") .description("A CLI for shortening links with the Dub API.") .version( packageInfo.version || "1.0.0", "-v, --version", "display the version number", ); program .addCommand(login) .addCommand(config) .addCommand(domains) .addCommand(shorten) .addCommand(links); ``` Sources: [packages/cli/src/index.ts:17-31](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/cli/src/index.ts#L17-L31) Ecosystem apps are packaged independently, such as `packages/stripe-app` for Stripe merchant dashboard integration and `packages/hubspot-app` for HubSpot CRM contact and deal synchronization. | Package / App | Purpose | Key Constants or Manifest Settings | | :--- | :--- | :--- | | **`apps/web`** | Core web application and edge routing middleware | Runtime: `nodejs`, Matcher excludes `/api/`, `/_next/`, `/_proxy/` | | **`packages/cli`** | Developer [CLI Tool](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/administration-and-api/cli-tool) for terminal-based link operations | Program name: `dub`, Commands: `login`, `config`, `domains`, `shorten`, `links` | | **`packages/stripe-app`** | Stripe integration utility for client IDs and API hosts | `DUB_CLIENT_ID`, `DUB_HOST`, `DUB_API_HOST` | | **`packages/hubspot-app`** | HubSpot app metadata and OAuth configuration | UID: `dub`, Scopes: `oauth`, `crm.objects.contacts.read`, `crm.objects.deals.read` | | **`packages/email`** | React-email templates for product updates and broadcasts | Templates: `DubProductUpdateMar26`, `DubProductUpdateSummer26` | Sources: [apps/web/middleware.ts:20-32](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/middleware.ts#L20-L32), [packages/stripe-app/src/utils/constants.ts:2-5](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/stripe-app/src/utils/constants.ts#L2-L5), [packages/hubspot-app/src/app/app-hsmeta.json:2-20](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/hubspot-app/src/app/app-hsmeta.json#L2-L20), [packages/cli/src/index.ts:17-31](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/cli/src/index.ts#L17-L31), [packages/email/src/templates/broadcasts/dub-product-update-summer26.tsx:18-24](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/packages/email/src/templates/broadcasts/dub-product-update-summer26.tsx#L18-L24) ## Edge request processing and analytics ### Middleware Routing and Link Resolution The root middleware in `apps/web/middleware.ts` intercepts inbound requests, checks hostnames, and dispatches traffic to specialized handlers [Request Routing](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/core-architecture/request-routing). Requests targeting application hostnames or admin consoles route to `AppMiddleware` or `AdminMiddleware`, whereas link traffic is processed by `LinkMiddleware` defined in `apps/web/lib/middleware/link.ts`. ```typescript export default async function middleware(req: NextRequest, ev: NextFetchEvent) { const { domain, path, key, fullKey } = parse(req); // Axiom logging logger.info(...transformMiddlewareRequest(req)); ev.waitUntil(logger.flush()); // for app.dub.co if (isAppHostname(domain)) { return AppMiddleware(req); } // for api.dub.co if (API_HOSTNAMES.has(domain)) { return ApiMiddleware(req); } // for public stats pages (e.g. d.to/stats/try -> rewrite to [/domain]/[key]/stats) if (path.startsWith("/stats/")) { return NextResponse.rewrite( new URL( `/${domain}/${encodeURIComponent(path.replace("/stats/", ""))}/stats`, req.url, ), ); } // for .well-known routes if (path.startsWith("/.well-known/")) { const file = path.split("/.well-known/").pop(); if (file && supportedWellKnownFiles.includes(file)) { return NextResponse.rewrite( new URL(`/wellknown/${domain}/${file}`, req.url), ); } } // default redirects for dub.sh if (domain === "dub.sh" && DEFAULT_REDIRECTS[key]) { return NextResponse.redirect(DEFAULT_REDIRECTS[key]); } if (ADMIN_HOSTNAMES.has(domain)) { return AdminMiddleware(req); } if (PARTNERS_HOSTNAMES.has(domain)) { return PartnersMiddleware(req); } if (isValidUrl(fullKey)) { return CreateLinkMiddleware(req); } return LinkMiddleware(req, ev); ``` Sources: [apps/web/middleware.ts:34-88](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/middleware.ts#L34-L88) `LinkMiddleware` parses the domain and short key, enforces case sensitivity based on domain configuration, strips inspect-mode suffixes (`+`), and handles root links (`_root`). Unsupported keys like `.php` trigger an immediate redirect with a `dub-no-track=1` query parameter and a `googlebot: noindex` robots header. ```typescript export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) { let { domain, fullKey: originalKey, fullPath, searchParamsObj } = parse(req); if (!domain) { return NextResponse.next(); } // encode the key to ascii // links on Dub are case insensitive by default let key = punyEncode(originalKey); if (!isCaseSensitiveDomain(domain)) { key = key.toLowerCase(); } const inspectMode = key.endsWith("+"); // if inspect mode is enabled, remove the trailing `+` from the key if (inspectMode) { key = key.slice(0, -1); } // if key is empty string, set to _root (root domain link) if (key === "") { key = "_root"; } const STATIC_PAGES_CACHE_HEADERS = { "Vercel-CDN-Cache-Control": "public, s-maxage=86400", "Vercel-Cache-Tag": linkCache._createStaticPagesCacheKeys({ domain, key: originalKey || "_root", }), }; // we don't support .php links (too much bot traffic) // hence we redirect to the root domain and add `dub-no-track` header to avoid tracking bot traffic if (isUnsupportedKey(key)) { return NextResponse.redirect(new URL("/?dub-no-track=1", req.url), { headers: { ...DUB_HEADERS, "X-Robots-Tag": "googlebot: noindex", }, status: 302, }); } ``` Sources: [apps/web/lib/middleware/link.ts:43-87](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/middleware/link.ts#L43-L87) > [!WARNING] > The middleware skips click tracking during Redis failover events by evaluating `redisFailOver`, falling back to a no-op handler to prevent request timeouts and cascading latency degradation [Caching & Rate Limiting](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/core-architecture/caching-rate-limiting). Sources: [apps/web/lib/middleware/link.ts:89-99](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/middleware/link.ts#L89-L99) ### Caching and Telemetry Streaming When a short link is requested, `LinkMiddleware` queries Redis cache via `linkCache.get`. If the link is missing, it fetches record data via `getLinkViaEdge` from PlanetScale [Database Architecture](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/core-architecture/database-architecture). If the domain is `buff.ly`, it invokes `crawlBitly`; otherwise, it returns a 404 rewrite [Data Importers](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/integrations-subsystem/data-importers). ```typescript if (!cachedLink) { let linkData = await getLinkViaEdge({ domain, key, }); if (!linkData) { if (domain === "buff.ly") { return await crawlBitly(req, ev); } return NextResponse.rewrite(new URL(`/${domain}/notfound`, req.url), { headers: { ...DUB_HEADERS, ...STATIC_PAGES_CACHE_HEADERS, }, }); } ``` Sources: [apps/web/lib/middleware/link.ts:100-117](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/middleware/link.ts#L100-L117) For partner links, the middleware fetches partner enrollment info and caches the enriched link object using `ev.waitUntil` to avoid blocking the synchronous response path. ```typescript isPartnerLink = Boolean(linkData.programId && linkData.partnerId); // format link to fit the RedisLinkProps interface cachedLink = formatRedisLink(linkData as any); ev.waitUntil( (async () => { if (!isPartnerLink) { await linkCache.set(linkData as any, { skipRevalidateTag: true }); return; } const { partner, discount } = await getPartnerEnrollmentInfo({ programId: linkData.programId, partnerId: linkData.partnerId, linkId: linkData.id, }); // we'll use this data on /track/click await linkCache.set( { ...(linkData as any), ...(partner && { partner }), ...(discount && { discount }), }, { skipRevalidateTag: true }, ); })(), ); } ``` Sources: [apps/web/lib/middleware/link.ts:119-148](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/lib/middleware/link.ts#L119-L148) | Middleware Handler | Target Condition | Action / Destination | | :--- | :--- | :--- | | **`AppMiddleware`** | `isAppHostname(domain)` | Routes to multi-tenant application dashboard | | **`ApiMiddleware`** | `API_HOSTNAMES.has(domain)` | Routes to public [REST API](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/administration-and-api/rest-api) handler | | **`AdminMiddleware`** | `ADMIN_HOSTNAMES.has(domain)` | Routes to internal administrative moderation console | | **`PartnersMiddleware`** | `PARTNERS_HOSTNAMES.has(domain)` | Routes to affiliate partner portal | | **`LinkMiddleware`** | Default link path | Resolves short link, checks cache, and redirects | Sources: [apps/web/middleware.ts:41-88](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/middleware.ts#L41-L88) ## Partner programs and affiliate workflows ### Partner Portal and Onboarding Dub Partners empowers workspaces to establish, manage, and scale affiliate and referral programs [Partner Programs](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/partner-programs/partner-programs). Workspaces that possess program management capabilities can initiate a new program from the workspace dashboard or via the `DubPartnersPopup` overlay [Workspace Subscriptions](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/billing-and-payouts/workspace-subscriptions). The partner portal UI surfaces network referral links, earnings summaries, and active referral tiers. ```tsx const { canManageProgram } = getPlanCapabilities(plan); const [dismissed, setDismissed, { loading: loadingDismissed }] = useWorkspaceStore("dubPartnersPopupDismissed"); if ( // Loading loadingWorkspace || loadingDismissed || // hide if workspace can't create a program !canManageProgram || // hide if there's already a default program defaultProgramId || // don't show on mobile isMobile || // hide if already dismissed dismissed ) return null; return ( setDismissed(true)} /> ); } ``` Sources: [apps/web/ui/layout/sidebar/dub-partners-popup.tsx:36-62](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/ui/layout/sidebar/dub-partners-popup.tsx#L36-L62) Prospective affiliates access network dashboards to track performance statistics and copy unique referral URLs [Embeddable Referrals](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/administration-and-api/embeddable-referrals). If a partner's profile is not yet accepted into the network, a locked state view intercepts direct link generation and prompts the user to apply [Partner Programs](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/partner-programs/partner-programs). ```tsx function ReferralLinkLocked() { return (

Network referral link

Get accepted to the Dub Network to unlock
); } ``` Sources: [apps/web/app/ee/partners.dub.co/dashboard/referrals/page.tsx:262-288](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/(ee)/partners.dub.co/(dashboard)/referrals/page.tsx#L262-L288) > [!NOTE] > Network referral links support deep-linking to any page on the partners domain by appending the `?via=username` query parameter directly to the destination URL [Conversion Tracking](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/analytics-pipeline/conversion-tracking). Sources: [apps/web/app/ee/partners.dub.co/dashboard/referrals/page.tsx:350-370](https://github.com/blade47/dub/blob/7c93d97abf0ecd37fb669c6a68a1f7ef9109daea/apps/web/app/(ee)/partners.dub.co/(dashboard)/referrals/page.tsx#L350-L370) ### Referral Link Construction and Embedded Dashboards Affiliates construct customized links using utility helpers that combine group configurations and destination targets [Embeddable Referrals](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/administration-and-api/embeddable-referrals). The `ReferralsEmbedQuickstart` component guides partners through sharing links, downloading program resources, and configuring payout methods [Payout Settlement](https://www.doc0.dev/docs/934e554a-e6a1-476f-bb2f-23e62d86c3fd/technical/billing-and-payouts/payout-settlement). ```tsx const items = [ { title: "Share your link", description: `Use your ${program.name} link to drive traffic and track every click, lead, and conversion.`, illustration: , cta: (