Linktree Clone SaaS
A vibe coding tutorial: build a Linktree clone SaaS application from scratch using Next.js, Prisma ORM, Prisma Postgres, and Clerk authentication with AI assistance
Introduction
Section titled “Introduction”In this vibe coding tutorial, you'll build a Linktree clone SaaS application from scratch with an AI coding assistant. The stack is:
- Next.js: React framework for production
- Prisma ORM: Type-safe database access
- Prisma Postgres: Serverless PostgreSQL database
- Clerk: Authentication and user management
By the end of this tutorial, you'll have a working SaaS application where users can sign up, create their profile, and manage their personal link page, all built with AI-assisted development.
Video tutorial
Section titled “Video tutorial”Watch this step-by-step walkthrough of the entire build process:
Prerequisites
Section titled “Prerequisites”Before starting this tutorial, make sure you have:
- Node.js 20+ installed
- A Clerk account (free tier works)
- An AI coding assistant (Cursor, Windsurf, GitHub Copilot, etc.)
- Basic familiarity with React and TypeScript
1. Set up your project
Section titled “1. Set up your project”Create a new Next.js application:
bunx create-next-app@latest app-namepnpm dlx create-next-app@latest app-nameyarn dlx create-next-app@latest app-namenpx create-next-app@latest app-nameOnce the setup is complete, add Prisma and Prisma Postgres to your project with the prepared setup prompt.
👉 *Find the setup prompt here:* Next.js + Prisma Prompt
How to use it:
- Create a new file called
prompt.mdat the root of your project - Copy and paste the prompt content into this file
- Ask your AI assistant to follow the instructions in this file
The AI sets up Prisma ORM, creates your database connection, and configures the project.
Quick Check
Section titled “Quick Check”Verify the setup:
- Start your development server:
bun run devpnpm run devyarn devnpm run dev- Open Prisma Studio to view your seed data:
bun run db:studiopnpm run db:studioyarn db:studionpm run db:studioIf both commands run without errors and you can see sample data in Prisma Studio, you're ready to continue.
2. Set Up Authentication with Clerk
Section titled “2. Set Up Authentication with Clerk”Add user authentication with Clerk, which provides sign-up, sign-in, and session management.
Steps to follow:
- Go to Clerk and create an account (if you don't have one)
- Create a new application in your Clerk dashboard
- Follow Clerk's official quickstart guide to integrate it with your Next.js app:
👉 *Clerk Next.js Quickstart:* clerk.com/docs/nextjs/getting-started/quickstart
The guide will walk you through installing the SDK, adding environment variables, and wrapping your app with the ClerkProvider.
Once complete, commit your changes:
git add .
git commit -m "Add Clerk authentication setup"3. Update your database schema
Section titled “3. Update your database schema”Since we're building a Linktree clone, we need to update the database schema to support our specific data model. This includes:
- A
Usermodel with a uniqueusername(for public profile URLs like/username) - A
Linkmodel to store each user's links
Replace the contents of your prisma/schema.prisma file with the following:
generator client {
provider = "prisma-client"
output = "../app/generated/prisma"
}
datasource db {
provider = "postgresql"
}
// Example User model for testing
model User {
id Int @id @default(autoincrement())
email String @unique
username String @unique // Important for the public profile URL
clerkId String @unique // Links to Clerk Auth
name String?
links Link[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Link {
id Int @id @default(autoincrement())
title String
url String
userId Int
user User @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
}Since we're changing the schema structure, we need to reset the database. The existing seed data was just for testing purposes, so it's safe to drop and recreate:
bunx prisma db push --force-resetpnpm prisma db push --force-resetyarn prisma db push --force-resetnpx prisma db push --force-resetThis command:
- Drops the existing database tables
- Creates new tables based on your updated schema
Quick Check
Section titled “Quick Check”Open Prisma Studio to verify the new schema is applied:
bun run db:studiopnpm run db:studioyarn db:studionpm run db:studioYou should see the updated User and Link tables (they'll be empty, which is expected).
Commit your changes:
git add .
git commit -m "Update schema for Linktree clone"4. Connect Clerk users to your database
Section titled “4. Connect Clerk users to your database”When a user signs in with Clerk, they exist in Clerk's system but not in your database. To bridge this gap, create a "Claim Username" flow where users pick their unique username (e.g., yourapp.com/johndoe) after signing in for the first time.
The Prompt
Section titled “The Prompt”Copy and paste the following prompt into your AI assistant:
Connect Clerk authentication to your Prisma database with a "Claim Username" flow.
**Goal:**
When a user signs in via Clerk, they don't automatically exist in YOUR database. Create a flow where:
1. Logged out → Show landing page with "Sign In" button
2. Logged in but no DB profile → Show "Claim Username" form
3. Has DB profile → Show dashboard
**User Model (already in schema):**
model User {
id Int @id @default(autoincrement())
email String @unique
username String @unique
clerkId String @unique
name String?
links Link[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
**Files to create/update:**
1. `app/actions.ts` - Server Action with `claimUsername(formData)`
2. `app/page.tsx` - Three-state UI (logged out / claim username / dashboard)
3. `app/api/users/route.ts` - Update POST to accept `clerkId`, `email`, `username`, `name`
**Requirements:**
- Use `'use server'` directive in `app/actions.ts`
- Use `currentUser()` from `@clerk/nextjs/server` to get auth user
- Store `clerkId`, `email`, `username`, and `name` in User model
- Use `redirect("/")` after successful profile creation
- Handle username uniqueness (Prisma will throw if duplicate)
**Pattern:**
1. Server Action receives FormData, validates username (min 3 chars, alphanumeric + underscore)
2. Creates User in Prisma with Clerk's `user.id` as `clerkId`
3. Page.tsx checks: `currentUser()` → then `prisma.user.findUnique({ where: { clerkId } })`
4. Render different UI based on auth state and DB state
**Keep it simple:**
- No middleware file needed
- No webhook sync (user creates profile manually)
- Basic validation (username length >= 3)
- Errors just throw (no fancy error UI for MVP)After the AI generates the code, you may see TypeScript errors. This is because the Prisma Client needs to be regenerated to reflect the schema changes:
bunx prisma generatepnpm prisma generateyarn prisma generatenpx prisma generateQuick Check
Section titled “Quick Check”Test the complete flow:
- Stop your dev server and restart it
- Open your app in the browser
- Sign up as a new user through Clerk
- You should see the "Claim Username" form
- Enter a username and submit
- Verify the user appears in Prisma Studio (
npm run db:studio)
If everything works, commit your changes.
5. Upgrade the UI Design
Section titled “5. Upgrade the UI Design”Give the app a cleaner, friendlier look inspired by platforms like Buy Me a Coffee.
👉 Visit Buy Me a Coffee for design inspiration
Copy and paste this prompt to your AI assistant:
Design a minimal, friendly UI inspired by Buy Me a Coffee.
**Theme:**
- Force light mode only (no dark mode switching)
- Clean white background (#FFFFFF)
- Black text (#000000) for headings
- Gray (#6B7280) for secondary text
- Bright yellow (#FFDD00) for CTA buttons
- Light gray (#F7F7F7) for cards/sections
- Subtle borders (#E5E5E5)
**Typography & Spacing:**
- Large, bold headlines (text-5xl or bigger)
- Generous whitespace and padding
- Rounded corners everywhere (rounded-full for buttons, rounded-xl for cards)
**Buttons:**
- Primary: Yellow background, black text, rounded-full, font-semibold
- Secondary: White background, border, rounded-full
**Overall feel:**
- Friendly, approachable, not corporate
- Minimal — only essential elements
- Mobile-first with good touch targets (py-4, px-8 on buttons)
- One unified canvas — background applies to the entire page (body), with white cards floating on top. No separate section backgrounds.
Use Tailwind CSS. Keep it simple.Quick Check
Section titled “Quick Check”After the AI applies the changes:
- Refresh your app and browse through all pages
- Verify the design has updated but no functionality has changed
- Test the sign-in flow and username claim process
Once verified, commit the changes:
git add .
git commit -m "Update UI design"6. Build Link Management (Add & Delete)
Section titled “6. Build Link Management (Add & Delete)”Add the core functionality, managing links. Users should be able to add new links and delete existing ones from their dashboard.
Copy and paste this prompt:
Build a simple dashboard for managing links using Next.js App Router and Server Actions.
**Requirements:**
- Server Component page that fetches user data from database
- "Add Link" form with Title and URL inputs
- List of existing links with Delete button
- Use Server Actions (no API routes) for create/delete operations
- Use `revalidatePath("/")` after mutations to refresh the page
**Pattern:**
1. Create server actions in `actions.ts` with `'use server'` directive
2. Pass actions directly to form `action` prop
3. Keep page.tsx as a Server Component (no 'use client')
4. Use hidden inputs for IDs (e.g., `<input type="hidden" name="linkId" value={id} />`)
**Keep it simple:**
- No loading states
- No client components
- No confirmation dialogs
- Just forms + server actions + revalidation
This is the MVP pattern for CRUD with Next.js App Router.Quick Check
Section titled “Quick Check”Test the link management:
- Add a new link with a title and URL
- Verify it appears in your dashboard
- Delete the link
- Verify it's removed
Both operations should work instantly without page navigation.
7. Create Public Profile Pages
Section titled “7. Create Public Profile Pages”This is the heart of a Linktree clone: public profile pages that anyone can visit at /username.
Copy and paste this prompt:
Build a public profile page at /[username] using Next.js App Router dynamic routes.
**Requirements:**
- Create `app/[username]/page.tsx` as a Server Component
- Fetch user + links from database by username (from URL params)
- Return 404 if user not found (use `notFound()` from next/navigation)
- Display: avatar (first letter), username, name, and list of links
- Links open in new tab with `target="_blank"`
- Add a small "Create your own" link at the bottom
**Pattern:**
1. Get params: `const { username } = await params`
2. Query database with `findUnique({ where: { username } })`
3. If no user: call `notFound()`
4. Render profile with links as clickable buttons
**Keep it simple:**
- No auth required (it's a public page)
- Pure Server Component (no 'use client')
- Basic styling with hover effects
This is the core "Linktree" feature — anyone can visit /username to see the links.Quick Check
Section titled “Quick Check”Test your public profile:
- Navigate to
localhost:3000/your-username(replace with your actual username) - Verify your profile and links display correctly
- Click a link and confirm it opens in a new tab
8. Add a "Copy Link" Button
Section titled “8. Add a "Copy Link" Button”Make it easy for users to share their profile URL with a one-click copy button.
Copy and paste this prompt:
**Requirements:**
- Create a Client Component (`'use client'`) for the button
- Use `navigator.clipboard.writeText(url)` to copy
- Show "Copied!" feedback for 2 seconds after clicking
- Use `useState` to toggle the button text
**Pattern:**
1. Create `app/components/copy-button.tsx` with 'use client'
2. Accept `url` as a prop
3. On click: copy to clipboard, set `copied` to true
4. Use `setTimeout` to reset after 2 seconds
5. Import and use in your Server Component page
**Keep it simple:**
- One small client component
- No toast libraries
- Just inline text feedback ("Copy link" → "Copied!")Quick Check
Section titled “Quick Check”- Find the "Copy link" button on your dashboard
- Click it and verify it shows "Copied!"
- Paste somewhere to confirm the URL was copied correctly
9. Create a Custom 404 Page
Section titled “9. Create a Custom 404 Page”When someone visits a non-existent username, they should see a friendly error page instead of a generic 404.
Copy and paste this prompt:
Create a custom 404 page for Next.js App Router.
**Requirements:**
- Create `app/not-found.tsx` (Server Component)
- Display: 404 heading, friendly message, "Go home" button
- Match your app's design (colors, fonts, spacing)
**Pattern:**
- Next.js automatically uses `not-found.tsx` when `notFound()` is called
- Or when a route doesn't exist
- No configuration needed — just create the file
**Keep it simple:**
- Static page, no data fetching
- One heading, one message, one link
- Same styling as rest of the appQuick Check
Section titled “Quick Check”Test the 404 page by visiting a random URL like /this-user-does-not-exist. You should see your custom 404 page with a link back to the homepage.
10. Add a Custom Background
Section titled “10. Add a Custom Background”Add a custom background pattern to the app.
First, either:
- Download a background SVG pattern you like, or
- Create your own using tools like SVG Backgrounds or Hero Patterns
Then, save it as background.svg in your public/ folder.
Copy and paste this prompt:
Add a custom SVG background to my app.
**Requirements:**
- The svg file is in the `public/` folder (e.g., `public/background.svg`)
- Apply it as a fixed, full-cover background on the body
**Pattern:**
In `globals.css`, update the body:
```css
body {
background: var(--background) url("/background.svg") center/cover no-repeat fixed;
min-height: 100vh;
}
```
**Key properties:**
- `center/cover` — centers and scales to fill
- `no-repeat` — prevents tiling
- `fixed` — background stays in place when scrolling
Files in `public/` are served at the root URL, so `/background.svg` works.Quick Check
Section titled “Quick Check”- Refresh your app
- Verify the background appears on all pages (homepage, dashboard, profile pages, 404)
- If the background doesn't appear everywhere, ask your AI to fix it
Commit your changes once it's working correctly.
11. Add Glassmorphism Card Containers
Section titled “11. Add Glassmorphism Card Containers”Create visual depth by adding semi-transparent card containers that "float" over the background.
Copy and paste this prompt:
Add a reusable card container class to create visual separation from the background.
**Requirements:**
- Create a `.card` class in `globals.css`
- Apply glassmorphism: semi-transparent white + blur
- Use on all main content areas (landing, forms, dashboard, profile pages)
**Pattern:**
In `globals.css`, add:
```css
.card {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
border-radius: 1.5rem;
padding: 2rem;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
```
**Usage:**
Wrap content sections with `<div className="card">...</div>`
For public profile pages (/[username]):
Wrap the entire profile (avatar, name, username, and links list) in a single .card container
This creates a Linktree-style floating card effect
Footer/attribution links stay outside the card
Hero section:
Add a soft radial glow behind the content (large blurred white circle, blur-3xl, 50% opacity)
No visible container edges — just organic, fading brightness
Content floats freely over the glow
**Result:**
- Content "lifts" off the background
- Subtle blur creates depth
- Consistent UI across all pages12. Display Clerk Profile Images
Section titled “12. Display Clerk Profile Images”If users sign in with Google or another OAuth provider, Clerk stores their profile photo. Display it on public profiles.
Copy and paste this prompt:
On the public profile page (`/[username]`), display the user's Clerk profile image (Google photo, etc.) instead of the initial letter avatar.
**Pattern:**
```typescript
// Fetch Clerk user to get profile image
const client = await clerkClient();
const clerkUser = await client.users.getUser(user.clerkId);
```
**Display:**
- Use a plain `<img>` tag (not Next.js Image component)
- If `clerkUser.imageUrl` exists, show the image
- Otherwise fallback to the yellow initial avatar
**Keep it simple:**
- No try/catch — let errors bubble up
- No next.config changes needed
- No database schema changes neededQuick Check
Section titled “Quick Check”Visit your public profile page and verify your profile image (from Google, GitHub, etc.) is displayed instead of the initial letter avatar.
13. Add Icons with Lucide
Section titled “13. Add Icons with Lucide”Add icons with Lucide React to make buttons and empty states easier to read.
Copy and paste this prompt:
Add Lucide React icons to improve the UI.
First install: npm install lucide-react
Add icons to these elements:
- View button: ExternalLink icon
- Delete button: Trash2 icon (replace text with icon)
- Empty links state: Link icon
Import icons from 'lucide-react' and use with size prop (e.g., size={18}).
Keep buttons minimal — only add icons where they improve clarity.Quick Check
Section titled “Quick Check”Browse through your app and verify the icons appear on:
- The view/external link buttons
- The delete buttons
- The empty state when no links exist
14. Deploy to Vercel
Section titled “14. Deploy to Vercel”Deploy your app to Vercel.
Step 1: Configure Prisma for Production
Section titled “Step 1: Configure Prisma for Production”Add a postinstall script to ensure Prisma Client is generated during deployment.
Add this to your package.json scripts section:
{
"scripts": {
"postinstall": "prisma generate"
}
}📖 *Reference:* Deploy to Vercel - Build Configuration
Step 2: Clean Up Development Files
Section titled “Step 2: Clean Up Development Files”Delete the scripts/ folder if it exists. This folder was auto-generated during initial setup for seed data, you don't need it in production.
Step 3: Deploy to Vercel
Section titled “Step 3: Deploy to Vercel”- Push your code to GitHub (if you haven't already)
- Go to vercel.com and import your repository
- Important: Add all your environment variables in Vercel's dashboard:
DATABASE_URLNEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEY
Step 4: Update the App URL
Section titled “Step 4: Update the App URL”After your first deployment:
- Copy your production URL from Vercel (e.g.,
https://your-app.vercel.app) - Add a new environment variable in Vercel:
text NEXT_PUBLIC_APP_URL=https://your-app.vercel.app - Redeploy to apply the change
Final Check
Section titled “Final Check”Test your deployed app thoroughly:
- Sign up flow works
- Username claiming works
- Adding/deleting links works
- Public profile pages load correctly
- Copy link copies the correct production URL
- 404 page displays for non-existent usernames
Your Linktree clone is live.