Next-js-Boilerplate README

The project's README from github.com/ixartz/Next-js-Boilerplate. As one markdown file: README.md.

Boilerplate and Starter for Next.js 16+, Tailwind CSS 4, and TypeScript.

Next js starter banner

🚀 Boilerplate and Starter for Next.js with App Router, Tailwind CSS, and TypeScript ⚡️ Prioritizing developer experience first: Next.js, TypeScript, ESLint, Prettier, Lefthook (replacing Husky), Lint-Staged, Vitest (replacing Jest), Testing Library, Playwright, Commitlint, VSCode, Tailwind CSS, Authentication with Clerk, Database with DrizzleORM (PostgreSQL, SQLite, and MySQL), Local database with PGlite and production with Neon, Error Monitoring with Sentry, Logging with LogTape (replacing Pino.js) and Log Management, Monitoring as Code, Storybook, Multi-language (i18n), AI-powered code reviews with CodeRabbit, Secure with Arcjet (Bot detection, Rate limiting, Attack protection, etc.), and more.

Clone this project and use it to create your own Next.js project. You can check out the live demo at Next.js Boilerplate, which includes a working authentication system.

Sponsors

Clerk – Authentication & User Management for Next.js CodeRabbit Sentry
Arcjet Crowdin Better Stack
PostHog RapidProxy Next.js SaaS Boilerplate with React
Add your logo here

Demo

Live demo: Next.js Boilerplate

Sign Up Sign In
Next.js Boilerplate SaaS Sign Up Next.js Boilerplate SaaS Sign In

Features

Developer experience first, extremely flexible code structure and only keep what you need:

Built-in features from Next.js:

Optional features (easy to add):

Philosophy

Requirements

Getting started

Run the following command on your local environment:

git clone --depth=1 https://github.com/ixartz/Next-js-Boilerplate.git my-project-name
cd my-project-name
npm install

For your information, all dependencies are updated every month.

Then, you can run the project locally in development mode with live reload by executing:

npm run dev

Open http://localhost:3000 with your favorite browser to see your project. For your information, the project is already pre-configured with a local database using PGlite. No extra setup is required to run the project locally.

Need advanced features? Multi-tenancy & Teams, Roles & Permissions, Shadcn UI, End-to-End Typesafety with oRPC, Stripe Payment, Light / Dark mode. Try Next.js Boilerplate Pro.

Or, need a Self-hosted auth stack (Better Auth)? Try Next.js Boilerplate Plus

Set up authentication

To get started, create a Clerk account at Clerk.com and create a new application in the Clerk Dashboard. Then copy the NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY values and add them to your .env.local file (not tracked by Git):

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_pub_key
CLERK_SECRET_KEY=your_clerk_secret_key

You now have a fully functional authentication system with Next.js, including features such as sign up, sign in, sign out, forgot password, reset password, update profile, update password, update email, delete account, and more.

Set up remote database

The project uses DrizzleORM, a type-safe ORM that is compatible with PostgreSQL, SQLite, and MySQL databases. By default, the project is configured to seamlessly work with PostgreSQL, and you have the flexibility to choose any PostgreSQL database provider of your choice.

When you launch the project locally for the first time, it automatically creates a PostgreSQL database on your local machine. This allows you to work with a PostgreSQL database without Docker or any additional setup.

To set up a remote and production database, you need to create a PostgreSQL database and obtain the connection string. One recommended option is to use Neon, which provides a free PostgreSQL database. This database is compatible and has been tested with Next.js Boilerplate.

After creating your Neon account, you can get the connection string and copy it to the DATABASE_URL variable in your .env.production file.

:warning: This project works out of the box with any PostgreSQL provider. Neon is mentioned here because it offers a free tier, and the link is an affiliate link. Feel free to use any PostgreSQL provider that fits your needs.

Create a fresh and empty database

If you want to create a fresh and empty database, you just need to remove the folder local.db from the root of the project. The next time you run the project, a new database will be created automatically.

Translation (i18n) setup

For translation, the project uses next-intl combined with Crowdin. As a developer, you only need to take care of the English (or another default language) version. Translations for other languages are automatically generated and handled by Crowdin. You can use Crowdin to collaborate with your translation team or translate the messages yourself with the help of machine translation.

To set up translation (i18n), create an account at Crowdin.com and create a new project. In the newly created project, you will be able to find the project ID. You will also need to create a new Personal Access Token by going to Account Settings > API. Then, in your GitHub Actions, you need to define the following environment variables: CROWDIN_PROJECT_ID and CROWDIN_PERSONAL_TOKEN.

After defining the environment variables in your GitHub Actions, your localization files will be synchronized with Crowdin every time you push a new commit to the main branch.

Project structure

.
├── README.md                       # README file
├── .github                         # GitHub folder
│   ├── actions                     # Reusable actions
│   └── workflows                   # GitHub Actions workflows
├── .storybook                      # Storybook folder
├── .vscode                         # VSCode configuration
├── migrations                      # Database migrations
├── public                          # Public assets folder
├── src
│   ├── app                         # Next JS App (App Router)
│   ├── components                  # React components
│   ├── libs                        # 3rd party libraries configuration
│   ├── locales                     # Locales folder (i18n messages)
│   ├── models                      # Database models
│   ├── styles                      # Styles folder
│   ├── templates                   # Templates folder
│   ├── types                       # Type definitions
│   ├── utils                       # Utilities folder
│   └── validations                 # Validation schemas
├── tests
│   ├── e2e                         # E2E tests, also includes Monitoring as Code
│   └── integration                 # Integration tests
├── drizzle.config.ts               # Drizzle ORM configuration
├── eslint.config.mjs               # ESLint configuration
├── next.config.ts                  # Next JS configuration
├── package.json                    # NPM dependencies and scripts
├── playwright.config.ts            # Playwright configuration
├── tsconfig.json                   # TypeScript configuration
└── vitest.config.ts                # Vitest configuration

