Next.jsReactSaaS

saas-template — Next.js SaaS模板

作者 deessejs

基于 Next.js 16 的单租户 SaaS 启动模板,采用 pnpm 与 Turbo 管理的 monorepo,包含营销站、登录后产品端和文档站三个可独立部署的应用。

看看你的网站会是什么样

浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。

3 个预览视图
桌面端首页1 / 3
桌面端截图首屏预览

由服务器浏览器实际访问页面后截取。

全部页面与视图 3

截图用于了解视觉与布局,交互效果请以实际项目为准。

采集于 2026-10-14查看来源

值得关注的模板亮点

从已有项目资料中,快速了解它的特点。

01

monorepo 内含三个可独立部署的应用:营销站 apps/web、登录后产品端 apps/app、Fumadocs 文档站 apps/docs

02

鉴权基于 Better Auth 与 Drizzle 适配器,包含邮箱验证和密码重置,验证在 apps/app/proxy.ts 中强制执行

03

API 层使用 Hono 与 oRPC,提供端到端类型化路由

04

数据库使用 Drizzle ORM 与 Postgres,单元测试通过 pg-mem 运行,无需真实数据库

05

共享版本集中在 pnpm-workspace.yaml 的 catalogs 中,并设置 catalogMode: strict

06

按单租户设计:未启用 organization 插件、组织 schema 与组织客户端

模板详细介绍

该模板是一个单租户 SaaS 起始项目,仓库由 pnpm 工作区与 Turbo 组织为 monorepo,包含三个可独立部署的应用:apps/web 为无鉴权的营销站点,apps/app 为带 proxy.ts 鉴权守卫的登录后产品端,apps/docs 为 Fumadocs 文档站。共享包覆盖鉴权(Better Auth 配合 Drizzle 适配器,含邮箱验证与密码重置)、API(Hono 与 oRPC 的端到端类型化路由)、数据库(Drizzle ORM、Postgres,测试使用 pg-mem 内存运行器)、UI(shadcn/ui 与 Tailwind v4 设计令牌)、邮件(React Email 模板,开发用 console、生产用 Resend)、环境变量校验(Zod)、Cookie 同意与通用工具。README 明确说明该模板按单租户设计:未启用 Better Auth 的 organization 插件,没有组织相关 schema 与客户端,也未配置组织自动创建的 session 钩子,邮箱验证在 apps/app/proxy.ts 中强制执行。若需要多租户,README 建议改用同仓库的 saas-template-multi-tenant 或单独从 organizationPlugin 开始,并指出本模板无法干净地嫁接多租户能力。README 未提供界面细节、性能数据或除 Vercel 之外的其他部署平台说明。

Next.jsReactSaaS

适合你的项目吗?

适用场景

  • 需要一个包含营销页、登录后产品端和文档站的 SaaS 项目起始结构
  • 希望使用 Better Auth 实现邮箱验证与密码重置等完整鉴权流程
  • 希望以类型化 RPC 方式构建前后端接口,而非使用 GraphQL
  • 希望在无数据库环境下运行单元测试,或在本地用 Docker 启动 Postgres 开发

适合人群

  • 计划构建单租户 SaaS 产品并接受 monorepo 结构的开发者
  • 使用 pnpm 与 Turbo 管理多应用仓库的团队
  • 需要营销站、产品端与文档站分离部署的项目
  • 希望以 Drizzle ORM 管理 Postgres schema 并自动生成鉴权表的项目

上手与定制指南

