This commit introduces a comprehensive engineering audit report for the Tootaio Studio project. The report is structured into documents covering architecture, code quality, performance, security, CI/CD, and observability. It also includes a phased improvement roadmap and a set of `.patch` files to apply immediate fixes for content schemas, package scripts, and CI configuration.
2.3 KiB
2.3 KiB
架构结构与改进方案
本文审计 Nuxt 4.2.0 架构与模块使用,指出结构异味并提供可落地改进。
现状评估
- 模块与目录(Low)
app/(pages/layouts/composables/utils/assets)职责清晰。content/与content.config.ts使用 zod 定义 Schema,利于类型驱动内容。i18n/采用locales/<locale>结构;no_prefix策略与当前站点定位一致。
- Nuxt 4 特性使用(Medium)
- 自动导入:已使用(如
useLocalizedCollection)。建议将文件命名统一为useXxx.ts便于识别。 - Runtime Config:未使用。建议引入
runtimeConfig管理外部域名、监控 DSN 等。 - Nitro Route Rules/缓存:未配置。建议为首页与静态资源设置
prerender+swr与长缓存。
- 自动导入:已使用(如
- 设计风险(Critical)
content.config.ts的 Index Schema 与 YAML 不一致:缺少title/description/seo字段;icon/highlight/spotlight约束与内容不符。
改进策略
- 内容 Schema 对齐(Critical)
- 为 Index 增加
title/description/seo;将icon设为可选,将highlight/spotlight设为可选并默认false。 - 参见补丁:
0001-content-config-align.patch。
- 为 Index 增加
- 运行时配置(Medium)
- 在
nuxt.config.ts中:export default defineNuxtConfig({ runtimeConfig: { sentryDsn: '', public: { assetBase: 'https://img.tootaio.com' }, }, }) - 在代码中读取
useRuntimeConfig(),避免硬编码外链与密钥。
- 在
- 路由规则与缓存(Medium)
- 为首页预渲染并设置 SWR,为构建产物设置 immutable 缓存:
export default defineNuxtConfig({ routeRules: { '/': { prerender: true, swr: 3600 }, '/_nuxt/**': { headers: { 'cache-control': 'public, max-age=31536000, immutable' }, }, }, }) - 参见补丁:
0004-nuxt-route-rules.patch。
- 为首页预渲染并设置 SWR,为构建产物设置 immutable 缓存:
- 组合式命名与分层(Low)
- 将
app/composables/LocalizedCollection.ts重命名为useLocalizedCollection.ts。 - 保持 composable 只做“取数+组装”,复杂 UI/状态拆到组件/Pinia(若引入)。
- 将
与 Nuxt 4.2.0 兼容性
- 现有
compatibilityDate: '2025-07-15'符合要求。 - 上述配置属于稳定 API:
routeRules/runtimeConfig/auto-import,安全可用。