Overview
The Dodo Supabase Subscription Starter follows a modern Next.js App Router structure with clear separation of concerns for server actions, components, database logic, and integrations.Root Directory Structure
Server Actions (/actions)
Server actions handle all data mutations and business logic:
cancel-subscription.ts- Cancel user subscriptionschange-plan.ts- Update subscription planscreate-dodo-customer.ts- Create customers in Dodo Paymentscreate-user.ts- Initialize new usersdelete-account.ts- Handle account deletionget-invoices.ts- Fetch payment historyget-products.ts- Retrieve available productsget-user-subscription.ts- Get current subscription detailsget-user.ts- Fetch authenticated user datarestore-subscription.ts- Restore cancelled subscriptions
App Routes
Pages
/- Landing page/login- Authentication page/dashboard- User dashboard (protected route)
API Routes
/api/auth/callback- OAuth callback handler/checkout- Payment checkout handler (GET/POST)
Components Architecture
Authentication Components (/components/auth)
google-signin.tsx- Google OAuth sign-in button
Dashboard Components (/components/dashboard)
dashboard.tsx- Main dashboard container with tabbed interfacesubscription-management.tsx- Subscription details and managementinvoice-history.tsx- Payment invoice listaccount-management.tsx- User account settingscancel-subscription-dialog.tsx- Subscription cancellation dialogupdate-plan-dialog.tsx- Plan upgrade/change dialogrestore-subscription-dialog.tsx- Restore cancelled subscription
Layout Components (/components/layout)
header.tsx- Application header with navigation
UI Components (/components/ui)
Shadcn/ui components for consistent design:
button.tsx,card.tsx,dialog.tsx,input.tsx,table.tsx, etc.theme-provider.tsx- Dark/light theme support
Library Structure
Configuration (/lib/config)
plans.ts- Subscription plan definitions
Database (/lib/drizzle)
client.ts- Drizzle ORM database clientschema.ts- Complete database schema definitions
Integrations
/lib/dodo-payments/- Dodo Payments SDK client/lib/supabase/- Supabase client (browser and server)
Supabase Functions
Edge Functions (/supabase/functions)
dodo-webhook/- Webhook handler for payment events- Processes payment and subscription webhooks
- Updates database based on webhook events
- Manages user tier upgrades/downgrades
Key Files
Configuration
drizzle.config.ts- Drizzle ORM configurationnext.config.ts- Next.js configurationtsconfig.json- TypeScript configurationtailwind.config.ts- Tailwind CSS configurationcomponents.json- Shadcn/ui configuration
Package Management
package.json- Dependencies and scriptsbun.lock- Bun lockfile
Design Patterns
Server-First Architecture
All data mutations use Next.js Server Actions ("use server") for type-safe server-side operations without API routes.
Component Composition
Components are organized by feature (auth, dashboard) with shared UI components in/components/ui.
Database Access Layer
All database operations use Drizzle ORM with type-safe queries and schema definitions.Client/Server Separation
- Server components for data fetching
- Client components (
"use client") for interactivity - Server actions for mutations
Environment Configuration
Required environment variables (see.env.example):
- Supabase credentials (URL, service role key)
- Dodo Payments API key
- Database connection string
- Webhook secrets
Development Workflow
- Database: Schema defined in
/lib/drizzle/schema.ts - Server Actions: Business logic in
/actions - Components: UI in
/components - Pages: Routes in
/app - Webhooks: Event handling in
/supabase/functions
