Loading repository data…
Loading repository data…
kx4x / repository
Modern template combining Next.js 15, Drizzle ORM, and Better Auth for scalable web apps. Features type-safe SQL queries, flexible authentication, TypeScript, Tailwind CSS, and responsive design. Includes organized project structure and PostgreSQL support for efficient full-stack development.
This is a modern full-stack template that combines Next.js with Drizzle ORM and Better Auth for a seamless development experience.
git clone https://github.com/kx4x/better-auth-with-drizzle-template.git
cd better-auth-with-drizzle-template
Create a .env file in the project root with the following variables:
# PostgreSQL database connection URL
DATABASE_URL="postgresql://username:password@localhost:5432/database_name"
# Authentication secret key (generate a strong key and keep it secret)
BETTER_AUTH_SECRET="your-secret-key-here"
# Application base URL
BETTER_AUTH_URL="http://localhost:3000"
Tip: To generate a strong secret key, you can use:
openssl rand -base64 32
Choose your preferred package manager:
# Using npm
npm install
# Using yarn
yarn
# Using pnpm
pnpm install
# Using bun
bun install
Run the migration to create the necessary tables in your database:
# Using npm
npm run db:push
# Using yarn
yarn db:push
# Using pnpm
pnpm db:push
# Using bun
bun run db:push
# Using npm
npm run dev
# Using yarn
yarn dev
# Using pnpm
pnpm dev
# Using bun
bun run dev
Now you can access the application at http://localhost:3000.
/
├── public/ # Static files
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── (auth)/ # Authentication routes
│ │ ├── api/ # API routes
│ │ └── dashboard/ # Protected dashboard
│ ├── components/ # Reusable React components
│ ├── db/ # Drizzle ORM configuration and schema
│ └── lib/ # Utilities and configurations
└── drizzle/ # Drizzle migrations
This template uses Better Auth to provide multiple authentication strategies:
This template uses TailwindCSS and shadcn/ui components.
The database schema is defined in src/db/schema.ts. Modify this file to add or alter tables as needed.
To add new pages, create files inside the src/app/ directory. The Next.js App Router uses file system conventions for routing.
# Development
bun run dev # Start the development server
# Database
bun run db:push # Apply schema to database
bun run db:studio # Open Drizzle Studio to manage the database
bun run db:generate # Generate a new migration
bun run db:reset # Reset the database (caution: deletes all data)
# Build and Production
bun run build # Create a production build
bun run start # Start the production server