Makerkit Next.js SaaS Starter Kit (Lite)

repository·main·Indexed 19 days ago

https://github.com/makerkit/nextjs-saas-starter-kit-lite

A Next.js and Supabase-based SaaS starter kit for rapid prototyping and building basic SaaS tools. It features a production-grade monorepo architecture using Turborepo, including utilities for enhancing Server Actions and Route Handlers with authentication and Zod validation, a shared UI package with Shadcn UI, and integrated Playwright E2E testing.

Tokens
77.2K
Snippets
248
Records
302
Agent score
62%

What's inside Makerkit Lite

  1. Understand the @kit/ui package structure

    main

    The @kit/ui package manages all UI components and styles for the application. It is organized into two distinct categories:

    1. Shadcn UI: Standard components that follow the shadcn/ui pattern, allowing for high customizability and consistency across the app.
    2. Makerkit-specific: Specialized components designed specifically for the MakerKit ecosystem and SaaS workflows.
  2. Understand the Project Structure

    main

    The project uses a Turborepo monorepo architecture:

    • apps/web/: The main Next.js application.
      • app/(marketing)/: Public marketing pages.
      • app/auth/: Authentication pages (logic resides in @kit/auth).
      • app/home/: Protected/Gated application pages.
      • supabase/: Database schema, migrations, and seed data.
      • config/: Application configuration.
    • packages/ui/: Shared UI components (Shadcn UI + TailwindCSS v4).
    • packages/features/: Core business logic packages (e.g., auth in packages/features/auth).
  3. Manage Supabase services

    main

    Use the following commands to control the local Supabase instance:

    • Stop Supabase: pnpm run supabase:web:stop
    • Reset Supabase: pnpm run supabase:web:reset (This applies migrations and resets the database using seed data).

    For advanced CLI operations, use the --filter web flag to target the web application package.

    pnpm run supabase:web:start
    pnpm run supabase:web:stop
    pnpm run supabase:web:reset
  4. Deploy to Production

    main

    Supabase Setup

    1. Create a new project in the Supabase dashboard.
    2. Push your local migrations to the remote project:
      pnpm --filter web supabase db push
    3. Set the Supabase Callback URL: In your Supabase project settings, set the Auth callback URL to <your-app-url>/auth/callback.

    Hosting

    • Vercel/Other Providers: Standard Next.js deployment.
    • Cloudflare: To deploy to Cloudflare, you must set the runtime to edge in apps/web/app/layout.tsx and enable Node.js compatibility in the Cloudflare dashboard:
      export const runtime = 'edge';
    export const runtime = 'edge';
  5. Run Code Health checks (Lint, Format, Typecheck)

    main

    The project uses Turborepo to cache results for these commands. You can run them frequently without performance impact:

    • Format code: pnpm run format:fix
    • Lint code: pnpm run lint
    • Validate TypeScript: pnpm run typecheck
    pnpm run format:fix
    pnpm run lint
    pnpm run typecheck
  6. Manage Database Migrations

    main

    The database schema and migrations are located in apps/web/supabase. Use these commands to manage changes:

    • Create a new migration:
      pnpm --filter web supabase migration new --name <migration-name>
      This creates a file in apps/web/supabase/migrations.
    • Apply migrations locally: Run pnpm run supabase:web:reset to apply migrations and reset with seed data.
    • Link to a remote Supabase project:
      pnpm --filter web supabase db link
    • Push migrations to remote Supabase:
      pnpm --filter web supabase db push
    pnpm --filter web supabase migration new --name <migration-name>
    pnpm --filter web supabase db link
    pnpm --filter web supabase db push
  7. Install the Next.js Supabase SaaS Starter Kit (Lite)

    main

    Follow these steps to set up the development environment locally:

    1. Clone the repository:
      git clone https://github.com/makerkit/next-supabase-saas-kit-lite.git
    2. Install dependencies using pnpm:
      pnpm install
    3. Start Supabase (requires Docker to be running):
      pnpm run supabase:web:start
      The Supabase Dashboard is typically available at http://localhost:54323.
    4. Start the Next.js application:
      pnpm run dev
      The app will be available at http://localhost:3000.
    git clone https://github.com/makerkit/next-supabase-saas-kit-lite.git
    pnpm install
    pnpm run supabase:web:start
    pnpm run dev
  8. Extend the application event system

    main

    The event system is built on a base set of application events. To add your own custom events, you must extend the ConsumerProvidedEventTypes type. The system uses TypeScript generics to ensure that when you emit or listen to an event, the payload is correctly typed based on your extensions.

    Base events included in BaseAppEventTypes:

    • user.signedIn: { userId: string }
    • user.signedUp: { method: 'magiclink' | 'password' }
    • user.updated: EmptyPayload
    • checkout.started: { planId: string; account?: string }
    // 1. Define your custom events
    export type ConsumerProvidedEventTypes = {
      'my.custom.event': { foo: string };
    };
    
    // The rest of the system will now automatically include 'my.custom.event'
    // with the correct payload type.
  9. Configure application via environment variables

    main

    Configure your application by adding variables to a .env.local file.

    Variable NameDescriptionDefault Value
    NEXT_PUBLIC_SITE_URLThe URL of your SaaS applicationhttp://localhost:3000
    NEXT_PUBLIC_PRODUCT_NAMEThe name of your SaaS productMakerkit
    NEXT_PUBLIC_SITE_TITLEThe title of your SaaS productMakerkit - The easiest way to build and manage your SaaS
    NEXT_PUBLIC_SITE_DESCRIPTIONThe description of your SaaS productMakerkit is the easiest way to build and manage your SaaS...
    NEXT_PUBLIC_DEFAULT_THEME_MODEThe default theme mode of your SaaS productlight
    NEXT_PUBLIC_THEME_COLORThe default theme color of your SaaS product#ffffff
    NEXT_PUBLIC_THEME_COLOR_DARKThe default theme color of your SaaS product in dark mode#0a0a0a
    NEXT_PUBLIC_SUPABASE_URLThe URL of your Supabase projecthttp://127.0.0.1:54321
    NEXT_PUBLIC_SUPABASE_ANON_KEYThe anon key of your Supabase project''
    SUPABASE_SERVICE_ROLE_KEYThe service role key of your Supabase project''
  10. Configure Route Context for navigation items

    main

    Navigation items can be restricted to specific contexts using the context property. This allows you to show or hide routes based on whether the user is in a personal, organizational, or global view.

    Available RouteContext values:

    • 'personal': For routes specific to an individual user.
    • 'organization': For routes specific to an organization/team.
    • 'all': The default context, making the route available in all views.
    // Example of a route restricted to organization context
    const orgRoute = {
      label: 'Team Settings',
      path: '/org/settings',
      context: 'organization' as const,
    };