A production-ready SaaS starter template built with Next.js 16, featuring complete authentication, multi-tenancy, and modern UI components.
- Email/Password Authentication with email verification
- Social Login (GitHub OAuth)
- Two-Factor Authentication (2FA) for enhanced security
- Email OTP Verification for passwordless login
- Password Reset with secure token-based flow
- Role-Based Access Control with admin capabilities
- Session Management with secure cookies
- Organization Management with member invitations
- Role-Based Permissions within organizations
- Member Management with customizable roles
- Organization Switching for users in multiple organizations
- ShadCN UI premium feel components
- Tailwind CSS 4 for styling
- Framer Motion for smooth animations
- Dark Mode Ready (easily configurable)
- Custom components including:
- Forms with validation
- Input groups and OTP inputs
- Buttons, cards, and alerts
- Tooltips and separators
- React Email for beautiful email templates
- Resend integration for reliable delivery
- Pre-built templates:
- OTP verification emails
- Welcome emails
- Password reset emails
- PostgreSQL as the primary database
- Drizzle ORM for type-safe database queries
- Pre-configured schema including:
- Users with roles and bans
- Organizations and members
- Sessions and two-factor
- Invitations and verifications
- Accounts for social login
- TypeScript for type safety
- Biome for fast linting and formatting
- Husky & Lint-Staged for pre-commit hooks
- Drizzle Studio for database GUI
- Hot reload and fast refresh
- Organized project structure
- Node.js 20+ or Bun (recommended)
- PostgreSQL database
- Resend account (for emails)
- GitHub OAuth App (optional, for social login)
git clone <your-repo-url>
cd SaaS-Templatebun install
# or
npm installCreate a .env.local file in the root directory:
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/saas
# App Configuration
NEXT_PUBLIC_PROJECT_NAME=Your SaaS Name
BETTER_AUTH_SECRET=your-secret-key-here # Generate with: openssl rand -base64 32
BETTER_AUTH_URL=http://localhost:3000
# Email (Resend)
RESEND_API_KEY=re_xxxxxxxxxxxxxxxx
RESEND_FROM_EMAIL=[email protected]
# OAuth (Optional)
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret# Generate migrations
bun run db:generate
# Run migrations
bun run db:migrate
# Or push schema directly (development)
bun run db:pushbun devOpen http://localhost:3000 to see your application.
| Command | Description |
|---|---|
bun dev |
Start development server |
bun build |
Build for production |
bun start |
Start production server |
bun run db:generate |
Generate database migrations |
bun run db:migrate |
Run database migrations |
bun run db:push |
Push schema to database (dev) |
bun run db:studio |
Open Drizzle Studio GUI |
bun run lint |
Check code quality |
bun run lint:fix |
Fix code quality issues |
bun run email |
Preview email templates |
src/
βββ app/ # Next.js App Router
β βββ (auth)/ # Authentication routes
β β βββ login/
β β βββ register/
β β βββ verify-email/
β β βββ forgot-password/
β βββ api/ # API routes
β β βββ auth/ # Better Auth handlers
β βββ layout.tsx # Root layout
βββ components/
β βββ auth/ # Auth-related components
β βββ emails/ # Email templates
β βββ layout/ # Layout components
β βββ profile/ # User profile components
β βββ ui/ # Reusable UI components
βββ db/
β βββ schema/ # Database schema
β β βββ enum/ # Enum definitions
β β βββ tables/ # Table schemas
β βββ index.ts # Database instance
βββ dal/ # Data Access Layer
βββ hooks/
β βββ auth/ # Authentication hooks
βββ lib/
β βββ auth.ts # Better Auth configuration
β βββ auth-client.ts # Client-side auth utilities
β βββ auth-guards.ts # Route protection
β βββ utils.ts # Utility functions
βββ validations/
βββ auth.ts # Zod validation schemas
- User signs up with email and password
- OTP sent to email for verification
- User verifies email with OTP code
- Account activated and user logged in
- User provides credentials
- Optional 2FA challenge if enabled
- Session created with secure cookie
- User requests password reset
- OTP sent to registered email
- User verifies OTP and sets new password
- Create and manage multiple organizations
- Invite members via email
- Assign roles (Owner, Admin, Member)
- Switch between organizations seamlessly
- Organization-level permissions
- Modify
src/app/globals.cssfor global styles - Update Tailwind config in
tailwind.config.ts - Customize component styles in
src/components/ui/
- Update
NEXT_PUBLIC_PROJECT_NAMEin.env.local - Replace logo and images in
public/ - Customize email templates in
src/components/emails/
- Modify schemas in
src/db/schema/ - Run
bun run db:generateto create migrations - Apply with
bun run db:migrate
- β HTTPS in production (configured via hosting)
- β Secure session management with httpOnly cookies
- β CSRF protection via Better Auth
- β SQL injection prevention via Drizzle ORM
- β Password hashing with bcrypt
- β Rate limiting (implement in production)
- β Input validation with Zod schemas
- Framework: Next.js 16 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS 4
- Database: PostgreSQL + Drizzle ORM
- Authentication: Better Auth
- Email: React Email + Resend
- UI Components: ShadCN UI
- Animation: Framer Motion
- Validation: Zod (via Better Auth)
- Linting: Biome
- Push your code to GitHub
- Import project in Vercel
- Add environment variables
- Deploy!
This template works with any platform supporting Node.js:
- Railway
- Render
- DigitalOcean App Platform
- AWS/GCP/Azure
Remember to:
- Set all environment variables
- Update
BETTER_AUTH_URLto your production domain - Configure production database
- Set up email sending domain in Resend
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | β |
NEXT_PUBLIC_PROJECT_NAME |
App name displayed to users | β |
BETTER_AUTH_SECRET |
Secret for session encryption | β |
BETTER_AUTH_URL |
Base URL of your app | β |
RESEND_API_KEY |
Resend API key | β |
RESEND_FROM_EMAIL |
Verified sender email | β |
GITHUB_CLIENT_ID |
GitHub OAuth client ID | β |
GITHUB_CLIENT_SECRET |
GitHub OAuth secret | β |
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.
- Next.js - The React Framework
- Better Auth - Authentication solution
- Drizzle ORM - TypeScript ORM
- Tailwind CSS - Utility-first CSS
- Resend - Email API
For questions and support, please open an issue on GitHub.
Built with β€οΈ by CianCode using modern web technologies