多租户组织、成员、邀请与细粒度权限策略,租户隔离有测试覆盖
BaseworkSaaS — Next.js 后台模板
作者 fizzexual
Basework 是一个基于 Next.js 的多租户 SaaS 启动模板,内置组织与细粒度 RBAC、Stripe 计费、按用量计量积分、带模拟登录的管理后台和审计日志,并支持零配置本地运行。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
目前有 1 张原始预览,可打开完整图片查看设计细节。
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
Stripe 订阅与按用量计量:积分账本、套餐限制、超额上报和客户门户
管理后台支持安全模拟登录、功能开关和不可变审计日志
零配置本地运行:内嵌 PGlite 与模拟邮件、计费、AI 提供方,无需密钥
通过 .env 切换真实 Postgres、Stripe、LLM 和 Resend,无需改代码
包含类型检查、Lint、单元/集成测试和 Playwright E2E,CI 不依赖外部服务
模板详细介绍
Basework 是面向多租户 SaaS 产品的 Next.js 启动代码库,目标用户是希望省去认证、组织、计费、用量计量和管理后台搭建工作的开发者。它提供组织、成员、邀请和细粒度权限策略,租户隔离有测试覆盖;计费链路包含 Checkout、签名校验的 Webhook 与数据库同步、客户门户和套餐变更时重置积分;用量计量以组织为单位的积分记录 API 调用、导出、AI token 等操作,并按套餐限制向 Stripe 上报超额用量。管理后台支持安全模拟登录、功能开关和不可变审计日志。
本地开发无需任何密钥:未设置 DATABASE_URL 时使用内嵌 PGlite,未设置 Stripe 密钥时使用模拟计费,未设置 LLM 密钥时使用模拟 AI,未设置 Resend 密钥时邮件输出到控制台。设置对应 .env 变量后自动切换到真实 Postgres、Stripe、LLM 和邮件服务。项目使用 Drizzle ORM 管理数据库迁移,包含类型检查、Lint、单元与集成测试以及 Playwright 端到端测试,CI 不依赖外部服务。
模板附带一个流式 AI 助手作为用量计量的示例消费者,并提供营销页、认证页、仪表盘和管理后台等页面结构。主题基于语义化设计令牌,支持亮暗模式和侧边栏/顶部导航两种布局。超级管理员可在 /admin/settings 运行时调整外观、开关功能模块、关闭注册或开启维护模式,设置持久化在 platform_settings 单例行中。
限制方面:该模板是启动代码库而非成品 SaaS,需要开发者自行实现产品功能;演示图片、字体、图标等第三方素材需单独核对许可;域名、托管、数据库、支付和 AI 等外部服务可能产生费用。
适合你的项目吗?
适用场景
- 快速搭建需要组织、权限和订阅计费的多租户 SaaS 后台
- 为 API 调用、导出或 AI token 等操作实现按用量计费和积分扣减
- 在管理后台中模拟用户登录排查问题,并保留审计日志
- 在本地无外部服务依赖的情况下开发和测试计费、认证与用量计量流程
- 作为学习多租户隔离、Stripe Webhook 同步和 RBAC 实现的参考项目
适合人群
- 需要现成认证、组织、计费和用量计量基础的 Next.js 开发者
- 计划构建多租户 SaaS 并希望自行实现产品功能的团队
- 需要零配置本地演示环境来评估 SaaS 基础架构的开发者
- 希望参考 Stripe Webhook 同步、RBAC 和审计日志实现的项目
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
本地运行:克隆仓库后执行 pnpm install 和 pnpm dev,访问 http://localhost:3000 使用种子账号登录
- 2
种子账号:[email protected] / password123(owner + admin)和 [email protected] / password123(member)
- 3
生产部署:复制 .env.example 到 .env,配置 DATABASE_URL、Stripe、BETTER_AUTH_SECRET、ENCRYPTION_KEY 和 LLM 密钥
- 4
数据库迁移使用 pnpm db:migrate,Stripe 产品/价格创建使用 pnpm stripe:sync
- 5
部署后需将 cron 指向 POST /api/jobs/tick 以消费持久任务队列
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
- 本地开发默认使用模拟提供方且无需密钥;要接入真实 Postgres、Stripe、邮件和 LLM 服务,必须自行配置对应的 .env 环境变量。
- 零配置运行仅适用于本地演示模式;该模式不连接真实数据库、Stripe 账户或 API 密钥,不能直接用于生产。
- 生产部署需要自行准备 Postgres 数据库(如 Neon)并设置 DATABASE_URL,属于外部服务依赖,可能产生费用。
- 生产环境需自行创建 Stripe 产品与价格并配置 STRIPE_* 密钥,依赖 Stripe 账户,可能产生费用。
- 生产部署必须自行提供 BETTER_AUTH_SECRET、ENCRYPTION_KEY 以及 LLM 密钥,LLM 服务为外部依赖并可能产生费用。
- 部署后需自行配置 cron 定时调用 POST /api/jobs/tick 来消费持久任务队列,否则任务不会被执行。
- 内置 AI 助手仅作为用量计量的示例消费者,并非完整产品功能,开发者需自行实现实际业务逻辑。
- 该模板只是 SaaS 基础框架,产品功能需由开发者自行实现,并需删除不需要的部分。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
It runs locally with mock providers and no keys, and switches to real Postgres, Stripe, email and LLM providers when the matching `.env` values are set.
README 原文
No `.env`, no database, no Stripe account, no API keys. It just runs.
README 原文
Provision Postgres (e.g. [Neon](https://neon.tech)) and set `DATABASE_URL`.
README 原文
Create Stripe products/prices (`pnpm stripe:sync`) and set `STRIPE_*`.
README 原文
Set `BETTER_AUTH_SECRET`, `ENCRYPTION_KEY`, and an LLM key.
README 原文
Point a cron at `POST /api/jobs/tick` to drain the job queue.
README 原文
The included AI assistant is just one example consumer.
README 原文
https://github.com/fizzexual/BaseworkSaaS/blob/main/LICENSEhttps://github.com/fizzexual/BaseworkSaaS/blob/main/README.mdYou bring the product (a CRM, an analytics tool, a dev platform, an AI app — anything); it brings everything around it, and you delete the parts you don't use.
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-05。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料一般 · 73 / 100
- 技术栈
- Next.js · React
- 网站类型
- 后台 · SaaS · 启动器
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2026-10-05
- 截图检查日期
- 2026-10-05
目前没有记录演示链接。请依据仓库说明在本地评估;仅凭截图无法确认交互行为。
目录记录的主要技术栈是 Next.js。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
审核声明: [email protected] · 2026-10-06
查看当时使用的来源资料
SHA-256: 3936c7b58e4a2d76395e6f15109401b1591e6e1095822352cbd590d0ccb0dea5
2026-10-05T18:07:20.479Z
来源文件 / 仓库<div align="center"> # Basework 🌱 ### The complete, multi-tenant SaaS template — you bring the product. Auth · Organizations & fine-grained RBAC · Stripe billing · **usage-based metering** · admin panel with impersonation · audit logs · durable jobs — every functionality your SaaS needs, so you just build the product. **Runs with zero configuration.** [](https://github.com/fizzexual/BaseworkSaaS/actions/workflows/ci.yml) [](./LICENSE)    <br/> <img src="./docs/screenshots/dashboard.png" alt="Basework dashboard" width="100%"/> </div> --- ## About Basework is a starter codebase for building a multi-tenant SaaS product on Next.js. It is for developers who want auth, organizations, billing, usage metering and an admin panel already in place, so they can focus on their own product. It runs locally with mock providers and no keys, and switches to real Postgres, Stripe, email and LLM providers when the matching `.env` values are set. ## Why Basework? Basework isn't tied to one product idea — it's the **complete foundation** every SaaS needs. You bring the product (a CRM, an analytics tool, a dev platform, an AI app — anything); it brings everything around it, and you delete the parts you don't use. - 📊 **Usage-based metering & billing.** Meter any action — API calls, exports, AI tokens — as per-org **credits**, enforce plan limits, and report overage to Stripe. The included AI assistant is just one example consumer. Almost no template ships this. - 🏢 **Real multi-tenancy.** Organizations, members, invitations, and a **fine-grained permission policy** (not bare role strings). Tenant isolation is covered by tests. - 💳 **Billing done right.** Checkout → **signature-verified webhook → database** sync, customer portal, plan changes that reset credits. The "everyone fakes it" part is real and tested. - 🛡️ **Admin panel with secure impersonation**, feature flags, and an immutable **audit log**. - ⚡ **Zero-config dev.** `pnpm dev` boots a fully seeded demo with **no accounts and no keys** — embedded Postgres (PGlite), plus mock email / billing / AI providers. Flip to production by filling `.env`. - ✅ **Genuinely tested.** Typecheck, lint, unit + integration (in-memory Postgres), and Playwright E2E — all in CI with no external services. > **The 30-second pitch:** clone it, run `pnpm dev`, and you have a multi-tenant dashboard with working billing, usage metering, an admin panel, and a streaming AI *example* — before you've created a single account anywhere. Then delete what you don't need and build your product. ## Quickstart ```bash git clone https://github.com/fizzexual/BaseworkSaaS.git cd BaseworkSaaS pnpm install pnpm dev ``` Open **http://localhost:3000** and sign in with the seeded demo accounts: | Account | Email | Password | Role | | --- | --- | --- | --- | | Owner / super-admin | `[email protected]` | `password123` | owner + admin | | Member | `[email protected]` | `password123` | member | No `.env`, no database, no Stripe account, no API keys. It just runs. ## Screenshots | AI assistant (streamed + metered) | Billing & plans | | --- | --- | | <img src="./docs/screenshots/ai-chat.png" width="100%"/> | <img src="./docs/screenshots/billing.png" width="100%"/> | | Usage ledger | Admin panel | | --- | --- | | <img src="./docs/screenshots/usage.png" width="100%"/> | <img src="./docs/screenshots/admin.png" width="100%"/> | ## Stack | Layer | Choice | | --- | --- | | Framework | **Next.js 16** (App Router, RSC, Server Actions), React 19, TypeScript (strict) | | UI | Tailwind CSS v4, Radix primitives, a token-driven design system with light & dark themes | | Database | **Drizzle ORM** — embedded **PGlite** in dev ↔ **Postgres / Neon** in prod | | Auth | **Better Auth** — email+password, OAuth, organizations, admin + impersonation | | Billing | **Stripe** (subscriptions + usage metering) behind a provider interface, with a mock provider for zero-config | | AI | **Vercel AI SDK** — streaming chat, credit metering, bring-your-own keys; mock provider when no key | | Infra | durable job queue, feature flags, per-plan rate limiting, structured logging, audit log, React Email + Resend | | Tooling | Biome, Vitest, Playwright, GitHub Actions | ## How it works Basework has **two modes**, chosen automatically from the environment: ``` DATABASE_URL empty → embedded PGlite (Postgres in-process) | set it → Postgres / Neon STRIPE_SECRET_KEY → mock billing (simulated checkout) | set it → real Stripe OPENAI/ANTHROPIC key → mock AI (deterministic streaming) | set it → real LLM RESEND_API_KEY empty → console email transport | set it → Resend ``` The credit-metering flow is the heart of it: ``` chat request → check org credit balance / plan overage policy → stream the model response (Vercel AI SDK) → on finish: count tokens → deduct credits (atomic, ledgered) → report overage to Stripe as a metered usage event ``` ## Theming & layout Every component is built on semantic design tokens (`bg-card`, `text-foreground`, `bg-brand`, …) defined once in [`src/app/globals.css`](src/app/globals.css) — so the whole app re-skins from one file. Two switches ship out of the box: - **Light / dark mode** — a persisted toggle (next-themes) in the sidebar and marketing header. The `.dark` class overrides the palette vars via `@theme inline`; no per-component changes. - **Nav layout** — a left sidebar rail or a horizontal top bar. Seed the default with `NEXT_PUBLIC_NAV_LAYOUT=topnav`, or flip it live from the admin panel (below). ## Superadmin controls A super-admin (global `admin` role or a `SUPER_ADMIN_EMAILS` address) configures the whole app at runtime from **`/admin/settings`** — no redeploy: - **Appearance** — nav layout, default theme, brand name, and accent color, applied app-wide and live. - **Feature modules** — switch AI, Billing, Members, or Usage off; a disabled module disappears from the nav, its pages redirect, and its API route / server actions reject (enforced server-side, not just in the UI). - **Access** — close sign-ups (invite-only mode — unexpired invitations still work) or flip on maintenance mode, which locks the app for non-admins in both the UI and at the mutation boundary. Settings persist in a `platform_settings` singleton row; module on/off rides the existing feature-flags table. The env flags seed the initial defaults, and the stored values override them once set — so it still boots zero-config. ## Going to production 1. Copy `.env.example` to `.env` and fill the values. 2. Provision Postgres (e.g. [Neon](https://neon.tech)) and set `DATABASE_URL`. 3. `pnpm db:migrate` to apply migrations. 4. Create Stripe products/prices (`pnpm stripe:sync`) and set `STRIPE_*`. 5. Set `BETTER_AUTH_SECRET`, `ENCRYPTION_KEY`, and an LLM key. 6. Deploy. Point a cron at `POST /api/jobs/tick` to drain the job queue. Run `pnpm doctor` anytime to see which mode each subsystem is in. ## Project structure ``` src/ app/ (marketing)/ # landing + pricing (auth)/ # sign-in / sign-up / accept-invitation dashboard/ # app shell: overview, ai, members, usage, billing, settings admin/ # super-admin: platform settings, users, flags, audit api/ # better-auth, stripe webhook, ai chat, jobs lib/ auth/ db/ billing/ ai/ rbac/ email/ jobs/ flags/ modules/ settings/ ratelimit/ observability/ env server/ # request context + server actions drizzle/ # schema migrations tests/ # vitest (unit + integration) and playwright (e2e) ``` ## Scripts | Command | Description | | --- | --- | | `pnpm dev` | Run the app (zero-config) | | `pnpm build` / `pnpm start` | Production build / serve | | `pnpm typecheck` | `tsc --noEmit` | | `pnpm lint` / `pnpm lint:fix` | Biome check / autofix | | `pnpm test` | Vitest (in-memory Postgres) | | `pnpm test:e2e` | Playwright end-to-end | | `pnpm db:generate` / `pnpm db:migrate` | Drizzle migrations | | `pnpm stripe:sync` | Create Stripe products/prices/meters | | `pnpm doctor` | Print the active runtime modes | ## How it compares | | **Basework** | Typical boilerplate | | --- | :---: | :---: | | Usage-based **metering & credits** | ✅ | ❌ | | Multi-tenant orgs + **fine-grained RBAC** | ✅ | partial | | Admin **impersonation** | ✅ | ❌ | | **Tested** Stripe webhook sync | ✅ | ❌ | | **Zero-config** runnable demo | ✅ | ❌ | | Audit log + durable jobs | ✅ | rare | | 100% open source (MIT) | ✅ | varies | ## Contributing Contributions are welcome — see [CONTRIBUTING.md](./CONTRIBUTING.md). Please keep `pnpm typecheck`, `pnpm lint`, `pnpm test`, and `pnpm build` green. ## License [MIT](./LICENSE) — use it for anything, including commercial products.
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

ai-website-cloner-template
Clone any website with one command using AI coding agents
Next.js · 启动器

Next.js SaaS Starter
Next.js SaaS Starter 是 Next.js 官方维护的 SaaS 起点模板,定位介于学习资源和可直接部署的脚手架之间。
Next.js · SaaS

Next.js Commerce
Next.js Commerce 是 Vercel 团队维护的电商启动模板,基于 Next.js App Router 构建,采用服务端渲染、React Server Components、Server Actions …
Next.js · 电商

Next-js-Boilerplate
Next-js-Boilerplate 是一个面向 Next.js 16、Tailwind CSS 4 和 TypeScript 的启动器,核心定位是开发者体验优先。
Next.js · 启动器

tailwind-nextjs-starter-blog
tailwind-nextjs-starter-blog 是一个面向个人技术博客的 Next.js 与 Tailwind CSS 启动模板,其 v2 版本基于 App Router 与 React Server Comp…
Next.js · 博客

next-forge
Production-grade Turborepo template for Next.js apps.
Next.js · 启动器
