next-forge
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesenext-forge
next-forge
next-forge is a production-grade Turborepo template for building Next.js SaaS applications. It provides a monorepo structure with multiple apps, shared packages, and integrations for authentication, database, payments, email, CMS, analytics, observability, security, and more.
next-forge是一个用于构建Next.js SaaS应用的生产级Turborepo模板。它提供了包含多个应用、共享包的单体仓库结构,并集成了认证、数据库、支付、邮件、CMS、分析、可观测性、安全等功能。
Quick Start
快速开始
Initialize a new project:
bash
npx next-forge@latest initThe CLI prompts for a project name and package manager (bun, npm, yarn, or pnpm). After installation:
- Set the in
DATABASE_URLpointing to a PostgreSQL database (Neon recommended).packages/database/.env - Run database migrations:
bun run migrate - Add any optional integration keys to the appropriate files.
.env.local - Start development:
bun run dev
All integrations besides the database are optional. Missing environment variables gracefully disable features rather than causing errors.
初始化新项目:
bash
npx next-forge@latest initCLI会提示输入项目名称和包管理器(bun、npm、yarn或pnpm)。安装完成后:
- 在中设置
packages/database/.env,指向PostgreSQL数据库(推荐使用Neon)。DATABASE_URL - 运行数据库迁移:
bun run migrate - 将可选的集成密钥添加到对应的文件中。
.env.local - 启动开发环境:
bun run dev
除数据库外,所有集成都是可选的。缺失环境变量会优雅地禁用对应功能,而非引发错误。
Architecture Overview
架构概述
The monorepo contains apps and packages. Apps are deployable applications. Packages are shared libraries imported as .
@repo/<package-name>Apps (in ):
/apps/| App | Port | Purpose |
|---|---|---|
| 3000 | Main authenticated SaaS application |
| 3001 | Marketing website with CMS and SEO |
| 3002 | Serverless API for webhooks, cron jobs |
| 3003 | React Email preview server |
| 3004 | Documentation site (Mintlify) |
| 6006 | Design system component workshop |
| 3005 | Prisma Studio for database editing |
Core Packages: , , , , , , , , , , , , , , , , , , , , .
authdatabasepaymentsemailcmsdesign-systemanalyticsobservabilitysecuritystorageseofeature-flagsinternationalizationwebhookscronnotificationscollaborationairate-limitnext-configtypescript-configFor detailed structure, see .
references/architecture.md单体仓库包含应用(apps)和包(packages)。应用是可部署的程序,包是可作为导入的共享库。
@repo/<package-name>应用(位于目录下):
/apps/| 应用 | 端口 | 用途 |
|---|---|---|
| 3000 | 主认证SaaS应用 |
| 3001 | 带CMS和SEO的营销网站 |
| 3002 | 用于Webhook、定时任务的无服务器API |
| 3003 | React Email预览服务器 |
| 3004 | 文档站点(基于Mintlify) |
| 6006 | 设计系统组件工作台 |
| 3005 | 用于数据库编辑的Prisma Studio |
核心包:, , , , , , , , , , , , , , , , , , , , .
authdatabasepaymentsemailcmsdesign-systemanalyticsobservabilitysecuritystorageseofeature-flagsinternationalizationwebhookscronnotificationscollaborationairate-limitnext-configtypescript-config如需了解详细结构,请查看。
references/architecture.mdKey Concepts
核心概念
Environment Variables
环境变量
Environment variable files live alongside apps and packages:
- — Main app keys (Clerk, Stripe, etc.)
apps/app/.env.local - — Marketing site keys
apps/web/.env.local - — API keys
apps/api/.env.local - —
packages/database/.env(required)DATABASE_URL - — BaseHub token
packages/cms/.env.local - — Languine project ID
packages/internationalization/.env.local
Each package has a file that validates environment variables with Zod via . Type safety is enforced at build time.
keys.ts@t3-oss/env-nextjs环境变量文件与应用和包存放在一起:
- — 主应用密钥(Clerk、Stripe等)
apps/app/.env.local - — 营销站点密钥
apps/web/.env.local - — API密钥
apps/api/.env.local - —
packages/database/.env(必填)DATABASE_URL - — BaseHub令牌
packages/cms/.env.local - — Languine项目ID
packages/internationalization/.env.local
每个包都有一个文件,通过使用Zod验证环境变量。构建时会强制进行类型安全检查。
keys.ts@t3-oss/env-nextjsInter-App URLs
应用间URL
Local URLs are pre-configured:
NEXT_PUBLIC_APP_URL=http://localhost:3000NEXT_PUBLIC_WEB_URL=http://localhost:3001NEXT_PUBLIC_API_URL=http://localhost:3002NEXT_PUBLIC_DOCS_URL=http://localhost:3004
Update these to production domains when deploying (e.g., , ).
app.yourdomain.comwww.yourdomain.com本地URL已预先配置:
NEXT_PUBLIC_APP_URL=http://localhost:3000NEXT_PUBLIC_WEB_URL=http://localhost:3001NEXT_PUBLIC_API_URL=http://localhost:3002NEXT_PUBLIC_DOCS_URL=http://localhost:3004
部署时请将这些URL更新为生产域名(例如, )。
app.yourdomain.comwww.yourdomain.comServer Components First
优先使用服务端组件
page.tsxlayout.tsx'use client'page.tsxlayout.tsx'use client'Graceful Degradation
优雅降级
All integrations beyond the database are optional. Clients use optional chaining (e.g., , ). If the corresponding environment variable is not set, the feature is silently disabled.
stripe?.prices.list()resend?.emails.send()除数据库外,所有集成都是可选的。客户端使用可选链(例如, )。如果未设置对应的环境变量,该功能会被静默禁用。
stripe?.prices.list()resend?.emails.send()Common Tasks
常见任务
Running Development
启动开发环境
bash
bun run dev # All apps
bun dev --filter app # Single app (port 3000)
bun dev --filter web # Marketing site (port 3001)bash
bun run dev # 启动所有应用
bun dev --filter app # 启动单个应用(端口3000)
bun dev --filter web # 启动营销站点(端口3001)Database Migrations
数据库迁移
After changing :
packages/database/prisma/schema.prismabash
bun run migrateThis runs Prisma format, generate, and db push in sequence.
修改后:
packages/database/prisma/schema.prismabash
bun run migrate此命令会依次运行Prisma format、generate和db push。
Adding shadcn/ui Components
添加shadcn/ui组件
bash
npx shadcn@latest add [component] -c packages/design-systemUpdate existing components:
bash
bun run bump-uibash
npx shadcn@latest add [component] -c packages/design-system更新现有组件:
bash
bun run bump-uiAdding a New Package
添加新包
Create a new directory in with a using the naming convention. Add it as a dependency in consuming apps.
/packages/package.json@repo/<name>在目录下创建新目录,并创建,使用命名规范。在需要使用该包的应用中将其添加为依赖。
/packages/package.json@repo/<name>Linting and Formatting
代码检查与格式化
bash
bun run lint # Check code style (Ultracite/Biome)
bun run format # Fix code stylebash
bun run lint # 检查代码风格(基于Ultracite/Biome)
bun run format # 修复代码风格Testing
测试
bash
bun run test # Run tests across monorepobash
bun run test # 在整个单体仓库中运行测试Building
构建
bash
bun run build # Build all apps and packages
bun run analyze # Bundle analysisbash
bun run build # 构建所有应用和包
bun run analyze # 包分析Deployment
部署
Deploy to Vercel by creating separate projects for , , and — each pointing to its respective root directory under . Add environment variables per project or use Vercel Team Environment Variables.
appwebapi/apps/For detailed setup and customization instructions, see:
- — Installation, prerequisites, environment variables, database and Stripe CLI setup
references/setup.md - — Detailed documentation for every package
references/packages.md - — Swapping providers, extending features, deployment configuration
references/customization.md - — Full monorepo structure, Turborepo pipeline, scripts
references/architecture.md
通过Vercel部署时,需为、和创建单独的项目——每个项目指向下对应的根目录。可为每个项目添加环境变量,或使用Vercel团队环境变量。
appwebapi/apps/如需详细的配置和定制说明,请查看:
- — 安装、前置条件、环境变量、数据库和Stripe CLI配置
references/setup.md - — 所有包的详细文档
references/packages.md - — 替换提供商、扩展功能、部署配置
references/customization.md - — 完整单体仓库结构、Turborepo流水线、脚本
references/architecture.md