Customization

You can easily configure Next js Boilerplate by searching the entire project for FIXME: to make quick customizations. Here are some of the most important files to customize:

You have full access to the source code for further customization. The provided code is just an example to help you start your project. The sky's the limit 🚀.

Change database schema

To modify the database schema in the project, you can update the schema file located at ./src/models/Schema.ts. This file defines the structure of your database tables using the Drizzle ORM library.

After making changes to the schema, generate a migration by running the following command:

npm run db:generate

This will create a migration file that reflects your schema changes.

After making sure your database is running, you can apply the generated migration using:

npm run db:migrate

There is no need to restart the Next.js server for the changes to take effect.

Commit Message Format

The project follows the Conventional Commits specification, meaning all commit messages must be formatted accordingly. To help you write commit messages, the project provides an interactive CLI that guides you through the commit process. To use it, run the following command:

npm run commit

One of the benefits of using Conventional Commits is the ability to automatically generate GitHub releases. It also allows us to automatically determine the next version number based on the types of commits that are included in a release.

Commit Types

Every commit message follows Conventional Commits and must begin with a type prefix (e.g., feat: add login page). The table below lists the available types:

Type Description
feat New feature or functionality
fix Bug fix
docs Documentation only
style Code formatting without logic changes
refactor Code restructuring without behavior changes
perf Performance improvement
test Adding or updating tests
build Build system
ci CI configuration and scripts
chore Maintenance tasks (dependencies, config)
revert Reverts a previous commit

CodeRabbit AI Code Reviews

The project uses CodeRabbit, an AI-powered code reviewer. CodeRabbit monitors your repository and automatically provides intelligent code reviews on all new pull requests using its powerful AI engine.

Setting up CodeRabbit is simple, visit coderabbit.ai, sign in with your GitHub account, and add your repository from the dashboard. That's it!

Testing

All unit tests are located alongside the source code in the same directory, making them easier to find. The unit test files follow this format: *.test.ts or *.test.tsx. The project uses Vitest and React Testing Library for unit testing. You can run the tests with the following command:

npm run test

Integration & E2E Testing

The project uses Playwright for integration and end-to-end (E2E) testing. Integration test files use the *.integ.ts extension, while E2E test files u

Next-js-Boilerplate (ixartz/Next-js-Boilerplate)

Searching Database…

这是什么?一个可直接用于生产环境的样板和入门套件,用于构建基于 App Router、TypeScript 和 Tailwind CSS 4 的 Next.js 16 应用。项目已预先集成身份认证、数据库、测试以及其他开发体验工具。
这是我要导入的库,还是我克隆后再基于它开发的模板?这是一个入门模板,你可以克隆下来,根据自己的项目进行定制;它不是需要安装到现有应用中的软件包。
我该如何让它运行起来?克隆仓库,安装依赖,然后运行开发命令即可。项目已预先配置好本地 PGlite 数据库,因此在本地运行无需额外设置数据库。
开始之前需要先安装什么?需要 Node.js 24 或更高版本以及 npm;要启用身份认证系统,还需要一个 Clerk 账户。
我需要自己搭建生产环境的数据库吗?在本地,直接使用随附的 PGlite 数据库即可运行;但部署到生产环境时,你需要自行创建 PostgreSQL 数据库(建议使用免费的 Neon),并将连接字符串填入 .env.production 文件中。
这个项目面向哪些人?面向希望获得功能完备、可直接用于生产环境的 Next.js 起点的开发者,无需从零开始配置身份认证、ORM、代码检查和测试。
有哪些部分需要 API 密钥,或会向第三方发送数据?需要。身份认证通过 Clerk 运行,需要 Clerk 的可发布密钥和私密密钥;此外还预先接入了一些可选集成,如 Sentry、PostHog、CodeRabbit 和 Crowdin。
它支持哪些 ORM 和数据库?它使用 DrizzleORM,这是一个类型安全的 ORM,兼容 PostgreSQL、SQLite 和 MySQL,并提供用于查看数据的 Drizzle Studio 以及用于数据库迁移的 Drizzle Kit。
如何支持多语言?使用 next-intl 实现国际化,非默认语言的翻译可通过 Crowdin 进行管理,并可自动生成。
有没有功能更多的付费版本?有,提供付费升级:Next.js Boilerplate Pro 增加了多租户、角色与权限、Shadcn UI 和 Stripe 支付;Next.js Boilerplate Plus 则提供可自托管的 Better Auth 技术栈。
包含哪些测试工具?单元测试使用 Vitest 配合 Testing Library,集成测试和端到端测试使用 Playwright,界面开发则使用 Storybook。
Creator
ixartz
Size
45 MB
Stars
13.1K
Age
6y
Commits · 90 Days