> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trytrellis.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Next.js + oRPC + PostgreSQL

> Next.js 全栈应用 + oRPC API 层 + PostgreSQL 的编码规范模板

适用于生产级 Next.js 应用的完整编码规范模板，包含 oRPC API 层、Drizzle ORM 和 PostgreSQL。

<Card title="下载模板" icon="download" href="https://download-directory.github.io/?url=https://github.com/mindfold-ai/Trellis/tree/main/marketplace/specs/nextjs-fullstack">
  下载 ZIP 并解压到 `.trellis/spec/`
</Card>

## 包含内容

| 分类 | 文件数  | 覆盖范围                        |
| -- | ---- | --------------------------- |
| 前端 | 12 个 | 组件、Hooks、状态、oRPC、AI SDK、CSS |
| 后端 | 10 个 | oRPC Router、数据库、认证、性能、日志    |
| 指南 | 3 个  | 跨层思考、实现前检查清单                |
| 共享 | 4 个  | TypeScript、代码质量、依赖管理        |
| 坑点 | 5 个  | PostgreSQL、构建系统、移动端 CSS     |

## 模板结构

```
spec/
├── frontend/
│   ├── index.md
│   ├── components.md
│   ├── hooks.md
│   ├── state-management.md
│   ├── orpc-usage.md
│   ├── authentication.md
│   ├── ai-sdk-integration.md
│   └── ...
│
├── backend/
│   ├── index.md
│   ├── orpc-usage.md
│   ├── database.md
│   ├── authentication.md
│   ├── performance.md
│   └── ...
│
├── guides/
│   ├── pre-implementation-checklist.md
│   ├── cross-layer-thinking-guide.md
│   └── ...
│
├── shared/
│   ├── typescript.md
│   ├── code-quality.md
│   ├── dependencies.md
│   └── ...
│
├── big-question/
│   ├── postgres-json-jsonb.md
│   ├── sentry-nextintl-conflict.md
│   └── ...
│
└── README.md
```

## 主要内容

### 前端

* Next.js 15 App Router + React 19
* oRPC 客户端 + React Query 集成
* Server Components vs Client Components
* better-auth 认证集成
* Vercel AI SDK（useChat、工具调用、流式传输）
* TailwindCSS 4 + Radix UI 模式

### 后端

* oRPC Router、Procedures 和 Middleware
* Drizzle ORM + PostgreSQL（N+1 防护、事务、JSON/JSONB）
* better-auth 服务端配置
* 性能模式（并发控制、缓存、限流）
* Sentry 结构化日志

### 指南

* 实现前检查清单（先搜索再动手）
* Next.js 全栈变更的跨层思考

### 常见坑点

* PostgreSQL `json` vs `jsonb` 与 Drizzle ORM
* Sentry + next-intl 插件冲突
* Turbopack vs Webpack flexbox 差异
* 移动端 WebKit tap highlight

## 使用方法

1. 下载 ZIP 文件
2. 解压到项目的 `.trellis/spec/` 目录
3. 将 `@your-app/*` 占位符替换为你的 monorepo 包路径
4. 按你项目的具体规范修改
5. 删掉不适用的部分

<Card title="在 GitHub 上查看" icon="github" href="https://github.com/mindfold-ai/Trellis/tree/main/marketplace/specs/nextjs-fullstack">
  浏览模板源码
</Card>
