From 74a656fda2adce37294e9155cc9b110a1a6187c9 Mon Sep 17 00:00:00 2001 From: Eric-Guo Date: Mon, 8 Sep 2025 14:51:22 +0800 Subject: [PATCH] Initial GPT-5-high generated cursor rules --- .cursor/rules/api-client.mdc | 16 ++++++++++++++++ .cursor/rules/i18n.mdc | 10 ++++++++++ .cursor/rules/project-structure.mdc | 21 +++++++++++++++++++++ .cursor/rules/typescript-react.mdc | 20 ++++++++++++++++++++ .cursor/rules/ui-components.mdc | 11 +++++++++++ 5 files changed, 78 insertions(+) create mode 100644 .cursor/rules/api-client.mdc create mode 100644 .cursor/rules/i18n.mdc create mode 100644 .cursor/rules/project-structure.mdc create mode 100644 .cursor/rules/typescript-react.mdc create mode 100644 .cursor/rules/ui-components.mdc diff --git a/.cursor/rules/api-client.mdc b/.cursor/rules/api-client.mdc new file mode 100644 index 0000000..7b7c91c --- /dev/null +++ b/.cursor/rules/api-client.mdc @@ -0,0 +1,16 @@ +--- +description: API client usage and streaming +--- + +### API Client + +- Use domain functions in `[service/index.ts](mdc:service/index.ts)` for app features. +- Prefer `get/post/put/del` from `[service/base.ts](mdc:service/base.ts)`; they apply base options, timeout, and error toasts. +- Set request bodies via `options.body`; it will be JSON-stringified automatically. +- Add query via `options.params` on GET. +- Downloads: set `Content-type` header to `application/octet-stream`. + +### SSE Streaming + +- For streaming responses, use `ssePost` from `[service/base.ts](mdc:service/base.ts)` and supply callbacks: `onData`, `onCompleted`, `onThought`, `onFile`, `onMessageEnd`, `onMessageReplace`, `onWorkflowStarted`, `onNodeStarted`, `onNodeFinished`, `onWorkflowFinished`, `onError`. +- Chat messages helper: `sendChatMessage` in `[service/index.ts](mdc:service/index.ts)` preconfigures streaming. diff --git a/.cursor/rules/i18n.mdc b/.cursor/rules/i18n.mdc new file mode 100644 index 0000000..900b06b --- /dev/null +++ b/.cursor/rules/i18n.mdc @@ -0,0 +1,10 @@ +--- +description: i18n usage and locale resolution +--- + +### i18n + +- Server locale: `getLocaleOnServer()` reads cookie or negotiates from headers: `[i18n/server.ts](mdc:i18n/server.ts)`. +- Client locale: use `getLocaleOnClient()` / `setLocaleOnClient()` in `[i18n/client.ts](mdc:i18n/client.ts)`; uses `LOCALE_COOKIE_NAME` from config. +- Place translations in `i18n/lang/**`. Keep keys synchronized across locales. +- Render `` using the resolved locale in `[app/layout.tsx](mdc:app/layout.tsx)`. diff --git a/.cursor/rules/project-structure.mdc b/.cursor/rules/project-structure.mdc new file mode 100644 index 0000000..873f454 --- /dev/null +++ b/.cursor/rules/project-structure.mdc @@ -0,0 +1,21 @@ +--- +alwaysApply: true +--- + +### Project Structure Overview + +- **App Router (Next.js 14)**: Entry is `app/layout.tsx` and `app/page.tsx`. +- **API Routes**: Located under `app/api/**`. Server handlers live in `route.ts` files per folder. +- **Components**: UI under `app/components/**` with feature folders (e.g., `chat`, `workflow`, `base`). +- **Services (API client)**: Client-side HTTP/SSE utilities in `[service/base.ts](mdc:service/base.ts)` and domain methods in `[service/index.ts](mdc:service/index.ts)`. +- **Config**: Global config in `[config/index.ts](mdc:config/index.ts)` and Next config in `[next.config.js](mdc:next.config.js)`. +- **i18n**: Client/server helpers in `[i18n/client.ts](mdc:i18n/client.ts)` and `[i18n/server.ts](mdc:i18n/server.ts)`, with resources in `i18n/lang/**`. +- **Styles**: Tailwind setup `[tailwind.config.js](mdc:tailwind.config.js)`, global styles under `app/styles/**`. + +Key entrypoints: + +- Layout: `[app/layout.tsx](mdc:app/layout.tsx)` +- Home page: `[app/page.tsx](mdc:app/page.tsx)` +- HTTP utilities: `[service/base.ts](mdc:service/base.ts)` +- API domain functions: `[service/index.ts](mdc:service/index.ts)` +- Internationalization: `[i18n/server.ts](mdc:i18n/server.ts)`, `[i18n/client.ts](mdc:i18n/client.ts)` diff --git a/.cursor/rules/typescript-react.mdc b/.cursor/rules/typescript-react.mdc new file mode 100644 index 0000000..7959f71 --- /dev/null +++ b/.cursor/rules/typescript-react.mdc @@ -0,0 +1,20 @@ +--- +globs: *.ts,*.tsx +--- + +### TypeScript/React Conventions + +- **Strict TS**: `strict: true` in `tsconfig.json`. Avoid `any`. Prefer explicit function signatures for exports. +- **Paths**: Use `@/*` alias (tsconfig `paths`) for absolute imports. +- **React 18**: Prefer function components. Use `React.memo` only for measurable perf wins. +- **Hooks**: Co-locate hooks under `hooks/**`. Keep hook names prefixed with `use`. +- **App Router**: Server components by default. Mark client components with `'use client'` when needed. +- **Styling**: Tailwind-first; SCSS only where necessary. +- **Classnames**: Use `classnames` or `tailwind-merge` for conditional classes. +- **Control Flow**: Early returns, handle edge cases first; avoid deep nesting. + +### Next.js Notes + +- Route handlers belong in `app/api/**/route.ts`. +- Do not import server-only modules into client components. +- Keep environment access to server files; avoid exposing secrets. diff --git a/.cursor/rules/ui-components.mdc b/.cursor/rules/ui-components.mdc new file mode 100644 index 0000000..cdce641 --- /dev/null +++ b/.cursor/rules/ui-components.mdc @@ -0,0 +1,11 @@ +--- +description: UI components and styling conventions +--- + +### UI Components + +- Component folders under `app/components/**`; keep base primitives in `base/**` (buttons, icons, inputs, uploader, etc.). +- Larger features (chat, workflow) live in their own folders with `index.tsx` and submodules. +- Prefer colocated `style.module.css` or Tailwind classes. Global styles in `app/styles/**`. +- Use `app/components/base/toast` for error/display notifications. +- Avoid unnecessary client components; mark with `'use client'` only when needed (state, effects, browser APIs).