Skip to content
VercelLogotypeVercelLogotype
LoginSign Up

MotherDuck Embedded Dives: vibecodable data apps

Next.js template for user-defined, AI-powered analytics UIs using MotherDuck embedded Dives.

DeployView Demo

Embedded Dives: vibecodable data apps

Dives are code-based, fully customizable React components that can query MotherDuck, a serverless cloud data warehouse powered by DuckDB. Dives lets you build interactive dashboards, presentations, or even data-driven games, all fetching live data through SQL queries. Embedded in your app, Dives give you infinite flexibility over how data is presented, without the constraints of traditional BI tools.

This template gives you a deployable Next.js app where users can browse starter Dives, open full-page previews, and use AI chat to customize a Dive in place.

Live demo →

Features

  • Starter dives: 3 example dives: slides, dashboard, and game mini-apps built on top of NYC 311 data, showed in the Dive gallery page with live previews.
  • AI dive remix workflow: user can explore the underlying data and customize each dive through a natural language interface
  • Auth options: public demo mode with anonymous sessions, password sign-in with one shared MotherDuck account, or password sign-in with each user providing a MotherDuck personal access token
  • AI provider options: Anthropic, OpenAI, or Vercel AI Gateway through Vercel AI SDK

Demo auth note: included auth is for demo purposes. For production use cases, connect your own identity provider and authorization model before shipping.

Deploy

Click Deploy with Vercel. The clone flow provisions:

  1. MotherDuck integration, which can set MOTHERDUCK_TOKEN
  2. Supabase integration, which can set POSTGRES_URL
  3. This template's Vercel build command, which runs database migrations from migrations/

If you do not install either integration, set the matching environment variable yourself before deploying.

After deploy, add at least one AI key in Vercel project settings, then redeploy:

  • ANTHROPIC_API_KEY
  • OPENAI_API_KEY
  • AI_GATEWAY_API_KEY

Manual deploy:

vercel link
vercel env pull .env.local
vercel deploy

Local Development

git clone <your-repo-url>
cd motherduck-dives
npm install
cp .env.example .env.local

Run local Postgres:

docker run --name motherduck-dives-postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=motherduck_dives \
-p 5433:5432 \
-d postgres:16

Set local database URL:

POSTGRES_URL=postgres://postgres:postgres@localhost:5433/motherduck_dives

Start app:

npm run dev

Open http://localhost:3000, choose a Dive, click Remix, and chat.

Useful commands:

npm run lint
npm exec tsc -- --noEmit
npm run build
npm run build:with-migrate

Environment Variables

VariableRequiredDescription
MOTHERDUCK_TOKENYesMotherDuck admin token used to provision service accounts and embed sessions
POSTGRES_URLYesPostgres connection string
ANTHROPIC_API_KEYOne AI key requiredAnthropic API key
OPENAI_API_KEYOne AI key requiredOpenAI API key
AI_GATEWAY_API_KEYOne AI key requiredVercel AI Gateway API key
AI_MODEL_ANTHROPICNoAnthropic model override, defaults to claude-sonnet-4-6
AI_MODEL_OPENAINoOpenAI model override, defaults to gpt-5.4
AI_MODEL_GATEWAYNoAI Gateway model override, defaults to anthropic/claude-sonnet-4.6

Advanced overrides:

VariableRequiredDescription
MOTHERDUCK_API_BASENoMotherDuck API URL override
MOTHERDUCK_MCP_URLNoMotherDuck MCP endpoint override
MOTHERDUCK_PG_HOSTNoMotherDuck Postgres endpoint host override

Auth Modes

Default mode is public demo mode. Visitors can preview shared starter Dives. First edit creates an isolated anonymous MotherDuck service account and cloned starter Dives for that browser session.

Password mode requires sign-in and uses one shared MotherDuck service account:

PASSWORD_AUTH_ENABLED=true
AUTH_SECRET=<long-random-string>
MOTHERDUCK_SHARED_SERVICE_ACCOUNT_USERNAME=app_shared

Personal token mode requires sign-in and asks each user for their own MotherDuck personal access token:

PASSWORD_AUTH_ENABLED=true
AUTH_SECRET=<long-random-string>
MOTHERDUCK_AUTH_MODE=personal_pat
MOTHERDUCK_PAT_ENCRYPTION_KEY=<long-random-string>

Auth mode options:

  • PASSWORD_AUTH_ENABLED: set to true to require email/password sign-in.
  • AUTH_SECRET: required when password auth is enabled. Use a long random string for NextAuth session signing.
  • MOTHERDUCK_SHARED_SERVICE_ACCOUNT_USERNAME: optional shared MotherDuck service account username. Defaults to app_shared.
  • MOTHERDUCK_AUTH_MODE: set to personal_pat to require each signed-in user to provide a MotherDuck PAT.
  • MOTHERDUCK_PAT_ENCRYPTION_KEY: required when MOTHERDUCK_AUTH_MODE=personal_pat. Use a long random string to encrypt stored MotherDuck PATs.
  • MOTHERDUCK_TOKEN_APP_NAME: optional app name shown on the MotherDuck token request page. Defaults to motherduck-dives.
  • AUTH_TRUSTED_ORIGINS: optional comma-separated scheme://host[:port] values allowed for mutating requests behind proxies or custom origins.

Customize

Starter Dives

Edit starter Dive components:

  • dives/presentation-dive.tsx
  • dives/dashboard-dive.tsx
  • dives/game-dive.tsx

Starter metadata lives in app/_lib/dive-provisioning.ts.

AI Behavior

  • Change model defaults in app/_lib/chat/ai-provider.ts or set model env vars.
  • Change editing instructions in app/_lib/chat/system-prompt.ts.

Data

Starter Dives use MotherDuck sample_data. To use your own data:

  1. Load or attach data in MotherDuck.
  2. Update SQL in the starter Dive files.
  3. If users should only see their own data, model access around MotherDuck shares, per-user databases, or row-level filters before production.

Production Checklist

  • Replace demo auth with your app's identity provider.
  • Add authorization around users, workspaces, Dives, chat history, and data access.
  • Add rate limits to chat and provisioning routes.
  • Keep assertSameOrigin(request) on every mutating route.
  • Add monitoring for AI usage, MCP calls, embed session creation, and provisioning failures.
  • Add cleanup for expired anonymous demo sessions and their MotherDuck service accounts before running a public demo at scale.

License

MIT

GitHub Repomotherduckdb/nextjs-motherduck-embedded-dives
LicenseView License
Use Cases
AI
Starter
Stack
Next.js
React
Tailwind
CSS
Database
Supabase
Postgres
Auth
NextAuth.js

Related Templates

Next.js Boilerplate

Get started with Next.js and React in seconds.
Next.js Boilerplate thumbnail

Image Gallery Starter

An image gallery built on Next.js and Vercel Blob.
Image Gallery Starter thumbnail

Chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
Chatbot thumbnail

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • AI Gateway

        One endpoint, all your models

      • Sandbox

        Isolated, safe code execution

      • Vercel Agent

        An agent that knows your stack

      • AI SDK

        The AI Toolkit for TypeScript

      • v0

        Build applications with AI

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Workflow

        Long-running workflows at scale

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
ContactDashboard
DeployView Demo
AI Gateway

One endpoint, all your models

Sandbox

Isolated, safe code execution

Vercel Agent

An agent that knows your stack

AI SDK

The AI Toolkit for TypeScript

v0

Build applications with AI

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Workflow

Long-running workflows at scale

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea