Next.js SaaS Starter Kit πŸš€

  • Author

    Binny Chanchal
  • Published

Welcome to the Next.js SaaS Starter Kit! This starter kit is designed to accelerate your SaaS (Software as a Service) application development by providing a robust foundation with essential features out of the box. Whether you’re a developer, startup, or tech leader, this starter kit will help you build scalable, secure, and efficient SaaS applications with ease.

Overview

The Next.js SaaS Starter Kit is a robust foundation for building scalable SaaS applications. It includes essential features like user authentication, subscription management, billing, and more, allowing you to focus on delivering value to your users without worrying about the underlying infrastructure.

πŸ“¦ Features

Our starter kit comes packed with a suite of powerful features:

  • User Authentication: Secure registration, login, and social authentication using NextAuth.js.
  • Subscription Management: Integrated with Stripe for managing subscription plans.
  • Billing and Payments: Automated invoicing and payment processing with Stripe.
  • Dashboards: User and admin dashboards with real-time analytics.
  • Email Notifications: Automated transactional and marketing emails.
  • API Integrations: Ready-to-use integrations with third-party services.
  • Styling: Responsive design with Tailwind CSS.
  • DevOps Ready: Docker and Kubernetes configurations for easy deployment.

Technologies Used

  • Frontend: Next.js, Tailwind CSS, React
  • Backend: Next.js API Routes, NextAuth.js, Prisma ORM
  • Database: PostgreSQL
  • Payments: Stripe
  • Email Services: SendGrid, Mailgun
  • DevOps: Docker, Kubernetes
  • Testing: Jest, React Testing Library

πŸ›  Getting Started

Follow these instructions to set up and run the project locally.

πŸš€ Prerequisites

Ensure you have the following installed on your machine:

  • Node.js: v16 or higher
  • npm or yarn or pnpm: Package managers
  • PostgreSQL: Database system
  • Docker (optional for containerization)
  • Stripe Account: For payment processing
  • Email Service Account: (e.g., SendGrid, Mailgun) for sending emails

πŸ“ Installation

  1. Clone the Repository

    git clone https://github.com/BinnyDuskbyte/nextjs-saas-starter-kit.git
    cd nextjs-saas-starter
    
    
  2. Install Dependencies

    npm install
    # or
    yarn install
    # or
    pnpm install
    
    
  3. Configure Environment Variables

    Create a .env file in the root directory based on the .env.example file.

    cp .env.example .env
    

    Open .env and fill in your configuration details:

    
      # Database Configuration
      DATABASE_URL="postgresql://username:password@localhost:5432/nextjs_saas?schema=public"
    
      # NextAuth Configuration
      NEXTAUTH_URL=http://localhost:3000
      NEXTAUTH_SECRET=your_nextauth_secret
    
      # Stripe Configuration
      STRIPE_SECRET_KEY=your_stripe_secret_key
      STRIPE_PUBLISHABLE_KEY=your_stripe_publishable_key
    
      # Email Configuration
      MAIL_HOST=smtp.mailgun.org
      MAIL_PORT=587
      MAIL_USERNAME=your_mailgun_username
      MAIL_PASSWORD=your_mailgun_password
      MAIL_ENCRYPTION=tls
      MAIL_FROM_ADDRESS=example@example.com
      MAIL_FROM_NAME="Next.js SaaS Starter"
    
      # Additional Configurations (if any)
    
  4. Initialize Prisma and Migrate Database

    npx prisma migrate dev --name init
    npx prisma generate
    
    
  5. Run the Development Server

    npm run dev
    # or
    yarn dev
    # or
    pnpm dev
    
  6. Access the Application

    Open http://localhost:3000 in your browser to see the result.

    You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.

πŸ–₯ Project Structure

Here’s an overview of the project’s directory structure:

