AGENTS.md TypeScript Frontend

lobehub โ€” AGENTS.md

๐Ÿคฏ LobeHub is your Chief Agent Operator, organizing your agents into 7ร—24 operations by hiring, scheduling, and reporting on your entire AI team.

AGENTS.md ยท 129 lines
# LobeHub Development Guidelines

Guidelines for using AI coding agents in this LobeHub repository.

## Tech Stack

- Next.js 16 + React 19 + TypeScript
- SPA inside Next.js with `react-router-dom`
- `@lobehub/ui`, antd for components; antd-style for CSS-in-JS โ€” **prefer `createStaticStyles` with `cssVar.*`** (zero-runtime); only fall back to `createStyles` + `token` when styles genuinely need runtime computation. See `.cursor/docs/createStaticStyles_migration_guide.md`.
- react-i18next for i18n; zustand for state management
- SWR for data fetching; TRPC for type-safe backend
- Drizzle ORM with PostgreSQL; Vitest for testing

## Project Structure

```plaintext
lobehub/
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ desktop/            # Electron desktop app
โ”‚   โ”œโ”€โ”€ cli/                # LobeHub CLI
โ”‚   โ””โ”€โ”€ device-gateway/     # Device gateway service
โ”œโ”€โ”€ packages/               # Shared packages (@lobechat/*)
โ”‚   โ”œโ”€โ”€ database/           # Database schemas, models, repositories
โ”‚   โ”œโ”€โ”€ agent-runtime/      # Agent runtime
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/                # Next.js App Router (backend API + auth)
โ”‚   โ”‚   โ”œโ”€โ”€ (backend)/     # API routes (trpc, webapi, etc.)
โ”‚   โ”‚   โ”œโ”€โ”€ spa/            # SPA HTML template service
โ”‚   โ”‚   โ””โ”€โ”€ [variants]/(auth)/  # Auth pages (SSR required)
โ”‚   โ”œโ”€โ”€ routes/             # SPA page components (Vite)
โ”‚   โ”‚   โ”œโ”€โ”€ (main)/         # Desktop pages
โ”‚   โ”‚   โ”œโ”€โ”€ (mobile)/       # Mobile pages
โ”‚   โ”‚   โ”œโ”€โ”€ (desktop)/      # Desktop-specific pages
โ”‚   โ”‚   โ”œโ”€โ”€ (popup)/        # Popup window pages
โ”‚   โ”‚   โ”œโ”€โ”€ onboarding/     # Onboarding pages
โ”‚   โ”‚   โ””โ”€โ”€ share/          # Share pages
โ”‚   โ”œโ”€โ”€ spa/                # SPA entry points and router config
โ”‚   โ”‚   โ”œโ”€โ”€ entry.web.tsx   # Web entry
โ”‚   โ”‚   โ”œโ”€โ”€ entry.mobile.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ entry.desktop.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ entry.popup.tsx
โ”‚   โ”‚   โ””โ”€โ”€ router/         # React Router configuration
โ”‚   โ”œโ”€โ”€ store/              # Zustand stores
โ”‚   โ”œโ”€โ”€ services/           # Client services
โ”‚   โ”œโ”€โ”€ server/             # Server services and routers
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ e2e/                    # E2E tests (Cucumber + Playwright)
```

## SPA Routes and Features

SPA-related code is grouped under `src/spa/` (entries + router) and `src/routes/` (page segments). We use a **roots vs features** split: route trees only hold page segments; business logic and UI live in features.

- **`src/spa/`** โ€“ SPA entry points (`entry.web.tsx`, `entry.mobile.tsx`, `entry.desktop.tsx`, `entry.popup.tsx`) and React Router config (`router/`, with `desktopRouter.config.*`, `mobileRouter.config.tsx`, `popupRouter.config.tsx`). Keeps router config next to entries to avoid confusion with `src/routes/`.

