This is a Next.js project boilerplate designed to kickstart your SaaS application development. It includes essential features like authentication, database integration with Drizzle ORM, UI components with Shadcn/ui, and more.
Before you begin, ensure you have the following installed:
- Node.js (Version 20 or higher recommended)
- A Node.js package manager: npm, yarn, pnpm, or bun
- PostgreSQL database
Follow these steps to get your development environment up and running:
-
Clone the repository:
git clone <your-repository-url> cd saas-boilerplate
-
Install dependencies: Choose your preferred package manager:
npm install # or yarn install # or pnpm install # or bun install
-
Set up environment variables:
You'll need to provide values for:
DATABASE_URL
: Your PostgreSQL connection string.BETTER_AUTH_SECRET
: A secret key for authentication.POLAR_ACCESS_TOKEN
: Polar acess token keyPOLAR_WEBHOOK_SECRET
: Webhook secretRESEND_API_KEY
: Your API key from Resend for sending emails.GOOGLE_CLIENT_ID
: Your Google OAuth client ID for social login.GOOGLE_CLIENT_SECRET
: Your Google OAuth client secret for social login.
-
Run database migrations: Apply the database schema:
npm run db:migrate
(Optional) You can seed the database with initial data using:
npm run db:seed
-
Run the development server:
npm run dev
Open http://localhost:3000 (or your configured
NEXT_PUBLIC_APP_URL
) in your browser to see the result.
The src/app-config.ts
file centralizes various configuration settings for the application. You should modify this file to match your specific needs.
This boilerplate uses Better Auth for handling authentication and user management. The core configuration can be found in src/lib/auth.ts
.
Key features implemented:
- Database Integration: Uses the
drizzleAdapter
with your PostgreSQL database (schema defined insrc/db/schema.ts
). - Email & Password: Standard email and password sign-up and sign-in are enabled.
- Social Login: Google authentication is implemented for easy sign-in. Define your client and secred ids in the .env
- Email Verification:
- Required for users signing up via email/password.
- Verification emails are sent automatically on sign-up using the
src/components/email-templates/verify-email.tsx
template. - Users are auto-signed in and redirected post-verification.
- Password Reset: Users can reset their passwords via email using the
src/components/email-templates/reset-password.tsx
template. - Welcome Email: A welcome email (
src/components/email-templates/welcome.tsx
) is sent when a new user record is created in the database. - Polar Integration:
- Automatically creates Polar customers on user sign-up
- You should create a product in Polar and insert their details to the db to dynamically fetch them for the better-auth/polar integration (see
utils/auth
) - Current Polar environment is set to sandbox
- Next.js Integration: Uses the
nextCookies()
plugin for proper cookie handling within the Next.js framework.
You can customize email templates, authentication flows, and plugin configurations by modifying src/lib/auth.ts
and the referenced email template components.
NB! Resend won't deliver your email if your domain is not authorized, that's why utils/app-config
email.from setting is important. Set something that is valid as your domain.
To learn more about the technologies used in this boilerplate, refer to their respective documentation:
- Next.js Documentation
- Drizzle ORM Documentation
- Better Auth Documentation
- Shadcn/ui Documentation
- Tailwind CSS Documentation
- Polar Documentation
This boilerplate includes Umami for privacy-friendly analytics. The tracking script is configured in src/app/layout.tsx
. You can:
- Replace it with your own Umami instance by updating the script source and website ID
- Switch to an alternative analytics solution like Plausible
- Remove the analytics script entirely if not needed