结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。

  1. 1

    环境要求:Node.js 22.0.0+(engines 中强制)、pnpm 11+、本地 Postgres 可用 Docker(若指向远程数据库可跳过)

  2. 2

    安装步骤:克隆仓库后执行 pnpm install,复制 .env.example 为 .env.local,依次运行 pnpm auth:generate、pnpm db:push,再用 pnpm dev 启动全部应用

  3. 3

    必需环境变量为 BETTER_AUTH_URL、BETTER_AUTH_SECRET(至少 32 字符)和 DATABASE_URL;生产使用 Resend 时还需 RESEND_API_KEY 与 RESEND_FROM_EMAIL

  4. 4

    apps/app 的代理默认信任 localhost:3000 与 localhost:3001,各应用默认端口见 apps/*/README.md

  5. 5

    部署到 Vercel 需为三个应用分别创建项目并按应用配置环境变量;README 未说明其他部署平台

查看仓库使用说明

授权与来源资料

使用条件与限制

免费使用 · 保留许可声明

本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。

使用时需要遵守

  • 允许免费使用、修改、商用和分发该版本代码。
  • 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
  • 代码按现状提供;担保与责任限制以原许可证及适用法律为准。

额外费用与待核对事项

  • 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
  • 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
  • 生产环境使用 Resend 发送邮件时,必须配置 RESEND_API_KEY,即需要 Resend 账户与 API 密钥。
  • 生产环境使用 Resend 时,必须提供在 Resend 上已验证的发件人邮箱地址。
  • 本地开发默认需要 Docker 运行 Postgres;若指向远程数据库则可跳过。
  • 部署到 Vercel 需为三个应用分别创建项目,并按应用逐一配置环境变量。
  • 该模板按单租户设计,无法干净地嫁接多租户能力;如需多租户须改用其他仓库或单独从 organizationPlugin 开始。
查看原文依据

Permission is hereby granted, free of charge

许可证原文

| `RESEND_API_KEY` | Prod only | server | Required when `MAIL_TRANSPORT=resend` |

README 原文

| `RESEND_FROM_EMAIL` | Prod only | server | Verified sender on Resend |

README 原文

- Docker (for local Postgres). Skip if you point `DATABASE_URL` at a remote DB

README 原文

Click the **Deploy with Vercel** button at the top. The monorepo is detected automatically; you will need to create three Vercel projects (one per app) and configure env vars per project.

README 原文

If you need multi-tenant, start from Better Auth's `organizationPlugin` separately. This template will not graft it in cleanly.

README 原文
https://github.com/deessejs/saas-template/blob/main/LICENSEhttps://github.com/deessejs/saas-template/blob/main/README.md

DeepSeek 根据仓库许可证和 README 整理 ·2026-10-14。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。

项目核对记录与介绍依据

模板资料

来源平台
GitHub
资料与维护参考分
资料较完整 · 88 / 100
技术栈
Next.js · React
网站类型
SaaS
这个分数如何计算

本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。

这个项目需要核对什么

记录的仓库更新时间
2026-09-18
截图检查日期
2026-10-14

已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。

目录记录的主要技术栈是 Next.js。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。

查看具体选型方法 →

介绍的制作与核对状态

介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。

审核声明: codex-user-requested-batch-review-20261015 · 2026-10-15

查看当时使用的来源资料

SHA-256: 23a7eef69ffacf7c9eb9682ecf9775daefa43c40feb57f1ad7e2b0d1f4c62520

2026-10-14T21:14:01.530Z

来源文件 / 仓库
<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="public/banner-ds.jpg">
    <source media="(prefers-color-scheme: light)" srcset="public/banner-ds.jpg">
    <img src="public/banner-ds.jpg" alt="SaaS Template banner" width="900">
  </picture>
</p>

<h1 align="center">SaaS Template</h1>

<p align="center">
  <strong>Production-ready single-tenant SaaS starter.</strong>
  Next.js 16 · Better Auth · Drizzle · Tailwind v4 · Deploy in minutes.
</p>

<p align="center">
  <a href="https://github.com/deessejs/saas-template/blob/main/LICENSE">
    <img src="https://img.shields.io/github/license/deessejs/saas-template" alt="License">
  </a>
  <a href="https://github.com/deessejs/saas-template/actions/workflows/ci.yml">
    <img src="https://img.shields.io/github/actions/workflow/status/deessejs/saas-template/ci.yml?label=CI" alt="CI">
  </a>
  <a href="https://github.com/deessejs/saas-template/stargazers">
    <img src="https://img.shields.io/github/stars/deessejs/saas-template?style=social" alt="Stars">
  </a>
</p>

<p align="center">
  <a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fdeessejs%2Fsaas-template">
    <img src="https://vercel.com/button" alt="Deploy with Vercel">
  </a>
  <a href="https://github.com/deessejs/saas-template/codespaces/new">
    <img src="https://github.com/codespaces/badge.svg" alt="Open in GitHub Codespaces">
  </a>
</p>

> 👉 **Need workspaces / multi-tenant?** See [`deessejs/saas-template-multi-tenant`](https://github.com/deessejs/saas-template-multi-tenant) — same monorepo with the Better Auth Organization plugin wired in, for users who need per-tenant data isolation and invite-based memberships.

---

## What's included

| Layer | What you get | Why it matters |
|---|---|---|
| **Apps** | `apps/web` (marketing), `apps/app` (authenticated product), `apps/docs` (Fumadocs) | Three deployable surfaces, each with its own purpose. |
| **Auth** | `packages/auth` ( Better Auth + Drizzle adapter, email verification, password reset | Real auth, not a demo. Production gating in `apps/app/proxy.ts`. |
| **API** | `packages/api` ( Hono + oRPC, end-to-end typed routes | Type-safe RPC without GraphQL. |
| **Database** | `packages/database` ( Drizzle ORM, Postgres, in-memory test runner (pg-mem) | Single source of truth for schema; tests run without a DB. |
| **UI** | `packages/ui` ( shadcn/ui + Tailwind v4, centralized design tokens | One component library, every app reuses it. |
| **Tooling** | pnpm 11 workspaces, Turbo v2, strict catalogs, shared ESLint + TS configs | One command rebuilds, lints, types, tests the whole monorepo. |
| **Single-tenant** | No organization plugin, no org schema, no org client | One user = one workspace. Multi-tenant is opt-in. |

## Why this template

- **Modern, but boring where it matters.** Next.js 16, Tailwind v4, React 19, TypeScript 6. Chosen because they're the default for new SaaS projects in 2026.
- **Lockfile-clean pnpm catalogs.** All shared versions live in `pnpm-workspace.yaml` with `catalogMode: strict`. No drift between apps.
- **Real auth flow.** Email verification is enforced in the proxy. No "demo" auth.
- **Real database.** Postgres locally (Docker) or in the cloud. Schema is generated, not hand-written.
- **Three apps, one repo.** Marketing, product, docs. Each deployable independently to Vercel.

## Quick start

> [!TIP]
> Don't want to install anything locally? [Open in GitHub Codespaces](https://github.com/deessejs/saas-template/codespaces/new). PostgreSQL is pre-configured in the dev container.

### Prerequisites

- Node.js **22.0.0+** (`engines.node: ">=22.0.0"` enforced)
- pnpm **11+** (`corepack enable` if not installed)
- Docker (for local Postgres). Skip if you point `DATABASE_URL` at a remote DB

### Install and run

```bash
# 1. Clone
git clone https://github.com/deessejs/saas-template.git
cd saas-template

# 2. Install dependencies
pnpm install

# 3. Copy environment defaults
cp .env.example .env.local

# 4. Generate the auth schema and push it to your database
pnpm auth:generate
pnpm db:push

# 5. Start every app in dev mode
pnpm dev
```

Each app's default port is in its own `README.md` (under `apps/*/`). `apps/app` proxies trust `localhost:3000` and `localhost:3001` by default. See `packages/auth/src/auth.ts:13`.

## Available commands

| Command | What it does |
|---|---|
| `pnpm dev` | Start every app in dev mode |
| `pnpm build` | Build every workspace |
| `pnpm lint` | Lint every workspace |
| `pnpm typecheck` | Type-check every workspace |
| `pnpm test` | Run unit tests (pg-mem, no DB needed) |
| `pnpm db:generate` | Diff schema → write SQL migration |
| `pnpm db:migrate` | Apply pending migrations |
| `pnpm db:push` | Sync schema directly (dev only. Never in prod) |
| `pnpm db:studio` | Open Drizzle Studio in the browser |
| `pnpm auth:generate` | Regenerate Better Auth schema in `packages/database/src/schema/auth.ts` |
| `pnpm env:check` | Validate that all required env vars are present |
| `pnpm dedupe:check` | Detect duplicated dependencies |

## Environment variables

| Variable | Required | Where | Purpose |
|---|---|---|---|
| `BETTER_AUTH_URL` | Yes | server | Public URL where auth runs |
| `BETTER_AUTH_SECRET` | Yes | server | Min 32 chars. Generate: `openssl rand -base64 32` |
| `DATABASE_URL` | Yes | server | Postgres connection string |
| `ALLOWED_ORIGINS` | No | server | CSV of trusted origins for CSRF |
| `MAIL_TRANSPORT` | No | server | `console` (default) or `resend` |
| `RESEND_API_KEY` | Prod only | server | Required when `MAIL_TRANSPORT=resend` |
| `RESEND_FROM_EMAIL` | Prod only | server | Verified sender on Resend |
| `NEXT_PUBLIC_APP_NAME` | No | client | Marketing site brand |
| `NEXT_PUBLIC_APP_URL` | No | client | Public URL of `apps/app` |

Copy `.env.example` to `.env.local` to start; defaults work for local Docker Postgres.

## Project structure

```
.
├── apps/
│   ├── web/        # Next.js 16 (marketing site) (public, no auth)
│   ├── app/        # Next.js 16 (authenticated product) (proxy.ts guard)
│   └── docs/       # Next.js 16 (Fumadocs site)
├── packages/
│   ├── auth/       # Better Auth setup (single source of truth)
│   ├── database/   # Drizzle ORM + schema (CLI-generated for auth tables)
│   ├── api/        # Hono + oRPC router
│   ├── email/      # React Email templates (Console dev / Resend prod)
│   ├── ui/         # shadcn/ui + Tailwind v4 design system
│   ├── env/        # Zod-validated env (server + client)
│   ├── cookies/    # Cookie consent UI
│   ├── utils/      # General utilities
│   ├── eslint-config/
│   └── typescript-config/
├── pnpm-workspace.yaml  # catalogs (strict)
├── turbo.json           # pipelines
└── .env.example
```

## Deployment

### One-click

Click the **Deploy with Vercel** button at the top. The monorepo is detected automatically; you will need to create three Vercel projects (one per app) and configure env vars per project.

### Per-app mapping

| App | Production URL |
|---|---|
| `apps/web` | `https://yourdomain.com` |
| `apps/app` | `https://app.yourdomain.com` |
| `apps/docs` | `https://docs.yourdomain.com` |

