Documentation
Documentation
Introduction

Getting Started

Getting StartedInstallationQuick StartProject Structure

Architecture

Architecture OverviewTech StacktRPC MiddlewareDesign Principles

Patterns

Code Patterns & ConventionsFeature ModulesError HandlingType Safety

Database

DatabaseSchema DefinitionDatabase OperationsMigrationsCaching

API

tRPCProceduresRouterstRPC Proxy Setup
APIsOpenAPIREST Endpoints

Auth & Access

AuthenticationConfigurationOAuth ProvidersRolesSession Management
AuthorizationUser RolesPermissions

Routing & i18n

RoutingDeclarative RoutingNavigation
InternationalizationTranslationsLocale Routing

Components & UI

ComponentsButtonsFormsNavigationDialogs
StylesTailwind CSSThemingTypography

Storage

StorageConfigurationUsageBuckets

Configuration

ConfigurationEnvironment VariablesFeature Flags

Templates

Template GuidesCreate New FeatureCreate New PageCreate Database TableCreate tRPC RouterAdd Translations

Development

DevelopmentCommandsAI AgentsBest Practices

Installation

Clone the repository and set up your development environment

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js: Version 2 or higher (LTS recommended)
  • npm or pnpm: Package manager
  • PostgreSQL: Local or remote instance for the database

VS Code Extensions

Recommended extensions for the best development experience:

ExtensionPurpose
ESLintLinting and code quality
PrettierCode formatting
i18n AllyTranslation management and inline previews
Tailwind CSS IntelliSenseTailwind class autocomplete

[!TIP] When adding new translation keys, run "TypeScript: Restart TS Server" (Cmd/Ctrl+Shift+P) for i18n Ally to recognize them.

Step 1: Clone the Repository

git clone <repository-url>
cd next-template

Step 2: Install Dependencies

Using npm:

npm install

Or using pnpm:

pnpm install

Step 3: Environment Setup

Copy the example environment file:

cp .env.local.example .env

Required Environment Variables

Open .env and fill in these required values:

Database

DATABASE_URL="postgresql://user:password@localhost:5432/mydb"

Authentication

Generate a secret key (minimum 32 characters):

BETTER_AUTH_SECRET="your-secret-key-min-32-chars"
BETTER_AUTH_URL="http://localhost:3000"

Optional Services

Configure these if you plan to use them:

# Email (Resend)
RESEND_API_KEY=""

# File Storage (S3/R2)
S3_ACCESS_KEY=""
S3_SECRET_KEY=""
S3_BUCKET=""
S3_REGION=""
S3_ENDPOINT=""

# OAuth Providers
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""

See src/env/env-server.ts for the complete list of environment variables.

Step 4: Database Setup

Push the schema to your database:

npm run db:push

This command uses Drizzle Kit to synchronize your database schema with the table definitions in src/db/tables/.

What This Does

  • Creates all tables defined in src/db/tables/
  • Sets up primary keys, foreign keys, and indexes
  • Applies default values and constraints
  • Enables Row Level Security (RLS) policies

Database Tables

The schema includes tables for:

  • Authentication - user, session, account, verification
  • Organizations - organization, organization_member, organization_invitation
  • API Keys - api_key
  • Settings - user_settings

See src/db/tables/ for complete table definitions.

Step 5: Run the Development Server

Start the development server:

npm run dev

Open http://localhost:3000 in your browser. You should see the homepage.

Troubleshooting

Database Connection Fails

  • Verify PostgreSQL is running
  • Check DATABASE_URL format
  • Ensure database exists and user has permissions

Port Already in Use

Change the port in package.json:

{
  "scripts": {
    "dev": "next dev -p 3001"
  }
}

Missing Environment Variables

Check for typos in .env and ensure all required variables are set. The app will throw validation errors for missing required vars on startup.

Next Steps

  • Quick Start - Run the app and create your first feature
  • Project Structure - Understand folder organization

On this page

Prerequisites
VS Code Extensions
Step 1: Clone the Repository
Step 2: Install Dependencies
Step 3: Environment Setup
Required Environment Variables
Database
Authentication
Optional Services
Step 4: Database Setup
What This Does
Database Tables
Step 5: Run the Development Server
Troubleshooting
Database Connection Fails
Port Already in Use
Missing Environment Variables
Next Steps