A production-ready starter template for building modern SaaS applications with Next.js and TypeScript. This boilerplate provides a solid foundation with built-in authentication, email workflows, database integration, and a polished UI components system.
- Next.js 16 - React framework with App Router
- TypeScript - Type-safe code
- Tailwind CSS - Utility-first styling
- shadcn/ui - Pre-built UI components
- React Hook Form - Form handling
- Sonner - Toast notifications
- React Email - Email template components
- tRPC - End-to-end typesafe APIs
- better-auth - Secure authentication and session management
- Drizzle ORM - Type-safe database operations
- PostgreSQL - Database
- Resend - Email delivery service
- Biome - Fast linting and formatting
- Zod - Runtime validation
- pnpm - Fast, disk space efficient package manager
- T3 Env - Type-safe environment variables
- React Email - Type-safe email templates
- Centralized SEO Config - Easy-to-manage SEO settings
src/
├── app/ # Next.js App Router pages and layouts
│ ├── (auth)/ # Authentication-related routes
│ └── api/ # API routes for auth and tRPC
├── components/ # Reusable React components
│ ├── forms/ # Form components for auth and account management
│ └── ui/ # Base UI components (shadcn/ui)
├── lib/ # Core utilities and configurations
│ ├── auth/ # Authentication setup and handlers
│ ├── trpc/ # tRPC client configuration
│ └── utils/ # Helper functions and utilities
├── server/ # Server-side code
│ ├── db/ # Database schema and configuration
│ ├── email/ # Email templates and sending logic
│ └── trpc/ # tRPC router and procedure definitions
└── types/ # TypeScript type definitions
- Complete email & password authentication flow
- Social authentication support
- Password reset workflow
- Email verification
- Session management
- Account settings and profile updates
- Transactional email templates
- Email verification workflow
- Password reset emails
- Email change verification
- Responsive email designs with React Email
- Type-safe database schema with Drizzle ORM
- PostgreSQL database integration
- tRPC for type-safe API routes
- Efficient data fetching with React Query
- Modern, responsive design
- Dark mode support
- Form validation and error handling
- Toast notifications
- Loading states and feedback
- Accessible components
- Consistent typography system
- Clone the repository:
git clone https://github.com/hellrae/saas-starter.git
cd saas-starter- Install dependencies:
pnpm install-
Set up your environment variables:
a. Copy the example environment file:
cp .env.example .env
b. Update the
.envfile with your values:# Database DATABASE_URL="postgresql://user:password@localhost:5432/your_database" # Auth BETTER_AUTH_SECRET="your-long-secret-key-min-32-chars" DOMAIN_NAME="yourdomain.com" # Email (Resend.com) RESEND_API_KEY="re_..." # Get from https://resend.com # Public URLs NEXT_PUBLIC_BASE_URL="http://localhost:3000" NEXT_PUBLIC_BETTER_AUTH_URL="http://localhost:3000/api/auth"
All environment variables are type-safe and validated at runtime using @t3-oss/env-nextjs. The schema is defined in src/lib/utils/env.ts.
- Set up the database:
pnpm db:push # Push schema to database
pnpm db:migrate # Run migrations- Start the development server:
pnpm dev- Create new pages in
src/app/following Next.js App Router conventions - Add corresponding API routes in
src/app/api/if needed - Create tRPC procedures in
src/server/trpc/routers/
- Modify or add schemas in
src/server/db/schema/ - Generate migrations:
pnpm db:generate
pnpm db:push- Install new shadcn/ui components:
pnpm ui:add [component-name]- Create custom components in
src/components/ - Style with Tailwind CSS utilities
- Add new email templates in
src/server/email/templates/ - Use React Email components for consistent styling
- Register new email types in
src/server/email/index.ts
The starter uses Next.js built-in font optimization with a centralized font management system:
- Font Configuration:
- Geist Sans as primary font
- Geist Mono for code and monospace content
- CSS variables for consistent font usage
const geistSans = Geist({ variable: "--font-geist-sans", subsets: ["latin"], }); const geistMono = Geist_Mono({ variable: "--font-geist-mono", subsets: ["latin"], });
The starter includes a comprehensive SEO system with:
- Centralized SEO Configuration in
src/lib/utils/seo.ts:
export const appSeo = {
name: "Your App Name",
title: "Your App Name – Your Tagline",
description: "Your app description",
url: "https://yourdomain.com",
// OpenGraph, Twitter cards, icons, etc.
}-
Advanced Metadata Features:
- OpenGraph and Twitter Cards
- JSON-LD structured data
- Automatic canonical URLs
- Customizable metadata per page
- SEO-friendly robots configuration
- PWA manifest support
-
Usage:
- Global SEO settings are automatically applied through the root layout
- Override metadata in any page using Next.js Metadata API
- Example page override:
export const metadata = { title: "Custom Page Title", description: "Custom page description", // Will inherit other settings from root layout }
-
SEO Best Practices:
- Semantic HTML structure
- Proper heading hierarchy
- Responsive images with alt text
- Schema.org JSON-LD integration
- Mobile-friendly viewport settings
- Add new environment variables in
src/lib/utils/env.ts - Variables are validated using Zod schemas:
server: {
DATABASE_URL: z.string().min(1),
// Add server-side variables
},
client: {
NEXT_PUBLIC_BASE_URL: z.string().min(1),
// Add client-side variables
}- TypeScript will enforce usage of these variables throughout the application
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request