Skip to content

πŸš€ Modern Next.js full-stack starter with Better Auth, Drizzle ORM, tRPC, and TanStack Query β€” built with Bun & TypeScript for fast and secure apps.

License

Notifications You must be signed in to change notification settings

Chust3r/next-better-stack

Repository files navigation

⚑ next-better-stack

A full-stack starter template built with modern technologies:

  • βœ… Next.js App Router
  • πŸ” Better Auth
  • 🧱 Drizzle ORM + PostgreSQL
  • 🧠 TRPC + TanStack Query (React Query)
  • πŸ”’ Secure sessions & role-based access
  • πŸ› οΈ Built with Bun, TypeScript, and Zod

πŸš€ Tech Stack

Technology Purpose
Next.js App Router + Server Actions
Better Auth Authentication & Authorization
Drizzle ORM Type-safe SQL with PostgreSQL
TanStack Query Client-side fetching + caching
TRPC Type-safe backend API calls
Zod Schema validation
Bun Runtime + Tooling

πŸ“¦ Installation

git clone https://github.com/Chust3r/next-better-stack.git
cd next-better-stack

bun install
# or: pnpm install / npm install / yarn install

🌱 Environment Variables

Create a .env file in the root directory and set the following environment variables:

# .env

# Better Auth
BETTER_AUTH_SECRET=cz6qRoGz7DXXomsUpeSlIEPs5Yw9RuPj
BETTER_AUTH_URL=http://localhost:3000

# PostgreSQL (Drizzle)
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/postgres

πŸ› οΈ Dev Scripts

Command Description
bun dev Start dev server with Turbopack
bun build Build the project
bun start Start production server
bun auth:generate Generate Better Auth boilerplate
bun db:push Push schema to DB
bun db:migrate Run migrations
bun db:introspect Introspect DB to schema
bun db:generate Generate schema/migrations
bun db:view Open Drizzle Studio
bun db:drop Drop all DB tables
bun lint Run Next.js lint
bun lint:fix Fix lint errors
bun lint:strict Fail on any warnings
bun prepare Setup Husky Git hooks

# Clone and install dependencies
git clone https://github.com/Chust3r/next-better-stack.git
cd next-better-stack
bun install

# Setup your .env
cp .env.example .env

# Generate auth files
bun auth:generate

# Push your database schema
bun db:push

# Start dev server
bun dev

πŸ“ Project Structure

β”œβ”€β”€ app/                  # Next.js App Router directory (routes and pages)
β”œβ”€β”€ auth/                 # Better Auth configuration and handlers
β”œβ”€β”€ components/           # Shared React components (UI, layout, etc.)
β”œβ”€β”€ config/               # Project-wide configuration (e.g., constants, env)
β”œβ”€β”€ database/             # Drizzle ORM schema definitions and database logic
β”œβ”€β”€ lib/                  # Utility functions and reusable libraries
β”œβ”€β”€ server/               # TRPC routers and backend procedures
β”œβ”€β”€ types/                # Global TypeScript types
β”œβ”€β”€ middleware.ts         # Next.js middleware for auth/session handling
└── .env                  # Environment variables (not committed)

πŸ§ͺ TRPC + React Query Example

import { useTRPC } from '@components/providers/trpc-provider';
import { useQuery } from '@tanstack/react-query';

export default function HomePage() {
  const trpc = useTRPC();

  const { data, isLoading } = useQuery(trpc.example.getExample.queryOptions());

  return <div>Home Page</div>;
}

πŸ’… Linting & Formatting

  • Uses Prettier, ESLint, and Tailwind Prettier plugin
  • Automatically formats staged files via lint-staged

πŸ§‘β€πŸ’» Contributing

  • Fork & clone the repo
  • Create a new branch: git checkout -b feature/my-feature
  • Commit your changes: git commit -am 'Add my feature'
  • Push to branch: git push origin feature/my-feature
  • Open a pull request πŸš€

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸš€ Modern Next.js full-stack starter with Better Auth, Drizzle ORM, tRPC, and TanStack Query β€” built with Bun & TypeScript for fast and secure apps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published