Quick Start Guide
TL;DR (Fastest Way)
- bun install 2) cp .env.example .env.local 3) bun run init 4) bun run dev
bun install && cp .env.example .env.local && bun run init && bun run dev
Get Started with NextJS Base in 10 Minutes
Get Project · Environment Setup · One-Click Initialization · Next Steps
📋 Overview
- Environment: Node.js 20.9+, PostgreSQL 16+ (or cloud service), recommended package manager: bun.
- Goal: Complete "Install → Initialize → Start" in 10 minutes.
This guide will help you complete the project's environment setup and startup in 10 minutes.
Prerequisites
| Tool | Version Requirement | Description |
|---|---|---|
| Node.js | 20.9+ | Recommended LTS version |
| PostgreSQL | 16+ | Or use cloud database services (e.g., Supabase, Neon) |
| bun/pnpm/npm/yarn | Latest | Recommended: bun |
| Git | Latest | Version control |
| GitHub Account | - | For Forking the project |
🍴 Get Project
Method 1: Fork Project (Recommended)
Recommended: This allows you to keep your own modifications while easily receiving upstream updates.
- Visit NextJS Base GitHub Repository
- Click the Fork button in the top right corner
- Select your GitHub account as the target
- After Forking, clone your own repository:
# Replace your-username with your GitHub username
git clone https://github.com/your-username/nextjs-base.git my-project
cd my-project- (Optional) Add upstream repository for syncing updates:
git remote add upstream https://github.com/huglemon/nextjs-base.git
# Later sync upstream updates
git fetch upstream
git merge upstream/developMethod 2: Use Template
If you want to be completely independent without maintaining a connection to the original repository:
- Visit NextJS Base GitHub Repository
- Click Use this template → Create a new repository
- Fill in your repository name and click create
- Clone the newly created repository:
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-nameMethod 3: Direct Clone (For Experience Only)
⚠️ Note: Direct cloning cannot push modifications to the original repository, only suitable for quick experience.
git clone https://github.com/huglemon/nextjs-base.git
cd nextjs-base🔧 Environment Setup
1. Install Dependencies (Recommended: bun)
bun install
pnpm install
npm install
yarn install
2. Configure Environment Variables
Copy the environment variable template:
cp .env.example .env.localEdit the .env.local file:
# Database Connection (Required)
DATABASE_URL="postgresql://username:password@localhost:5432/your_database?schema=public"
# Better Auth Configuration (Required)
BETTER_AUTH_SECRET="your-secret-key-at-least-32-characters"
BETTER_AUTH_URL="http://localhost:3000"
# Cloud Storage (Optional, for asset management)
# Supports: r2, s3, aliyun, qiniu - switch via CDN_MODE
CDN_MODE="r2"
R2_ACCOUNT_ID="your-account-id"
R2_ACCESS_KEY_ID="your-access-key"
R2_SECRET_ACCESS_KEY="your-secret-key"
R2_BUCKET_NAME="your-bucket"
R2_PUBLIC_URL="https://your-bucket.r2.cloudflarestorage.com"
# For more storage service configurations, see /docs/admin/guides/STORAGE3. Prepare Database
Local PostgreSQL
# Login to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE your_database;
# Exit
\qUse Cloud Database (Recommended)
Recommended cloud database services, no local installation required:
| Service | Description | Free Tier |
|---|---|---|
| Supabase | Open-source Firebase alternative | 500MB |
| Neon | Serverless PostgreSQL | 512MB |
| Vercel Postgres | Native Vercel integration | 256MB |
After creating the database, fill in the connection string in .env.local's DATABASE_URL.
🚀 One-Click Initialization
Execute Initialization
Just run one command to complete all initialization work:
This command will automatically complete:
- ✅ Load
.env.localenvironment variables - ✅ Generate Prisma Client
- ✅ Create database table structure
- ✅ Import seed data (RBAC permissions, menus, example data)
- ✅ Create super admin account (interactive email and password input)
╔═══════════════════════════════════════════════════════════╗
║ NextJS Base Admin - Initialization ║
╚═══════════════════════════════════════════════════════════╝
[1/4] Checking environment...
✓ Loaded environment from .env.local
✓ DATABASE_URL found
[2/4] Setting up database schema...
✓ Prisma Client generated
✓ Database schema created
[3/4] Importing seed data...
✓ 43 permissions created
✓ 17 menus created
✓ 8 roles created
✓ 3 example records created
[4/4] Creating super admin account...
Admin Email: [email protected]
Admin Password: ********
✓ Super admin created
╔═══════════════════════════════════════════════════════════╗
║ ✅ Initialization Completed! ║
╚═══════════════════════════════════════════════════════════╝Non-Interactive Initialization (CI/CD)
If you want to skip interactive input, you can preset admin information via environment variables:
Step-by-Step Execution
If you want more granular control over the initialization process:
🎉 Start Project
Development Mode
Access Application
| Page | Address |
|---|---|
| Frontend Home | http://localhost:3000 |
| Admin Panel | http://localhost:3000/admin |
Use the admin account you created during initialization to log in to the admin panel.
⚠️ Security Tip: Please use a strong password and change it regularly in production!
👤 Super Admin Explanation
What is a Super Admin?
Super admin is the highest-privilege user in the system:
| Attribute | Value | Description |
|---|---|---|
role | admin | Better Auth's admin role |
roles | [] | No RBAC roles needed |
isBackendAllowed | true | Allowed to access admin panel |
Important:
role: 'admin'has all permissions and does not need RBAC role assignment.
User Type Comparison
| Type | role | roles | isBackendAllowed | Description |
|---|---|---|---|---|
| Regular User | user | [] | false | Can only access frontend |
| Admin User | user | ['role_id'] | true | Needs RBAC role assignment |
| Super Admin | admin | [] | true | Has all permissions |
📦 Seed Data Explanation
The initialization script imports the following preset data (using fixed IDs, all installation system data is consistent):
RBAC Data
| Type | Count | Description |
|---|---|---|
| Permissions | 43 | Includes CRUD, RBAC, system management permissions |
| Menus | 17 | Dashboard, Example, RBAC, System, Links |
| Roles | 8 | Admin Roles, User Roles and their sub-roles |
Preset Roles
| Role Name | Description |
|---|---|
Super Admin | Full permissions |
Demo - Readonly | Global read-only |
Admin - RBAC Ops (No Delete) | RBAC writable but no delete |
Demo - RBAC Readonly + Example Write | Demo role |
Example Data
| Type | Count | Description |
|---|---|---|
| Example Data | 3 | SmartCrudPage demo data |
✅ Verify Installation
Checklist
- Project starts successfully without errors
- Can access frontend home page
- Can access admin login page
- Can log in with admin account
- Admin menu displays normally (Dashboard, Example, User & Permission, System, Links)
- Can access Example > Data Table > Basic page
Common Issues
Database Connection Failed
Check if the DATABASE_URL configuration in .env.local is correct:
DATABASE_URL="postgresql://username:password@host:port/database_name?schema=public"Ensure:
- PostgreSQL service is started
- Username and password are correct
- Database is created
- Port number is correct (default 5432)
Initialization Script Error "DATABASE_URL not found"
Ensure .env.local file exists and format is correct:
# Check if file exists
ls -la .env.local
# Check content
cat .env.localNote:
- Environment variables should not have extra spaces
- If values contain special characters, wrap them in double quotes
Prisma Migration Failed
Try resetting the database:
# Reset database (will delete all data)
bunx prisma migrate reset
# Re-run initialization
bun run initLogin Admin Shows No Permission
Ensure your account is a super admin (role: 'admin'), or has been assigned the correct RBAC role.
You can check user data via Prisma Studio:
How to Add More Admins?
Method 1: Via Command Line
Method 2: Via Admin Panel
Login to Admin → User & Permission → Users → Create User → Set role: admin
🎯 Next Steps
Congratulations on completing project initialization! Next you can:
Create First Page
Complete announcement management CRUD page in 15 minutes
Project Structure
Familiarize yourself with app/(client) and admin directories in 5 minutes
Overall Architecture
Understand data flow, permissions, and core components in 10 minutes
Complete Example
Read end-to-end coupon management example in 20 minutes
📜 Available Commands
| Command | Description |
|---|---|
bun run init | One-click initialization (recommended) |
bun run dev | Start development server |
bun run build | Build production version |
bun run db:generate | Generate Prisma Client |
bun run db:push | Push Schema to database |
bun run db:migrate | Execute database migration |
bun run db:studio | Open Prisma Studio |
bun run db:seed | Import seed data |
bun run db:admin | Create super admin |