mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-14 03:30:19 +00:00
4.1 KiB
4.1 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
- Follow strict TypeScript practices for type safety and code quality
- Use proper type annotations
- Prefer interfaces over types for object shapes
- Use generics for reusable components
React Components
- Use functional components with hooks
Database Schema
- Follow Drizzle ORM naming conventions
- Use plural snake_case for table names
- Implement proper foreign key relationships
- Follow the schema style guide
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]'
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 - If a test fails twice, stop and ask for help
- Always add tests for new code
Type Checking
- Use
bun run type-checkto check for type errors - Ensure all TypeScript errors are resolved before committing
Internationalization
- Add new keys to
src/locales/default/namespace.ts - Translate at least
zh-CNfiles for development preview - Use hierarchical nested objects, not flat keys
- Don't run
pnpm i18nmanually (handled by CI)
Available Development Rules
The project provides comprehensive rules in .cursor/rules/ directory:
Core Development
backend-architecture.mdc- Three-layer architecture and data flowreact-component.mdc- Component patterns and UI library usagedrizzle-schema-style-guide.mdc- Database schema conventionsdefine-database-model.mdc- Model templates and CRUD patternsi18n.mdc- Internationalization workflow
State Management & UI
zustand-slice-organization.mdc- Store organization patternszustand-action-patterns.mdc- Action implementation patternspackages/react-layout-kit.mdc- Flex layout component usage
Testing & Quality
testing-guide/testing-guide.mdc- Comprehensive testing strategycode-review.mdc- Code review process and standards
Desktop (Electron)
desktop-feature-implementation.mdc- Main/renderer process patternsdesktop-local-tools-implement.mdc- Tool integration workflowdesktop-menu-configuration.mdc- Menu system configurationdesktop-window-management.mdc- Window management patternsdesktop-controller-tests.mdc- Controller testing guide
Best Practices
- Conservative for existing code, modern approaches for new features
- Code Language: Use Chinese for files with existing Chinese comments, American English for new files
- Always add tests for new functionality
- Follow the established patterns in the codebase
- Use proper error handling and logging
- Implement proper accessibility features
- Consider internationalization from the start