diff --git a/apps/docs/scripts/check-type.mjs b/apps/docs/scripts/check-type.mjs index f214fd0a..4a1ce5c5 100644 --- a/apps/docs/scripts/check-type.mjs +++ b/apps/docs/scripts/check-type.mjs @@ -26,6 +26,13 @@ const HOME_ONLY = [ ] const SIZE_OK = /^(var\(--(fs|sl-text)-[\w-]+\)|inherit)$/ const WEIGHT_OK = /^(var\(--fw-[\w-]+\)|400|500|600|normal|inherit)$/ +// `font:` 简写能一次写死字号和字重(`font: 600 13px/1.4 …`),只放行 inherit 和整条变量 +const FONT_OK = /^(inherit|var\(--[\w-]+\))$/ +const RULES = { + 'font-size': [SIZE_OK, '用 var(--fs-*)'], + 'font-weight': [WEIGHT_OK, '只用 400 / 500 / 600(var(--fw-*))'], + font: [FONT_OK, '简写只写 inherit,字号和字重分开用 var(--fs-*) / var(--fw-*)'], +} const files = (dir, ext) => readdirSync(join(ROOT, dir), { recursive: true, withFileTypes: true }) .filter((e) => e.isFile() && ext.test(e.name)).map((e) => join(e.parentPath, e.name)) @@ -36,11 +43,10 @@ const styleFiles = [...files('src/styles', /\.css$/), ...files('src/components', for (const file of styleFiles) { readFileSync(file, 'utf8').split('\n').forEach((line, i) => { if (line.includes('type-ok:')) return - for (const [, prop, value] of line.matchAll(/(?['items'][number] +// 目录只画两层:章节和它下面的小节。再深的标题(把 tableOfContents.maxHeadingLevel 调到 4 以上时才有) +// 拍平进所在章节的小节列表,不能直接丢 —— 只渲染 children 那一层的话,第三层会静默消失 +const flat = (items: TocItem[]): TocItem[] => items.flatMap((i) => [i, ...flat(i.children)]) const t = (zh: string, en: string) => (Astro.locals.starlightRoute.locale === 'en' ? en : zh) --- @@ -53,7 +57,7 @@ const t = (zh: string, en: string) => (Astro.locals.starlightRoute.locale === 'e {item.children.length > 0 && ( diff --git a/apps/docs/src/content/docs/en/getting-started/introduction.mdx b/apps/docs/src/content/docs/en/getting-started/introduction.mdx index e9755dce..4152ea9e 100644 --- a/apps/docs/src/content/docs/en/getting-started/introduction.mdx +++ b/apps/docs/src/content/docs/en/getting-started/introduction.mdx @@ -50,7 +50,7 @@ A request passes through four layers, top to bottom: a client (web, desktop or m Because AI changes code fast, and every change here has something to catch it: -- **One repo, one change.** Backend, web, desktop, mobile and the docs site live in one pnpm + turbo monorepo. When an AI changes an API, the backend, the contract file and the pages that call it are all in the same context, so the whole change lands in one PR; split across repos, it would only see half. CI then checks the whole repo for that PR: `pnpm typecheck` covers every package, a contract-freshness check fails if the API changed but the contract wasn't regenerated, and `pnpm arch:check` holds the `i18n ← ui ← platform ← web` dependency direction, so a shortcut import the wrong way doesn't get through. +- **One repo, one change.** Backend, web, desktop, mobile and the docs site live in one pnpm + turbo monorepo. When an AI changes an API, the backend, the contract file and the pages that call it are all in the same context, so the whole change lands in one PR; split across repos, it would only see half. CI then checks the whole repo for that PR: `pnpm typecheck` covers every TypeScript package, a contract-freshness check fails if the API changed but the contract wasn't regenerated, and `pnpm arch:check` holds the `i18n ← ui ← platform ← web` dependency direction, so a shortcut import the wrong way doesn't get through. - **Tests.** An AI touching a dozen files at once is routine, and nobody can click through all of that by hand. 1,400+ backend pytest cases run against a real database and Redis, 150+ Playwright cases drive a real browser, no mocks, on every CI run; failing cases come with screenshots and video, and the [E2E report](https://yile2020.github.io/fastapi-react-admin/e2e/) is public. - **Types.** The frontend/backend contract is generated from the backend's OpenAPI schema (`packages/api/src/schema.d.ts`). Mobile infers every request's types from it, so an API change the screens didn't follow fails `pnpm typecheck`; the web client is still migrating, and its call sites currently declare response types by hand (see [Developer tools](/en/features/developer-tools/#frontendbackend-contract)). - **Rules written for AI.** 50+ per-directory `CLAUDE.md` / `AGENTS.md` files record pitfalls and hard rules found by testing; a coding assistant reads the one for whatever directory it edits. diff --git a/apps/docs/src/content/docs/getting-started/introduction.mdx b/apps/docs/src/content/docs/getting-started/introduction.mdx index 7bec466e..9187a859 100644 --- a/apps/docs/src/content/docs/getting-started/introduction.mdx +++ b/apps/docs/src/content/docs/getting-started/introduction.mdx @@ -50,7 +50,7 @@ packages/ 依赖单向:i18n / api ← ui ← platform ← web 因为 AI 改代码很快,而这里每一处改动都有东西兜底: -- **一个仓库,改动一次到位。** 后端、网页端、桌面端、手机端和文档站在同一个 pnpm + turbo monorepo 里。AI 改一个接口时,后端、契约文件和调用它的页面都在同一份上下文里,一次改动、一个 PR 就能改完;分成几个仓库的话,它只看得到其中一半。CI 对这个 PR 跑全仓:`pnpm typecheck` 覆盖每一个包;改了接口忘了重新生成契约,有「契约新鲜度」检查拦着;`pnpm arch:check` 守住 `i18n ← ui ← platform ← web` 的依赖方向,图省事反向 import 也过不去。 +- **一个仓库,改动一次到位。** 后端、网页端、桌面端、手机端和文档站在同一个 pnpm + turbo monorepo 里。AI 改一个接口时,后端、契约文件和调用它的页面都在同一份上下文里,一次改动、一个 PR 就能改完;分成几个仓库的话,它只看得到其中一半。CI 对这个 PR 跑全仓:`pnpm typecheck` 覆盖每一个 TypeScript 包;改了接口忘了重新生成契约,有「契约新鲜度」检查拦着;`pnpm arch:check` 守住 `i18n ← ui ← platform ← web` 的依赖方向,图省事反向 import 也过不去。 - **测试兜底。** AI 一次改十几个文件很常见,人工点一遍点不过来。后端 1400+ 条 pytest 连真实数据库和 Redis,前端 150+ 条 Playwright 跑真实浏览器,不用 mock,CI 每次全量跑;失败的用例带截图和录像,[E2E 报告](https://yile2020.github.io/fastapi-react-admin/e2e/)公开。 - **类型兜底。** 前后端契约由后端的 OpenAPI 生成(`packages/api/src/schema.d.ts`)。移动端的每个请求都从它推断类型,接口改了而页面没跟上,`pnpm typecheck` 直接报错;网页端还在迁移,请求的返回类型目前在各调用点手写(见[开发者工具](/features/developer-tools/#前后端契约))。 - **规矩写给 AI 看。** 仓库里 50 多份按目录拆分的 `CLAUDE.md` / `AGENTS.md` 记着实测踩过的坑和硬纪律,编码助手改到哪个目录,就读到哪一份。 diff --git a/apps/docs/src/data/architecture.ts b/apps/docs/src/data/architecture.ts index 3a7c167e..0b7532b6 100644 --- a/apps/docs/src/data/architecture.ts +++ b/apps/docs/src/data/architecture.ts @@ -6,6 +6,7 @@ * * 每个模块都对得上仓库里的真实目录(2026-11-26 核对):客户端 = apps/web · desktop · mobile + packages/*; * 接入层 = apps/web/nginx.conf(/api、/ws、/uploads)、Vite 开发服务器、/api/open/v1; + * ⚠️ 开发时 Vite 只代理 /uploads,接口请求由浏览器直连 :8088(API_BASE),所以 Vite 那张卡写「接口直连」,别写成「/api 反代」; * 应用层 = backend/app/admin/api/v1/{auth,sys,log,monitor} + backend/app/task,插件 = backend/plugin/*(plugin.toml 的 summary); * 基础设施 / 公共层 = backend/common/*;数据层 = 三种数据库 + Redis(缓存 · 会话 · 默认的 Celery broker)+ OpenDAL 对象存储。 * 加了 / 删了模块或插件时一起改这里。 @@ -34,7 +35,7 @@ export const architecture = { index: '02', label: '接入层', sub: 'Nginx · Vite', flow: 'ASGI · FastAPI', cards: [ { code: 'Nginx', title: '生产环境', icon: 'server', tags: ['静态资源', '/api 反代', '/ws 推送'] }, - { code: 'Vite', title: '开发环境', icon: 'zap', tags: ['热更新', '端口 8888'] }, + { code: 'Vite', title: '开发环境', icon: 'zap', tags: ['页面热更新', '接口直连 :8088'] }, { code: '/api/open/v1', title: '开放接口', icon: 'key', tags: ['AK/SK 签名', 'Webhook'] }, ], }, @@ -98,7 +99,7 @@ export const architecture = { index: '02', label: 'Gateway', sub: 'Nginx · Vite', flow: 'ASGI · FastAPI', cards: [ { code: 'Nginx', title: 'Production', icon: 'server', tags: ['Static assets', '/api proxy', '/ws push'] }, - { code: 'Vite', title: 'Development', icon: 'zap', tags: ['Hot reload', 'Port 8888'] }, + { code: 'Vite', title: 'Development', icon: 'zap', tags: ['Hot reload', 'API direct to :8088'] }, { code: '/api/open/v1', title: 'Open API', icon: 'key', tags: ['AK/SK signing', 'Webhooks'] }, ], },