## Customization

This template is **single-tenant by design**. The auth guides under `docs/guides/better-auth/` explain the lock-ins:

- No `organization(...)` plugin in `packages/auth/src/auth.ts`.
- No `databaseHooks.session.create.before` for org auto-create.
- No `organizationClient()` on the client.
- Email verification is enforced in `apps/app/proxy.ts` (unverified users redirect to `/verify-email`).

If you need multi-tenant, start from Better Auth's `organizationPlugin` separately. This template will not graft it in cleanly.

## Architecture notes

- **Proxy, not middleware.** Next.js 16 renamed `middleware.ts` to `proxy.ts`. The auth guard lives at `apps/app/proxy.ts`.
- **Catalogs, not manual pins.** All shared versions are centralized in `pnpm-workspace.yaml` with `catalogMode: strict`.
- **Schema ownership.** `packages/database/src/schema/auth.ts` is owned by the Better Auth CLI. Never hand-edit.
- **Single source of truth for auth config.** Everything lives in `packages/auth/src/auth.ts`; routes and components import from `@workspace/auth`.

## Contributing

Open an issue to discuss larger changes. For typos, broken links, and small fixes, PRs are welcome.

## License

[MIT](./LICENSE). See the LICENSE file for details.

## Support

- Issues: [github.com/deessejs/saas-template/issues](https://github.com/deessejs/saas-template/issues)
- Discussions: [github.com/deessejs/saas-template/discussions](https://github.com/deessejs/saas-template/discussions)
- Email: [[email protected]](mailto:[email protected])
反馈内容错误

看看同类模板

对比同技术栈与用途的模板,找到更适合的视觉与内容结构。