How paddlehq/paddle-nextjs-starter-kit works
Project’s Purpose and Main Components
• The project is a full-stack SaaS starter kit for digital product sales and subscription management using Paddle Billing.
• It is built using Next.js and leverages Supabase for authentication and user management, Tailwind CSS with shadcn/ui for components, and integrates with Paddle for billing and checkout.
• The key functionalities include a pricing page, checkout flow, user authentication, a dashboard for managing subscriptions and payments, and webhook endpoints for syncing Paddle events.
A. Frontend (Next.js Application)
• Pages and Views:
• Home, Pricing, Signup, Login, Dashboard (with sections for subscriptions and payments), and error handling.
• Components:
• UI components (buttons, dialogs, forms, etc.) using shadcn/ui.
• Authentication forms, checkout components, home page header, and dashboard layouts.
• Technology/Framework:
• Next.js uses both server-side rendering (SSR) and client-side interactivity.
B. API Routes / Serverless Endpoints (Inside Next.js App)
• API Routes:
• /api endpoints for webhooks (processing Paddle notifications) and possibly other backend logic.
• Authentication & Callback:
• Endpoints for handling auth callbacks and session management.
• Checkout and Payment Processing:
• API logic that interacts with Paddle for initiating checkouts – for example, the checkout route using the provided price IDs.
C. External Services:
• Paddle Billing:
• Payment processing, subscription management, and pricing (via Paddle Checkout, Paddle.js).
• Interactions include checkout initiation from the frontend and webhook callbacks to the API to reflect changes in subscriptions.
• Supabase:
• Authentication service and user data store.
• Manages user session, secure data access, and additional business logic for user management (e.g., subscription and payment details).
D. Database and Data Synchronization:
• Supabase Database:
• Contains user profiles, subscription records, and payment history.
• Synchronization:
• Webhook endpoints process incoming events from Paddle and update the Supabase database accordingly.
E. Deployment and Configuration Artifacts:
• Vercel deployment (as the hosting platform).
• Environment variables and configuration files (.env.local.example, next.config.mjs, etc.) that manage keys and setup.
• Supabase folder for database migrations and seeds, reflecting the intended persistence architecture.
How the Components Interact (Data Flow & Dependencies)
• The Client (browser) interacts with the Next.js frontend to access pages like Home, Signup/Login, Pricing, and Dashboard.
• On the Pricing page or during signup, the client triggers checkout actions that call the Next.js API routes which wrap Paddle’s endpoints.
• Paddle processes checkout and billing: after a successful transaction, Paddle sends a webhook callback to /api/webhook (an endpoint in the Next.js app).
• The webhook endpoint validates and processes the event (using the PADDLE_NOTIFICATION_WEBHOOK_SECRET) before updating the Supabase database with subscription and payment details.
• The Dashboard then reads from Supabase (via server-side functions or client-side fetching) to display current subscriptions and payment history.
• Authentication flows (login/signup) leverage Supabase’s auth APIs via Next.js routes/components.
Architectural Patterns and Design Principles
• Separation of Concerns:
• The frontend is clearly separated from the backend API logic.
• API routes are responsible for handling external integrations and secure data processing.
• External Integrations:
• The project leverages external services (Paddle Billing and Supabase) for specialized functionalities.
• Modular Components:
• The file structure reveals modular React components (organized under /src/components) and isolated API logic under /src/app/api.
• Serverless Approach:
• API endpoints (including webhooks) suggest a serverless design, aligning with the hurdles of cloud deployment via Vercel.