- **`src/routes/` (roots)**\
  Only page-segment files: `_layout/index.tsx`, `index.tsx` (or `page.tsx`), and dynamic segments like `[id]/index.tsx`. Keep these **thin**: they should only import from `@/features/*` and compose layout/page, with no business logic or heavy UI.

- **`src/features/`**\
  Business components by **domain** (e.g. `Pages`, `PageEditor`, `Home`). Put layout chunks (sidebar, header, body), hooks, and domain-specific UI here. Each feature exposes an `index.ts` (or `index.tsx`) with clear exports.

When adding or changing SPA routes:

1. In `src/routes/`, add only the route segment files (layout + page) that delegate to features.
2. Implement layout and page content under `src/features/<Domain>/` and export from there.
3. In route files, use `import { X } from '@/features/<Domain>'` (or `import Y from '@/features/<Domain>/...'`). Do not add new `features/` folders inside `src/routes/`.
4. **Register the desktop route tree in both configs:** `src/spa/router/desktopRouter.config.tsx` and `src/spa/router/desktopRouter.config.desktop.tsx` must stay in sync (same paths and nesting). Updating only one can cause **blank screens** if the other build path expects the route. `desktopRouter.sync.test.tsx` guards this invariant โ€” keep it passing.

See the **spa-routes** skill (`.agents/skills/spa-routes/SKILL.md`) for the full convention and file-division rules.

## Development

### Starting the Dev Environment

```bash
# SPA dev mode (frontend only, proxies API to localhost:3010)
bun run dev:spa

# Full-stack dev (Next.js + Vite SPA concurrently)
bun run dev
```

After `dev:spa` starts, the terminal prints a **Debug Proxy** URL:

```plaintext
Debug Proxy: https://app.lobehub.com/_dangerous_local_dev_proxy?debug-host=http%3A%2F%2Flocalhost%3A9876
```

Open this URL to develop locally against the production backend (app.lobehub.com). The proxy page loads your local Vite dev server's SPA into the online environment, enabling HMR with real server config.

### Git Workflow

- **Branch strategy**: `canary` is the development branch (cloud production); `main` is the release branch (periodically cherry-picks from canary)
- New branches should be created from `canary`; PRs should target `canary`
- Use rebase for `git pull`
- Commit messages: prefix with gitmoji
- Branch format: `<type>/<feature-name>`

### Package Management

- `pnpm` for dependency management
- `bun` to run npm scripts
- `bunx` for executable npm packages

### Testing

```bash
# Run specific test (NEVER run `bun run test` - takes ~10 minutes)
bunx vitest run --silent='passed-only' '[file-path]'

# Database package
cd packages/database && bunx vitest run --silent='passed-only' '[file]'
```

- Prefer `vi.spyOn` over `vi.mock`
- Tests must pass type check: `bun run type-check`
- After 2 failed fix attempts, stop and ask for help

### i18n

- Add keys to a namespace file under `src/locales/default/` (e.g. `agent.ts`, `auth.ts`)
- For dev preview: translate `locales/zh-CN/` and `locales/en-US/`
- `pnpm i18n` is slow; run it manually when locale keys need updating (e.g. before opening a PR).

### Code Review

Before reviewing a PR / diff / branch change, read the **review-checklist** skill (`.agents/skills/review-checklist/SKILL.md`) โ€” it lists the recurring mistakes specific to this codebase.
Share on X

ใ“ใกใ‚‰ใ‚‚ใŠใ™ใ™ใ‚

Frontend ใ‚ซใƒ†ใ‚ดใƒชใฎไป–ใฎใƒซใƒผใƒซ

ใ‚‚ใฃใจใƒซใƒผใƒซใ‚’ๆŽขใ™

CLAUDE.mdใ€.cursorrulesใ€AGENTS.mdใ€Image Prompts ใฎๅ…จ 254 ใƒซใƒผใƒซใ‚’ใƒใ‚งใƒƒใ‚ฏใ€‚