/nextjs-saas-starter
β”œβ”€β”€ /app
β”‚   β”œβ”€β”€ /api
β”‚   β”‚   β”œβ”€β”€ /auth
β”‚   β”‚   β”‚   └── [...nextauth].ts      # NextAuth.js API routes
β”‚   β”‚   └── /subscriptions
β”‚   β”‚       └── route.ts              # Subscription-related API routes
β”‚   β”œβ”€β”€ /auth
β”‚   β”‚   β”œβ”€β”€ /login
β”‚   β”‚   β”‚   └── page.tsx              # Login page
β”‚   β”‚   └── /register
β”‚   β”‚       └── page.tsx              # Registration page
β”‚   β”œβ”€β”€ /dashboard
β”‚   β”‚   └── page.tsx                  # User dashboard
β”‚   β”œβ”€β”€ /admin
β”‚   β”‚   └── page.tsx                  # Admin dashboard
β”‚   β”œβ”€β”€ layout.tsx
β”‚   └── page.tsx                      # Landing page
β”œβ”€β”€ /components
β”‚   β”œβ”€β”€ /layout
β”‚   β”‚   β”œβ”€β”€ Navbar.tsx
β”‚   β”‚   └── Footer.tsx
β”‚   └── /ui
β”‚       β”œβ”€β”€ Button.tsx
β”‚       β”œβ”€β”€ FeatureCard.tsx
β”‚       β”œβ”€β”€ StatisticCard.tsx
β”‚       β”œβ”€β”€ TestimonialCard.tsx
β”‚       β”œβ”€β”€ AnimatedSection.tsx       # Lottie Animation Section
β”‚       └── PureSVGAnimatedSection.tsx# Pure SVG Animation Section
β”œβ”€β”€ /lib
β”‚   β”œβ”€β”€ prisma.ts                      # Prisma client setup
β”‚   β”œβ”€β”€ stripe.ts                      # Stripe client setup
β”‚   └── mails
β”‚       └── SubscriptionConfirmation.ts # Email sending logic
β”œβ”€β”€ /prisma
β”‚   └── schema.prisma                  # Prisma schema
β”œβ”€β”€ /public
β”‚   β”œβ”€β”€ /animations
β”‚   β”‚   └── feature-animation.json      # Lottie Animation JSON
β”‚   └── /images
β”‚       β”œβ”€β”€ hero.jpg
β”‚       β”œβ”€β”€ feature1.svg
β”‚       β”œβ”€β”€ feature2.svg
β”‚       β”œβ”€β”€ feature3.svg
β”‚       β”œβ”€β”€ feature4.svg
β”‚       β”œβ”€β”€ feature5.svg
β”‚       β”œβ”€β”€ feature6.svg
β”‚       β”œβ”€β”€ feature7.svg
β”‚       β”œβ”€β”€ feature8.svg
β”‚       β”œβ”€β”€ statistic.svg
β”‚       β”œβ”€β”€ testimonial1.jpg
β”‚       β”œβ”€β”€ testimonial2.jpg
β”‚       └── animated-feature.svg        # Pure SVG Animation
β”œβ”€β”€ /styles
β”‚   └── globals.css                    # Global CSS with Tailwind directives
β”œβ”€β”€ /tests
β”‚   └── ...                            # Testing files
β”œβ”€β”€ .env.example
β”œβ”€β”€ tailwind.config.js
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ package.json
└── README.md

πŸ›  Configuration Details

πŸ“¦ Prisma ORM

Prisma is used for database interactions. The schema is defined in prisma/schema.prisma. Ensure that the DATABASE_URL in your .env file is correctly set to connect to your PostgreSQL database.

πŸ” Authentication with NextAuth.js

NextAuth.js manages user authentication. Supported providers can be configured in app/api/auth/[…nextauth].ts. By default, it includes credential-based authentication, but you can add OAuth providers as needed.

πŸ’³ Payment Processing with Stripe

Stripe is integrated for handling payments and subscriptions. Configure your Stripe API keys in the .env file. The Stripe client is set up in lib/stripe.ts.

πŸ“§ Email Notifications with NodeMailer

NodeMailer is used to send transactional emails, such as subscription confirmations. Configure your email service credentials in the .env file. The email sending logic is encapsulated in lib/mails/SubscriptionConfirmation.ts.

🎨 Styling with Tailwind CSS

Tailwind CSS is employed for styling, allowing for rapid and responsive UI development. Customize your Tailwind configuration in tailwind.config.js to match your branding and design preferences.

πŸ§ͺ Testing

The project is set up with Jest and React Testing Library for unit and integration testing. Sample tests are located in the /tests directory. To run tests:

npm run test
# or
yarn test
# or
pnpm test

πŸš€ Deployment

🐳 Docker Deployment

A Dockerfile and docker-compose.yml are provided for containerizing the application.

  1. Build and Run Containers

    docker-compose up --build
    
  2. Access the Application

    Visit http://localhost:3000 to see the application running inside Docker containers.

  3. πŸ›‘ Kubernetes Deployment

    For scalable deployments, Kubernetes manifests can be created based on the Docker setup. This allows for orchestrating containers in a production environment.

  4. 🌐 Deploy to Vercel

    Vercel is a great platform for deploying Next.js applications.

    1. Push to GitHub

      Ensure your project is pushed to a GitHub repository.

        git init
        git add .
        git commit -m "Initial commit"
        git remote add origin https://github.com/BinnyDuskbyte/nextjs-saas-starter-kit.git
        git push -u origin main
      
    2. Connect to Vercel

      • Sign in to Vercel and import your GitHub repository.
      • Configure environment variables in Vercel based on your .env file.
      • Deploy the application directly from Vercel’s dashboard.

πŸ›  Development Tools

  • ESLint: Ensures code quality and consistency.
  • Prettier: Code formatter for maintaining a uniform code style.
  • Turbopack: Next-generation bundler for improved build performance.

πŸ“š Documentation

Contributing

Contributions are welcome!

πŸ“ License

This project is licensed under the MIT License.

πŸ“¬ Contact

For any inquiries or support, please contact binny@duskbyte.com.

πŸŽ‰ Thank You!

Thank you for choosing the Next.js SaaS Starter Kit! We hope this starter kit helps you build amazing SaaS applications efficiently and effectively. If you have any feedback or suggestions, feel free to open an issue or contribute to the project.

Happy Coding! πŸš€

πŸ“Έ Screenshots

NextJs_SaaS_Starter_Kit

Login

Register