A production-ready Next.js starter template with BetterAuth, Flowglad, tRPC, and Drizzle ORM. Perfect for building full-stack applications with authentication, billing, and type-safe APIs.
- Next.js 16 - React framework with App Router
- BetterAuth - Modern authentication and user management
- Flowglad - Billing and subscription management
- tRPC - End-to-end typesafe APIs
- Drizzle ORM - PostgreSQL database with type-safe queries
- TypeScript - Type safety throughout
- Tailwind CSS - Utility-first CSS framework
- shadcn/ui - Beautiful UI component library
- ✅ Authentication - Email/password authentication with BetterAuth
- ✅ Billing - Subscription management with Flowglad
- ✅ Type-Safe APIs - End-to-end type safety with tRPC
- ✅ Database - PostgreSQL with Drizzle ORM migrations
- ✅ UI Components - Pre-built shadcn/ui components
- ✅ TypeScript - Full type safety across the stack
- Node.js >= 18.18.0
- pnpm >= 9.12.0
- PostgreSQL database
pnpm installCopy the example environment file:
cp .env.example .env.localFill in the required values in .env.local:
-
DATABASE_URL- PostgreSQL connection string- Example:
postgresql://user:password@localhost:5432/dbname
- Example:
-
BETTER_AUTH_SECRET- Secret key for BetterAuth session encryption- Generate with:
openssl rand -base64 32
- Generate with:
-
FLOWGLAD_API_KEY- API key for Flowglad billing- Get your API key from: https://flowglad.com
Generate and run database migrations:
pnpm db:generate
pnpm db:migratepnpm devOpen http://localhost:3000 to see the application.
pnpm dev- Start development serverpnpm build- Build for productionpnpm start- Start production serverpnpm lint- Run ESLintpnpm lint:fix- Fix ESLint errors automaticallypnpm type-check- Run TypeScript type checkingpnpm test- Run tests with Vitestpnpm db:generate- Generate database migrationspnpm db:migrate- Run database migrationspnpm db:studio- Open Drizzle Studio (database GUI)
├── src/
│ ├── app/ # Next.js App Router pages and routes
│ │ ├── api/ # API routes (tRPC, BetterAuth, Flowglad)
│ │ ├── sign-in/ # Sign in page
│ │ └── sign-up/ # Sign up page
│ ├── components/ # React components
│ │ └── ui/ # shadcn/ui components
│ ├── lib/ # Utility functions and configurations
│ │ ├── auth.ts # BetterAuth configuration
│ │ ├── auth-client.ts # BetterAuth client
│ │ └── flowglad.ts # Flowglad configuration
│ └── server/ # Server-side code
│ ├── api/ # tRPC routers
│ └── db/ # Database schema and client
├── drizzle/ # Generated database migrations
└── public/ # Static assets
This template uses BetterAuth for authentication. Users can sign up and sign in with email/password. The authentication state is managed server-side with secure cookies.
Flowglad is integrated for subscription and billing management. The Flowglad provider is configured to work with BetterAuth sessions.
The project uses Drizzle ORM with PostgreSQL. The schema includes the necessary tables for BetterAuth (users, sessions, accounts, verifications). You can extend the schema in src/server/db/schema.ts.
MIT