vite-architecture
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVite + TanStack Router Architecture Enforcement
Vite + TanStack Router 架构强制执行
Overview
概述
Enforces hypercore Vite + TanStack Router architecture rules with strict validation before editing code.
This skill is RIGID. Follow exactly. No exceptions.
OPERATING MODE: This skill must stay self-contained. Do not block on external orchestration surfaces just to apply architecture rules. If a repo-local persistence loop is already active, carry these gates into that loop. Otherwise proceed directly with this skill.
NOTE: Some rules in this skill are stricter than TanStack Router defaults. Treat them as hypercore team conventions unless the user explicitly asks to follow official TanStack defaults instead.
在编辑代码前,通过严格校验强制执行hypercore Vite + TanStack Router架构规则。
本规则严格执行,必须完全遵循,无例外。
运行模式: 本规则必须独立执行。不得为了应用架构规则而依赖外部编排流程。如果仓库本地已有持久化循环机制,需将这些校验规则融入该循环;否则直接执行本规则。
注意: 本规则中的部分要求比TanStack Router默认规则更严格。除非用户明确要求遵循TanStack官方默认规则,否则将这些要求视为hypercore团队约定。
Trigger Examples
触发示例
Positive
适用场景
Audit this Vite + TanStack Router app for route structure, validateSearch, and service boundaries before editing.Add a new route folder in a Vite + TanStack Router app and keep hooks/services compliant.Refactor a TanStack Router page so the UI stays in the route and logic moves into -hooks/.
在编辑前审核这个Vite + TanStack Router应用的路由结构、validateSearch和服务边界。在Vite + TanStack Router应用中添加新路由文件夹,并确保钩子/服务符合规范。重构TanStack Router页面,使UI保留在路由中,逻辑迁移至-hooks/目录。
Negative
不适用场景
Create a new Codex skill for browser QA.Review a TanStack Start app that uses createServerFn and @tanstack/react-start.
为浏览器QA创建新的Codex技能。审查使用createServerFn和@tanstack/react-start的TanStack Start应用。
Boundary
边界场景
-
Direct editing can be enough if the change does not cross an architecture boundary, but touched files still need a quick compliance check.
Make a tiny copy-only text change in a Vite route file. -
Route away to
The repo actually uses @tanstack/react-start.instead of forcing Vite rules onto a Start project.tanstack-start-architecture
-
如果变更未跨越架构边界,可直接编辑,但仍需对涉及文件进行快速合规性检查。
在Vite路由文件中进行微小的纯文本复制修改。 -
应切换至
仓库实际使用@tanstack/react-start。规则,而非将Vite规则强制应用于Start项目。tanstack-start-architecture
Step 1: Project Validation
步骤1:项目验证
Before any work, confirm a Vite + TanStack Router project:
bash
undefined在开展任何工作前,确认项目为Vite + TanStack Router项目:
bash
undefinedCheck for Vite + TanStack Router indicators (ANY of these)
检查Vite + TanStack Router标识(满足任意一项即可)
grep -r "@tanstack/react-router" package.json 2>/dev/null
grep -r "vite" package.json 2>/dev/null
ls vite.config.ts 2>/dev/null
ls src/routes/__root.tsx 2>/dev/null
If NONE found: **STOP. This skill does not apply.** Inform the user and return to the normal implementation or review path.
If `@tanstack/react-start` or `app.config.ts` is present: **STOP.** Route to `tanstack-start-architecture`.
If the repo matches Vite + TanStack Router: proceed with architecture enforcement.grep -r "@tanstack/react-router" package.json 2>/dev/null
grep -r "vite" package.json 2>/dev/null
ls vite.config.ts 2>/dev/null
ls src/routes/__root.tsx 2>/dev/null
如果**未找到任何标识**:**停止执行。本规则不适用。** 告知用户并返回常规实现或审查流程。
如果发现`@tanstack/react-start`或`app.config.ts`:**停止执行。** 切换至`tanstack-start-architecture`规则。
如果仓库符合Vite + TanStack Router项目特征:继续执行架构强制规则。Step 2: Read Architecture Rules
步骤2:阅读架构规则
Load the detailed rules reference:
REQUIRED: Read in this skill directory before writing any code.
architecture-rules.mdFor detailed patterns and examples, also read the relevant rule files:
- - naming, TypeScript, imports, comments
rules/conventions.md - - route folder structure,
rules/routes.md, loaders, search paramsroute.tsx - - public API services, query options, mutations, client boundaries
rules/services.md - - custom hook separation and internal order
rules/hooks.md - - loader/runtime boundaries, SSR-aware caveats, env safety
rules/execution-model.md - -
rules/platform.md, router setup, generated files, env and alias rulesvite.config.ts
加载详细规则参考:
必须执行: 在编写任何代码前,阅读本规则目录下的文件。
architecture-rules.md如需详细模式和示例,还需阅读相关规则文件:
- - 命名规范、TypeScript、导入规则、注释要求
rules/conventions.md - - 路由文件夹结构、
rules/routes.md、加载器、搜索参数route.tsx - - 公共API服务、查询选项、变更操作、客户端边界
rules/services.md - - 自定义钩子分离规则及内部顺序
rules/hooks.md - - 加载器/运行时边界、SSR注意事项、环境变量安全
rules/execution-model.md - -
rules/platform.md、路由配置、生成文件、环境变量及别名规则vite.config.ts
Step 3: Pre-Change Validation Checklist
步骤3:变更前校验清单
Before writing ANY code, verify the planned change against these gates:
在编写任何代码前,验证计划变更是否符合以下校验项:
Brownfield Adoption Rule
遗留项目适配规则
- Do not treat every untouched legacy deviation as an immediate project-wide failure.
- Safety or boundary issues still block immediately, especially in touched files.
- Hypercore-specific style or structure drift in untouched legacy code can be recorded as migration backlog.
- Any file you touch should be brought into compliance unless that would require a materially risky migration.
- 不要将所有未修改的遗留代码偏差视为立即需要修复的项目级问题。
- 安全或边界问题仍需立即阻止,尤其是在涉及修改的文件中。
- 未修改的遗留代码中不符合hypercore风格或结构的部分可记录为迁移待办项。
- 除非存在重大迁移风险,否则所有你修改的文件都必须符合规范。
Gate 1: Layer Violations
校验项1:分层违规
Routes -> Services -> External API| Check | Rule |
|---|---|
Route calling | BLOCKED. Must go through services |
Hook calling | BLOCKED. Must go through services |
Service returning raw | BLOCKED. Return typed data |
| BLOCKED |
路由层 -> 服务层 -> 外部API| 检查内容 | 规则 |
|---|---|
路由直接调用 | 禁止。必须通过服务层调用 |
钩子直接调用 | 禁止。必须通过服务层调用 |
服务层向路由/钩子返回原始 | 禁止。需返回类型化数据 |
Vite应用中使用 | 禁止 |
Gate 2: Route Structure
校验项2:路由结构
| Check | Rule |
|---|---|
Flat file route for a page that owns UI/logic? ( | BLOCKED. Use a folder route ( |
Missing | BLOCKED. Every page needs it |
Missing | BLOCKED. Every page needs it |
| BLOCKED. Vite skill does not allow server functions |
| BLOCKED. Must be |
| Logic in page component? | BLOCKED. Extract to |
Layout route missing | BLOCKED |
Route with search params but no | BLOCKED. Use |
Route with loader but no | WARNING. Recommended |
| 检查内容 | 规则 |
|---|---|
拥有UI/逻辑的页面使用扁平文件路由( | 禁止。需使用文件夹路由( |
缺少 | 禁止。每个页面都必须包含该文件夹 |
缺少 | 禁止。每个页面都必须包含该文件夹 |
存在 | 禁止。Vite规则不允许使用服务端函数 |
| 禁止。必须写为 |
| 页面组件中包含逻辑代码? | 禁止。需提取至 |
布局路由拥有共享加载器/beforeLoad/布局逻辑但缺少 | 禁止 |
使用搜索参数但未配置 | 禁止。需使用 |
路由配置了加载器但未设置 | 警告。建议配置 |
Gate 3: Services
校验项3:服务层
| Check | Rule |
|---|---|
| POST/PUT/PATCH without schema validation? | BLOCKED. Validate with Zod before calling |
Direct | BLOCKED. Use service functions |
| BLOCKED. Import directly from concrete files |
| Missing explicit return type on service function? | BLOCKED |
| 检查内容 | 规则 |
|---|---|
| POST/PUT/PATCH请求未进行Schema校验? | 禁止。调用前需使用Zod进行校验 |
路由或钩子中直接使用 | 禁止。需使用服务层函数 |
使用 | 禁止。需直接从具体文件导入 |
| 服务层函数缺少显式返回类型? | 禁止 |
Gate 4: Hooks
校验项4:钩子
| Check | Rule |
|---|---|
| Hook logic left inside page component? | BLOCKED. Move to |
| Wrong hook order? | BLOCKED. State -> Global -> Query -> Handlers -> Memo -> Effect |
| Missing exported return type interface? | BLOCKED |
| camelCase hook filename? | BLOCKED. Use |
| BLOCKED |
| 检查内容 | 规则 |
|---|---|
| 钩子逻辑留在页面组件中? | 禁止。需迁移至 |
| 钩子内部顺序错误? | 禁止。正确顺序:状态 -> 全局 -> 查询 -> 处理器 -> 计算属性 -> 副作用 |
| 缺少导出的返回类型接口? | 禁止 |
| 钩子文件名使用小驼峰命名? | 禁止。需使用 |
Vite钩子中使用 | 禁止 |
Gate 5: Conventions
校验项5:编码约定
| Check | Rule |
|---|---|
| camelCase filename? | BLOCKED. Use kebab-case |
| BLOCKED. Use const arrow functions |
| BLOCKED. Use |
| Missing explicit return type? | BLOCKED |
| Wrong import order? | BLOCKED. External -> @/ -> Relative -> Type |
| Missing Korean block comments for grouped logic? | BLOCKED |
Using | BLOCKED. Use |
| 检查内容 | 规则 |
|---|---|
| 文件名使用小驼峰命名? | 禁止。需使用短横线分隔命名 |
使用 | 禁止。需使用箭头函数表达式 |
使用 | 禁止。需使用 |
| 缺少显式返回类型? | 禁止 |
| 导入顺序错误? | 禁止。正确顺序:外部依赖 -> @/别名 -> 相对路径 -> 类型导入 |
| 分组逻辑缺少韩文块注释? | 禁止 |
使用 | 禁止。Zod 4中需使用 |
Gate 6: Execution Model
校验项6:执行模型
| Check | Rule |
|---|---|
Treating a route | BLOCKED. Loaders are client-reachable and may also participate in SSR/manual rendering |
| Secret, DB, filesystem, or privileged SDK access inside a route module or loader? | BLOCKED. Keep it behind an actual backend/API boundary |
| Browser-only APIs used at module scope or in shared route helpers without a client boundary? | BLOCKED |
Non- | BLOCKED |
| 检查内容 | 规则 |
|---|---|
将路由 | 禁止。加载器可被客户端访问,也可能参与SSR/手动渲染 |
| 路由模块或加载器中访问密钥、数据库、文件系统或特权SDK? | 禁止。需将这些逻辑放在真实后端/API边界之后 |
| 在模块作用域或共享路由工具中使用浏览器专属API但未设置客户端边界? | 禁止 |
在客户端可访问代码中使用非 | 禁止 |
Gate 7: Platform Setup
校验项7:平台配置
| Check | Rule |
|---|---|
| BLOCKED. Router plugin must stay explicit and precede |
| BLOCKED. Treat as generated output |
| Router setup hidden or inconsistent with SSR/manual rendering needs? | WARNING. Keep |
| Path alias or env setup relies on implicit behavior only? | WARNING. Keep |
| 检查内容 | 规则 |
|---|---|
| 禁止。路由插件必须显式配置且位于 |
手动编辑 | 禁止。该文件为自动生成文件 |
| 路由配置隐藏或与SSR/手动渲染需求不一致? | 警告。需保持 |
| 路径别名或环境变量配置仅依赖隐式行为? | 警告。需保持 |
Step 3.5: Auto-Remediation Policy
步骤3.5:自动修复策略
Auto-fix directly when the issue is local, reversible, and low-risk.
- add missing
validateSearch - move direct route/hook network access into
services/ - add missing or
pendingComponenterrorComponent - create missing or
-components/folders for touched pages-hooks/ - add or correct plugin setup, router scaffolding, or explicit env/alias wiring
tanstackRouter()
Do not auto-apply broad or potentially breaking migrations without explicit justification.
- mass route/file renames
- sweeping route-tree restructures across many pages
- introducing SSR/manual server rendering where the repo was SPA-only
- large auth or API-client rewrites
当问题为局部、可逆且低风险时,可直接自动修复:
- 添加缺失的
validateSearch - 将路由/钩子中直接的网络访问迁移至目录
services/ - 添加缺失的或
pendingComponenterrorComponent - 为涉及修改的页面创建缺失的或
-components/文件夹-hooks/ - 添加或修正插件配置、路由脚手架或显式的环境变量/别名配置
tanstackRouter()
未经明确论证,不得自动应用范围广泛或可能导致破坏性变更的迁移:
- 批量路由/文件重命名
- 跨多个页面的路由树大规模重构
- 在仅为SPA的仓库中引入SSR/手动服务端渲染
- 大规模身份验证或API客户端重写
Step 4: Implementation
步骤4:开发实现
Carry these acceptance criteria into the active task:
text
- [ ] Layer architecture respected (Routes -> Services -> External API)
- [ ] Route uses folder structure with -components/ and -hooks/
- [ ] export const Route = createFileRoute(...) used
- [ ] No Start-only server-function APIs in this Vite project
- [ ] Search params use zodValidator from @tanstack/zod-adapter
- [ ] Custom Hooks live in -hooks/ with correct internal order
- [ ] Loaders stay public-safe and SSR-safe
- [ ] Vite/router platform setup stays explicit (router plugin, router file, generated files)
- [ ] All filenames kebab-case
- [ ] Korean block comments present
- [ ] const arrow functions with explicit return types将以下验收标准纳入当前任务:
text
- [ ] 遵循分层架构(路由层 -> 服务层 -> 外部API)
- [ ] 路由使用包含-components/和-hooks/的文件夹结构
- [ ] 使用export const Route = createFileRoute(...)声明路由
- [ ] Vite项目中未使用Start专属服务端函数API
- [ ] 搜索参数使用@tanstack/zod-adapter中的zodValidator
- [ ] 自定义钩子位于-hooks/目录且内部顺序正确
- [ ] 加载器保持公共安全和SSR安全
- [ ] Vite/路由平台配置保持显式(路由插件、路由文件、生成文件)
- [ ] 所有文件名使用短横线分隔命名
- [ ] 包含韩文块注释
- [ ] 使用箭头函数表达式并声明显式返回类型Step 5: Post-Change Verification
步骤5:变更后验证
After writing code, verify:
- Structure check: confirm each touched page still has and
-components/and no-hooks/-functions/ - Export check: grep for
export const Route - Layer check: no direct /
fetchin touched route or hook filesaxios - Convention check: no camelCase filenames, no keyword declarations
function - Hook order check: read touched hooks and verify State -> Global -> Query -> Handlers -> Memo -> Effect
- Execution check: loaders and route modules do not touch secrets, DB clients, or private env values directly
- Platform check: ,
vite.config.ts, env wiring, and generated router files remain coherentsrc/router.tsx
编写代码后,验证以下内容:
- 结构检查:确认每个涉及修改的页面仍包含和
-components/目录,且无-hooks/目录-functions/ - 导出检查:使用grep命令检查是否存在
export const Route - 分层检查:涉及修改的路由或钩子文件中无直接/
fetch调用axios - 约定检查:无小驼峰命名的文件,无关键字声明的函数
function - 钩子顺序检查:阅读涉及修改的钩子,验证顺序为状态 -> 全局 -> 查询 -> 处理器 -> 计算属性 -> 副作用
- 执行检查:加载器和路由模块未直接访问密钥、数据库客户端或私有环境变量
- 平台检查:、
vite.config.ts、环境变量配置及生成的路由文件保持一致src/router.tsx
Quick Reference: Folder Structure
快速参考:文件夹结构
text
src/
├── routes/
│ ├── __root.tsx
│ ├── index.tsx
│ └── users/
│ ├── route.tsx # shared layout / beforeLoad / loader
│ ├── index.tsx # /users
│ ├── -components/
│ ├── -hooks/
│ ├── $id/
│ │ ├── index.tsx # /users/$id
│ │ ├── -components/
│ │ └── -hooks/
│ └── -sections/ # optional for large pages
├── services/<domain>/
│ ├── schemas.ts
│ ├── queries.ts
│ └── mutations.ts
├── hooks/ # global hooks
├── stores/
├── components/
├── config/
├── env/
├── lib/
├── src/router.tsx
└── routeTree.gen.ts # generated, do not hand-edittext
src/
├── routes/
│ ├── __root.tsx
│ ├── index.tsx
│ └── users/
│ ├── route.tsx # 共享布局 / beforeLoad / 加载器
│ ├── index.tsx # /users
│ ├── -components/
│ ├── -hooks/
│ ├── $id/
│ │ ├── index.tsx # /users/$id
│ │ ├── -components/
│ │ └── -hooks/
│ └── -sections/ # 大型页面可选目录
├── services/<domain>/
│ ├── schemas.ts
│ ├── queries.ts
│ └── mutations.ts
├── hooks/ # 全局钩子
├── stores/
├── components/
├── config/
├── env/
├── lib/
├── src/router.tsx
└── routeTree.gen.ts # 自动生成文件,请勿手动编辑Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| |
| |
| |
Direct | move to |
| use services + TanStack Query |
Page component holds | extract to |
| regenerate it; do not hand-edit |
Loader reads secrets or non- | move behind a real backend/API boundary |
| add |
| 错误 | 修复方案 |
|---|---|
使用 | 改为 |
页面拥有独立UI/逻辑文件夹但使用 | 改为 |
声明路由时使用 | 改为 |
路由/钩子中直接使用 | 迁移至 |
应用中使用 | 使用服务层 + TanStack Query替代 |
页面组件中内联使用 | 提取至 |
手动编辑 | 重新生成该文件;请勿手动编辑 |
加载器读取密钥或非 | 将逻辑迁移至真实后端/API边界之后 |
使用搜索参数但未配置 | 添加 |
Red Flags - STOP and Fix
危险信号 - 立即停止并修复
- is present but the Vite skill is being applied
@tanstack/react-start - route or hook imports /
fetchdirectlyaxios - missing on
exportconst Route - page component contains inline state/query/mutation logic
- ,
createServerFn, oruseServerFnappears in the route tree-functions/ - loader or route module reads secrets, DB clients, or private env values directly
- has hand edits
routeTree.gen.ts - search params are used without
validateSearch
- 项目中存在但仍在应用Vite规则
@tanstack/react-start - 路由或钩子直接导入/
fetchaxios - 未添加
const Routeexport - 页面组件包含内联状态/查询/变更逻辑
- 路由树中出现、
createServerFn或useServerFn目录-functions/ - 加载器或路由模块直接访问密钥、数据库客户端或私有环境变量
- 存在手动编辑痕迹
routeTree.gen.ts - 使用搜索参数但未配置
validateSearch