2026-03-03 16:01:41 +08:00
# LobeHub Development Guidelines
2025-08-29 15:52:02 +08:00
2026-03-03 16:01:41 +08:00
This document serves as a comprehensive guide for all team members when developing LobeHub.
2025-08-29 15:52:02 +08:00
2025-12-02 19:05:08 +08:00
## Project Description
2026-01-23 22:30:18 +08:00
You are developing an open-source, modern-design AI Agent Workspace: LobeHub (previously LobeChat).
2025-12-02 19:05:08 +08:00
2025-08-29 15:52:02 +08:00
## Tech Stack
2025-11-27 20:10:40 +08:00
- **Frontend**: Next.js 16, React 19, TypeScript
2025-08-29 15:52:02 +08:00
- **UI Components**: Ant Design, @lobehub/ui , antd-style
- **State Management**: Zustand, SWR
- **Database**: PostgreSQL, PGLite, Drizzle ORM
- **Testing**: Vitest, Testing Library
- **Package Manager**: pnpm (monorepo structure)
## Directory Structure
2026-03-19 16:13:01 +08:00
``` plaintext
2026-03-14 22:06:09 +08:00
lobehub/
2026-01-23 22:30:18 +08:00
├── apps/desktop/ # Electron desktop app
├── packages/ # Shared packages (@lobechat/*)
│ ├── database/ # Database schemas, models, repositories
│ ├── agent-runtime/ # Agent runtime
│ └── ...
├── src/
│ ├── app/ # Next.js app router
2026-03-01 18:35:38 +08:00
│ ├── spa/ # SPA entry points (entry.*.tsx) and router config
│ ├── routes/ # SPA page components (roots)
│ ├── features/ # Business components by domain
2026-01-23 22:30:18 +08:00
│ ├── store/ # Zustand stores
│ ├── services/ # Client services
│ ├── server/ # Server services and routers
│ └── ...
├── .agents/skills/ # AI development skills
└── e2e/ # E2E tests (Cucumber + Playwright)
```
2025-08-29 15:52:02 +08:00
## Development Workflow
### Git Workflow
2026-02-26 22:59:10 +08:00
- **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`
2025-09-17 23:30:04 +08:00
- Use rebase for git pull
2025-08-29 15:52:02 +08:00
- Git commit messages should prefix with gitmoji
2026-03-19 00:35:20 +08:00
- Git branch name format: `feat/feature-name`
2025-08-29 15:52:02 +08:00
- Use `.github/PULL_REQUEST_TEMPLATE.md` for PR descriptions
### Package Management
- Use `pnpm` as the primary package manager
- Use `bun` to run npm scripts
- Use `bunx` to run executable npm packages
### Code Style Guidelines
#### TypeScript
- Prefer interfaces over types for object shapes
### Testing Strategy
2026-01-23 22:30:18 +08:00
``` bash
# Web tests
bunx vitest run --silent= 'passed-only' '[file-path-pattern]'
2025-08-29 15:52:02 +08:00
2026-01-23 22:30:18 +08:00
# Package tests (e.g., database)
cd packages/[ package-name] && bunx vitest run --silent= 'passed-only' '[file-path-pattern]'
```
2025-08-29 15:52:02 +08:00
**Important Notes ** :
- Wrap file paths in single quotes to avoid shell expansion
2026-02-05 21:40:43 +08:00
- Never run `bun run test` - this runs all tests and takes \~10 minutes
2025-08-29 15:52:02 +08:00
### Type Checking
2025-12-19 23:05:15 +08:00
- Use `bun run type-check` to check for type errors
2025-08-29 15:52:02 +08:00
2025-09-30 16:07:32 +08:00
### i18n
2025-08-29 15:52:02 +08:00
2025-09-30 16:07:32 +08:00
- **Keys**: Add to `src/locales/default/namespace.ts`
- **Dev**: Translate `locales/zh-CN/namespace.json` locale file only for preview
- DON'T run `pnpm i18n` , let CI auto handle it
2025-08-29 15:52:02 +08:00
2026-03-01 18:35:38 +08:00
## SPA Routes and Features
2026-03-19 16:13:01 +08:00
- **`src/routes/` ** holds only page segments (`_layout/index.tsx` , `index.tsx` , `[id]/index.tsx` ). Keep route files **thin ** — import from `@/features/*` and compose, no business logic.
- **`src/features/` ** holds business components by **domain ** (e.g. `Pages` , `PageEditor` , `Home` ). Layout pieces, hooks, and domain UI go here.
- See the **spa-routes ** skill for the full convention and file-division rules.
2026-03-01 18:35:38 +08:00
2026-01-23 22:30:18 +08:00
## Skills (Auto-loaded)
2026-03-19 16:13:01 +08:00
All AI development skills are available in `.agents/skills/` directory and auto-loaded by Claude Code when relevant.
**IMPORTANT ** : When reviewing PRs or code diffs, ALWAYS read `.agents/skills/code-review/SKILL.md` first.