mirror of
https://github.com/lobehub/lobe-chat.git
synced 2025-12-20 01:12:52 +08:00
3.4 KiB
3.4 KiB
LobeChat Development Guidelines
This document serves as a comprehensive guide for all team members when developing LobeChat.
Tech Stack
Built with modern technologies:
- Frontend: Next.js 15, React 19, TypeScript
- 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)
- Build Tools: Next.js (Turbopack in dev, Webpack in prod)
Directory Structure
The project follows a well-organized monorepo structure:
apps/- Main applicationspackages/- Shared packages and librariessrc/- Main source codedocs/- Documentation.cursor/rules/- Development rules and guidelines
Development Workflow
Git Workflow
- Use rebase for git pull
- Git commit messages should prefix with gitmoji
- Git branch name format:
username/feat/feature-name - Use
.github/PULL_REQUEST_TEMPLATE.mdfor PR descriptions
Package Management
- Use
pnpmas the primary package manager - Use
bunto run npm scripts - Use
bunxto run executable npm packages - Navigate to specific packages using
cd packages/<package-name>
Code Style Guidelines
TypeScript
- Prefer interfaces over types for object shapes
Testing Strategy
Required Rule: testing-guide/testing-guide.mdc
Commands:
- Web:
bunx vitest run --silent='passed-only' '[file-path-pattern]' - Packages:
cd packages/[package-name] && bunx vitest run --silent='passed-only' '[file-path-pattern]'(each subpackage contains its own vitest.config.mts)
Important Notes:
- Wrap file paths in single quotes to avoid shell expansion
- Never run
bun run test- this runs all tests and takes ~10 minutes
Type Checking
- Use
bun run type-checkto check for type errors
i18n
- Keys: Add to
src/locales/default/namespace.ts - Dev: Translate
locales/zh-CN/namespace.jsonlocale file only for preview - DON'T run
pnpm i18n, let CI auto handle it
Project Rules Index
All following rules are saved under .cursor/rules/ directory:
Backend
drizzle-schema-style-guide.mdc– Style guide for defining Drizzle ORM schemas
Frontend
react-component.mdc– React component style guide and conventionsi18n.mdc– Internationalization guide using react-i18nexttypescript.mdc– TypeScript code style guidepackages/react-layout-kit.mdc– Usage guide for react-layout-kit
State Management
zustand-action-patterns.mdc– Recommended patterns for organizing Zustand actionszustand-slice-organization.mdc– Best practices for structuring Zustand slices
Desktop (Electron)
desktop-feature-implementation.mdc– Implementing new Electron desktop featuresdesktop-controller-tests.mdc– Desktop controller unit testing guidedesktop-local-tools-implement.mdc– Workflow to add new desktop local toolsdesktop-menu-configuration.mdc– Desktop menu configuration guidedesktop-window-management.mdc– Desktop window management guide
Debugging
debug-usage.mdc– Using the debug package and namespace conventions
Testing
testing-guide/testing-guide.mdc– Comprehensive testing guide for Vitesttesting-guide/electron-ipc-test.mdc– Electron IPC interface testing strategytesting-guide/db-model-test.mdc– Database Model testing guide