Skip to content

Commit 0efe28d

Browse files
authored
✨ feat(image): polish ai image (#8915)
1 parent 3361139 commit 0efe28d

File tree

57 files changed

+1609
-579
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1609
-579
lines changed

.cursor/rules/project-introduce.mdc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Emoji logo: 🤯
1010

1111
## Project Technologies Stack
1212

13-
read [package.json](mdc:package.json) to know all npm packages you can use. read [folder-structure.mdx](mdc:docs/development/basic/folder-structure.mdx) to learn project structure.
13+
read [package.json](mdc:package.json) to know all npm packages you can use.
1414

1515
The project uses the following technologies:
1616

@@ -42,17 +42,3 @@ The project uses the following technologies:
4242
- Cursor AI for code editing and AI coding assistance
4343

4444
Note: All tools and libraries used are the latest versions. The application only needs to be compatible with the latest browsers;
45-
46-
## Often used npm scripts and commands
47-
48-
```bash
49-
# !: don't any build script to check weather code can work after modify
50-
# type check
51-
bun run type-check
52-
53-
# install dependencies
54-
pnpm install
55-
56-
# run tests
57-
npx vitest run --config vitest.config.ts '[file-path-pattern]'
58-
```
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
---
2+
description: Project directory structure overview
3+
alwaysApply: false
4+
---
5+
6+
# LobeChat Project Structure
7+
8+
## Directory Structure
9+
10+
note: some files are not shown for simplicity.
11+
12+
```plaintext
13+
lobe-chat/
14+
├── apps/ # Applications directory
15+
│ └── desktop/ # Electron desktop application
16+
│ ├── src/ # Desktop app source code
17+
│ └── resources/ # Desktop app resources
18+
├── docs/ # Project documentation
19+
│ ├── development/ # Development docs
20+
│ ├── self-hosting/ # Self-hosting docs
21+
│ └── usage/ # Usage guides
22+
├── locales/ # Internationalization files
23+
│ ├── en-US/ # English
24+
│ └── zh-CN/ # Simplified Chinese
25+
├── packages/ # Monorepo packages directory
26+
│ ├── const/ # Constants definition package
27+
│ ├── database/ # Database related package
28+
│ ├── model-runtime/ # AI model runtime package
29+
│ ├── types/ # TypeScript type definitions
30+
│ ├── utils/ # Utility functions package
31+
│ ├── file-loaders/ # File processing packages
32+
│ ├── prompts/ # AI prompt management
33+
│ └── web-crawler/ # Web crawling functionality
34+
├── public/ # Static assets
35+
│ ├── icons/ # Application icons
36+
│ ├── images/ # Image resources
37+
│ └── screenshots/ # Application screenshots
38+
├── scripts/ # Build and tool scripts
39+
├── src/ # Main application source code (see below)
40+
├── tests/ # Test configuration
41+
├── .cursor/ # Cursor AI configuration
42+
├── docker-compose/ # Docker configuration
43+
├── package.json # Project dependencies
44+
├── pnpm-workspace.yaml # pnpm monorepo configuration
45+
├── next.config.ts # Next.js configuration
46+
├── drizzle.config.ts # Drizzle ORM configuration
47+
└── tsconfig.json # TypeScript configuration
48+
```
49+
50+
## Core Source Directory (`src/`)
51+
52+
```plaintext
53+
src/
54+
├── app/ # Next.js App Router routes
55+
│ ├── (backend)/ # Backend API routes
56+
│ │ ├── api/ # REST API endpoints
57+
│ │ │ ├── auth/ # Authentication endpoints
58+
│ │ │ └── webhooks/ # Webhook handlers for various auth providers
59+
│ │ ├── middleware/ # Request middleware
60+
│ │ ├── oidc/ # OpenID Connect endpoints
61+
│ │ ├── trpc/ # tRPC API routes
62+
│ │ │ ├── async/ # Async tRPC endpoints
63+
│ │ │ ├── edge/ # Edge runtime endpoints
64+
│ │ │ ├── lambda/ # Lambda runtime endpoints
65+
│ │ │ └── tools/ # Tools-specific endpoints
66+
│ │ └── webapi/ # Web API endpoints
67+
│ │ ├── chat/ # Chat-related APIs for various providers
68+
│ │ ├── models/ # Model management APIs
69+
│ │ ├── plugin/ # Plugin system APIs
70+
│ │ ├── stt/ # Speech-to-text APIs
71+
│ │ ├── text-to-image/ # Image generation APIs
72+
│ │ └── tts/ # Text-to-speech APIs
73+
│ ├── [variants]/ # Page route variants
74+
│ │ ├── (main)/ # Main application routes
75+
│ │ │ ├── chat/ # Chat interface and workspace
76+
│ │ │ ├── discover/ # Discover page (assistants, models, providers)
77+
│ │ │ ├── files/ # File management interface
78+
│ │ │ ├── image/ # Image generation interface
79+
│ │ │ ├── profile/ # User profile and stats
80+
│ │ │ ├── repos/ # Knowledge base repositories
81+
│ │ │ └── settings/ # Application settings
82+
│ │ └── @modal/ # Modal routes
83+
│ └── manifest.ts # PWA configuration
84+
├── components/ # Global shared components
85+
│ ├── Analytics/ # Analytics tracking components
86+
│ ├── Error/ # Error handling components
87+
│ └── Loading/ # Loading state components
88+
├── config/ # Application configuration
89+
│ ├── aiModels/ # AI model configurations
90+
│ └── modelProviders/ # Model provider configurations
91+
├── features/ # Feature components (UI Layer)
92+
│ ├── AgentSetting/ # Agent configuration and management
93+
│ ├── ChatInput/ # Chat input with file upload and tools
94+
│ ├── Conversation/ # Message display and interaction
95+
│ ├── FileManager/ # File upload and knowledge base
96+
│ └── PluginStore/ # Plugin marketplace and management
97+
├── hooks/ # Custom React hooks
98+
├── layout/ # Global layout components
99+
│ ├── AuthProvider/ # Authentication provider
100+
│ └── GlobalProvider/ # Global state provider
101+
├── libs/ # External library integrations
102+
│ ├── analytics/ # Analytics services integration
103+
│ ├── next-auth/ # NextAuth.js configuration
104+
│ └── oidc-provider/ # OIDC provider implementation
105+
├── locales/ # Internationalization resources
106+
│ └── default/ # Default language definitions
107+
├── migrations/ # Client-side data migrations
108+
├── server/ # Server-side code
109+
│ ├── modules/ # Server modules
110+
│ ├── routers/ # tRPC routers
111+
│ └── services/ # Server services
112+
├── services/ # Client service layer
113+
│ ├── aiModel/ # AI model services
114+
│ ├── session/ # Session services
115+
│ └── message/ # Message services
116+
├── store/ # Zustand state management
117+
│ ├── agent/ # Agent state
118+
│ ├── chat/ # Chat state
119+
│ └── user/ # User state
120+
├── styles/ # Global styles
121+
├── tools/ # Built-in tool system
122+
│ ├── artifacts/ # Code artifacts and preview
123+
│ └── web-browsing/ # Web search and browsing
124+
├── types/ # TypeScript type definitions
125+
└── utils/ # Utility functions
126+
├── client/ # Client-side utilities
127+
└── server/ # Server-side utilities
128+
```
129+
130+
## Key Monorepo Packages
131+
132+
```plaintext
133+
packages/
134+
├── const/ # Global constants and configurations
135+
├── database/ # Database schemas and models
136+
│ ├── src/models/ # Data models (CRUD operations)
137+
│ ├── src/schemas/ # Drizzle database schemas
138+
│ ├── src/repositories/ # Complex query layer
139+
│ └── migrations/ # Database migration files
140+
├── model-runtime/ # AI model runtime
141+
│ └── src/
142+
│ ├── openai/ # OpenAI provider integration
143+
│ ├── anthropic/ # Anthropic provider integration
144+
│ ├── google/ # Google AI provider integration
145+
│ ├── ollama/ # Ollama local model integration
146+
│ ├── types/ # Runtime type definitions
147+
│ └── utils/ # Runtime utilities
148+
├── types/ # Shared TypeScript type definitions
149+
│ └── src/
150+
│ ├── agent/ # Agent-related types
151+
│ ├── message/ # Message and chat types
152+
│ ├── user/ # User and session types
153+
│ └── tool/ # Tool and plugin types
154+
├── utils/ # Shared utility functions
155+
│ └── src/
156+
│ ├── client/ # Client-side utilities
157+
│ ├── server/ # Server-side utilities
158+
│ ├── fetch/ # HTTP request utilities
159+
│ └── tokenizer/ # Token counting utilities
160+
├── file-loaders/ # File loaders (PDF, DOCX, etc.)
161+
├── prompts/ # AI prompt management
162+
└── web-crawler/ # Web crawling functionality
163+
```
164+
165+
## Architecture Layers
166+
167+
### 1. **Presentation Layer**
168+
169+
- Business-specific feature components and reusable UI components
170+
- Global layout providers and responsive design wrappers
171+
172+
### 2. **State Management Layer**
173+
174+
- Zustand-based client state with domain-specific slices
175+
- Actions and selectors for predictable state updates
176+
177+
### 3. **Client Service Layer**
178+
179+
- Environment-adaptive services (local Model vs remote tRPC)
180+
- Dual implementation pattern for multi-runtime compatibility
181+
182+
### 4. **API Interface Layer**
183+
184+
- Type-safe tRPC routers organized by runtime environment
185+
- Request routing and validation
186+
187+
### 5. **Server Service Layer**
188+
189+
- Platform-agnostic business logic with implementation abstractions
190+
- Reusable, testable service composition
191+
192+
### 6. **Data Access Layer**
193+
194+
- **Repository**: Complex queries, joins, and transaction management
195+
- **Model**: Basic CRUD operations and single-table queries
196+
- **Schema**: Drizzle ORM definitions and migration management
197+
198+
### 7. **Integration & Extensions**
199+
200+
- **External**: Third-party service integrations and library wrappers
201+
- **Built-in**: AI runtime, tool system, file processing, and web crawling
202+
203+
## Data Flow Architecture
204+
205+
### Unified Flow Pattern
206+
207+
```
208+
UI Layer → State Management → Client Service → [Environment Branch] → Database
209+
↓ ↓ ↓ ↓ ↓
210+
React Zustand Environment Local/Remote PGLite/
211+
Components Store Adaptation Routing PostgreSQL
212+
```
213+
214+
### Environment-Specific Routing
215+
216+
| Mode | UI | Service Route | Database |
217+
| --------------- | -------- | ---------------------- | ------------------- |
218+
| **Browser/PWA** | React | Direct Model Access | PGLite (Local) |
219+
| **Server** | React | tRPC → Server Services | PostgreSQL (Remote) |
220+
| **Desktop** | Electron | tRPC → Local Node.js | PGLite/PostgreSQL\* |
221+
222+
_\*Depends on cloud sync configuration_
223+
224+
### Key Characteristics
225+
226+
- **Type Safety**: End-to-end type safety via tRPC and Drizzle ORM
227+
- **Local/Remote Dual Mode**: PGLite enables user data ownership and local control

.cursor/rules/testing-guide/db-model-test.mdc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ alwaysApply: false
55

66
## 🗃️ 数据库 Model 测试指南
77

8+
测试 `packages/database` 下的数据库 Model 层。
9+
810
### 测试环境选择 💡
911

1012
数据库 Model 层通过环境变量控制数据库类型,在两种测试环境下有不同的数据库后端:客户端环境 (PGLite) 和 服务端环境 (PostgreSQL)
@@ -17,10 +19,10 @@ alwaysApply: false
1719

1820
```bash
1921
# 1. 先在客户端环境测试(快速验证)
20-
npx vitest run --config vitest.config.ts src/database/models/__tests__/myModel.test.ts
22+
cd packages/database && TEST_SERVER_DB=0 bunx vitest run --silent='passed-only' src/database/models/__tests__/myModel.test.ts
2123

22-
# 2. 再在服务端环境测试(兼容性验证)
23-
npx vitest run --config vitest.config.server.ts src/database/models/__tests__/myModel.test.ts
24+
# 2. 再在服务端环境测试(兼容性验证), 需要设置环境变量 `TEST_SERVER_DB=1`
25+
cd packages/database && TEST_SERVER_DB=1 bunx vitest run --silent='passed-only' src/database/models/__tests__/myModel.test.ts #
2426
```
2527

2628
### 创建新 Model 测试的最佳实践 📋

0 commit comments

Comments
 (0)