Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

📝 docs: Add image generation development environment setup (#8859)

Maple Gao3ae513498443
diff --git a/docs/development/basic/image-generation-setup.mdx b/docs/development/basic/image-generation-setup.mdx
new file mode 100644
index 00000000000..8acb3c25c56
--- /dev/null
+++ b/docs/development/basic/image-generation-setup.mdx
@@ -0,0 +1,190 @@
+---
+title: Image Generation Development Setup
+description: Configure local environment for developing text-to-image and image-to-image features
+---
+
+# Image Generation Development Setup
+
+This guide helps developers set up the local environment for developing image generation features (text-to-image, image-to-image) with file storage capabilities.
+
+## Prerequisites
+
+- Docker installed and running
+- Node.js and pnpm installed
+- PostgreSQL client tools (optional, for debugging)
+
+<Callout type="warning">
+ **Security Notice**: This setup is designed for local development only. It uses default credentials and open permissions that are NOT suitable for production environments.
+</Callout>
+
+## Quick Setup
+
+Run the provided script to automatically set up all required services:
+
+```bash
+# Set up PostgreSQL and MinIO for image storage
+./scripts/setup-image-generation-dev.sh
+
+# Start the development server
+pnpm dev:desktop
+```
+
+This script will:
+
+1. Start PostgreSQL (no authentication for local development)
+2. Run database migrations to initialize schema
+3. Start MinIO (S3-compatible storage)
+4. Create and configure the storage bucket
+5. Add necessary S3 environment variables to `.env.desktop`
+
+## Architecture Overview
+
+The image generation feature requires:
+
+- **PostgreSQL**: Stores metadata about generated images
+- **MinIO/S3**: Stores the actual image files
+- **Server Mode**: Required for file handling (`NEXT_PUBLIC_SERVICE_MODE=server`)
+
+## Environment Configuration
+
+The following environment variables are automatically configured by the setup script:
+
+```bash
+# S3 Storage Configuration (MinIO for local development)
+S3_ACCESS_KEY_ID=minioadmin
+S3_SECRET_ACCESS_KEY=minioadmin
+S3_ENDPOINT=http://localhost:9000
+S3_BUCKET=lobe-chat
+S3_REGION=us-east-1
+S3_PUBLIC_DOMAIN=http://localhost:9000/lobe-chat
+S3_ENABLE_PATH_STYLE=1 # Required for MinIO
+```
+
+## Development Workflow
+
+### 1. Image Generation API
+
+When developing image generation features, generated images will be:
+
+1. Created by the AI model
+2. Uploaded to S3/MinIO via presigned URLs
+3. Metadata stored in PostgreSQL
+4. Served via the public S3 URL
+
+### 2. File Storage Structure
+
+```
+lobe-chat/ # S3 Bucket
+├── generated/ # Generated images
+│ └── {userId}/
+│ └── {sessionId}/
+│ └── {imageId}.png
+└── uploads/ # User uploads for image-to-image
+ └── {userId}/
+ └── {fileId}.{ext}
+```
+
+### 3. Testing Your Implementation
+
+After setting up the environment, you can test:
+
+```typescript
+// Example: Upload generated image
+const uploadUrl = await trpc.upload.createPresignedUrl.mutate({
+ filename: 'generated-image.png',
+ contentType: 'image/png',
+});
+
+// Upload to S3
+await fetch(uploadUrl, {
+ method: 'PUT',
+ body: imageBlob,
+ headers: { 'Content-Type': 'image/png' },
+});
+```
+
+## Manual Setup
+
+If you prefer to set up services manually:
+
+### PostgreSQL
+
+```bash
+docker run -d --name lobe-postgres \
+ -p 5432:5432 \
+ -e POSTGRES_HOST_AUTH_METHOD=trust \
+ -e POSTGRES_DB=postgres \
+ postgres:15
+```
+
+### MinIO
+
+```bash
+# Start MinIO
+docker run -d --name lobe-minio \
+ -p 9000:9000 -p 9001:9001 \
+ -e MINIO_ROOT_USER=minioadmin \
+ -e MINIO_ROOT_PASSWORD=minioadmin \
+ quay.io/minio/minio:RELEASE.2025-04-22T22-12-26Z \
+ server /data --console-address ":9001"
+
+# Create bucket
+docker run --rm \
+ --link lobe-minio:minio \
+ --entrypoint bash \
+ quay.io/minio/mc:RELEASE.2025-04-18T16-45-00Z \
+ -c "
+ mc config host add minio http://minio:9000 minioadmin minioadmin &&
+ mc mb minio/lobe-chat &&
+ mc anonymous set public minio/lobe-chat
+ "
+```
+
+## Service URLs
+
+- **PostgreSQL**: `postgres://postgres@localhost:5432/postgres`
+- **MinIO API**: `http://localhost:9000`
+- **MinIO Console**: `http://localhost:9001` (minioadmin/minioadmin)
+- **Application**: `http://localhost:3015`
+
+## Troubleshooting
+
+### Port Conflicts
+
+If ports are already in use:
+
+```bash
+# Check what's using the ports
+lsof -i :5432 # PostgreSQL
+lsof -i :9000 # MinIO API
+lsof -i :9001 # MinIO Console
+```
+
+### Reset Environment
+
+To completely reset your development environment:
+
+```bash
+# Stop and remove containers
+docker stop lobe-postgres lobe-minio
+docker rm lobe-postgres lobe-minio
+
+# Re-run setup
+./scripts/setup-image-generation-dev.sh
+```
+
+### Database Migrations
+
+The setup script runs migrations automatically. If you need to run them manually:
+
+```bash
+pnpm db:migrate
+```
+
+Note: In development mode with `pnpm dev:desktop`, migrations also run automatically on startup.
+
+## Related Documentation
+
+- [Server Database Setup](/docs/self-hosting/server-database)
+- [S3 Storage Configuration](/docs/self-hosting/advanced/s3)
+- [Environment Variables](/docs/self-hosting/environment-variables)
diff --git a/docs/development/basic/image-generation-setup.zh-CN.mdx b/docs/development/basic/image-generation-setup.zh-CN.mdx
new file mode 100644
index 00000000000..26f51a856dd
--- /dev/null
+++ b/docs/development/basic/image-generation-setup.zh-CN.mdx
@@ -0,0 +1,190 @@
+---
+title: 图像生成开发环境配置
+description: 配置本地环境以开发文本生图和图像处理功能
+---
+
+# 图像生成开发环境配置
+
+本指南帮助开发者配置本地环境,用于开发图像生成功能(文生图、图生图)等和文件存储能力。
+
+## 前置条件
+
+- 已安装并运行 Docker
+- 已安装 Node.js 和 pnpm
+- PostgreSQL 客户端工具(可选,用于调试)
+
+<Callout type="warning">
+ **安全提醒**:此配置仅适用于本地开发。使用的默认凭据和开放权限不适合生产环境。
+</Callout>
+
+## 快速配置
+
+运行提供的脚本来自动配置所有必需的服务:
+
+```bash
+# 配置 PostgreSQL 和 MinIO 用于图像存储
+./scripts/setup-image-generation-dev.sh
+
+# 启动开发服务器
+pnpm dev:desktop
+```
+
+此脚本将执行:
+
+1. 启动 PostgreSQL(本地开发无需身份验证)
+2. 运行数据库迁移以初始化模式
+3. 启动 MinIO(S3 兼容存储)
+4. 创建并配置存储桶
+5. 在 `.env.desktop` 中添加必要的 S3 环境变量
+
+## 架构概览
+
+图像生成功能需要:
+
+- **PostgreSQL**:存储生成图像的元数据
+- **MinIO/S3**:存储实际的图像文件
+- **服务器模式**:文件处理所需(`NEXT_PUBLIC_SERVICE_MODE=server`)
+
+## 环境配置
+
+以下环境变量会被配置脚本自动设置:
+
+```bash
+# S3 存储配置(本地开发使用 MinIO)
+S3_ACCESS_KEY_ID=minioadmin
+S3_SECRET_ACCESS_KEY=minioadmin
+S3_ENDPOINT=http://localhost:9000
+S3_BUCKET=lobe-chat
+S3_REGION=us-east-1
+S3_PUBLIC_DOMAIN=http://localhost:9000/lobe-chat
+S3_ENABLE_PATH_STYLE=1 # MinIO 必需
+```
+
+## 开发工作流
+
+### 1. 图像生成 API
+
+在开发图像生成功能时,生成的图像将:
+
+1. 由 AI 模型创建
+2. 通过预签名 URL 上传到 S3/MinIO
+3. 元数据存储在 PostgreSQL 中
+4. 通过公共 S3 URL 提供服务
+
+### 2. 文件存储结构
+
+```
+lobe-chat/ # S3 存储桶
+├── generated/ # 生成的图像
+│ └── {userId}/
+│ └── {sessionId}/
+│ └── {imageId}.png
+└── uploads/ # 用户上传的图像处理文件
+ └── {userId}/
+ └── {fileId}.{ext}
+```
+
+### 3. 测试您的实现
+
+配置环境后,您可以测试:
+
+```typescript
+// 示例:上传生成的图像
+const uploadUrl = await trpc.upload.createPresignedUrl.mutate({
+ filename: 'generated-image.png',
+ contentType: 'image/png',
+});
+
+// 上传到 S3
+await fetch(uploadUrl, {
+ method: 'PUT',
+ body: imageBlob,
+ headers: { 'Content-Type': 'image/png' },
+});
+```
+
+## 手动配置
+
+如果您希望手动配置服务:
+
+### PostgreSQL
+
+```bash
+docker run -d --name lobe-postgres \
+ -p 5432:5432 \
+ -e POSTGRES_HOST_AUTH_METHOD=trust \
+ -e POSTGRES_DB=postgres \
+ postgres:15
+```
+
+### MinIO
+
+```bash
+# 启动 MinIO
+docker run -d --name lobe-minio \
+ -p 9000:9000 -p 9001:9001 \
+ -e MINIO_ROOT_USER=minioadmin \
+ -e MINIO_ROOT_PASSWORD=minioadmin \
+ quay.io/minio/minio:RELEASE.2025-04-22T22-12-26Z \
+ server /data --console-address ":9001"
+
+# 创建存储桶
+docker run --rm \
+ --link lobe-minio:minio \
+ --entrypoint bash \
+ quay.io/minio/mc:RELEASE.2025-04-18T16-45-00Z \
+ -c "
+ mc config host add minio http://minio:9000 minioadmin minioadmin &&
+ mc mb minio/lobe-chat &&
+ mc anonymous set public minio/lobe-chat
+ "
+```
+
+## 服务地址
+
+- **PostgreSQL**:`postgres://postgres@localhost:5432/postgres`
+- **MinIO API**:`http://localhost:9000`
+- **MinIO 控制台**:`http://localhost:9001` (minioadmin/minioadmin)
+- **应用程序**:`http://localhost:3015`
+
+## 故障排除
+
+### 端口冲突
+
+如果端口已被占用:
+
+```bash
+# 检查端口使用情况
+lsof -i :5432 # PostgreSQL
+lsof -i :9000 # MinIO API
+lsof -i :9001 # MinIO 控制台
+```
+
+### 重置环境
+
+要完全重置开发环境:
+
+```bash
+# 停止并删除容器
+docker stop lobe-postgres lobe-minio
+docker rm lobe-postgres lobe-minio
+
+# 重新运行配置
+./scripts/setup-image-generation-dev.sh
+```
+
+### 数据库迁移
+
+配置脚本会自动运行迁移。如需手动运行:
+
+```bash
+pnpm db:migrate
+```
+
+注意:在使用 `pnpm dev:desktop` 的开发模式下,迁移也会在启动时自动运行。
+
+## 相关文档
+
+- [服务器数据库配置](/docs/self-hosting/server-database)
+- [S3 存储配置](/docs/self-hosting/advanced/s3)
+- [环境变量](/docs/self-hosting/environment-variables)
diff --git a/scripts/setup-image-generation-dev.sh b/scripts/setup-image-generation-dev.sh
new file mode 100755
index 00000000000..91830f9bb9e
--- /dev/null
+++ b/scripts/setup-image-generation-dev.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+
+echo "🚀 Setting up image upload development environment..."
+
+# 1. 设置 PostgreSQL (无密码本地开发)
+echo "Step 1: Setting up PostgreSQL..."
+docker stop lobe-postgres 2>/dev/null && docker rm lobe-postgres 2>/dev/null
+docker run -d --name lobe-postgres \
+ -p 5432:5432 \
+ -e POSTGRES_HOST_AUTH_METHOD=trust \
+ -e POSTGRES_DB=postgres \
+ postgres:15
+
+echo "Waiting for PostgreSQL to start..."
+sleep 10
+
+# 运行数据库迁移
+echo "Running database migrations..."
+pnpm db:migrate
+
+# 2. 启动 MinIO
+echo ""
+echo "Step 2: Starting MinIO..."
+docker stop lobe-minio 2>/dev/null && docker rm lobe-minio 2>/dev/null
+docker run -d --name lobe-minio \
+ -p 9000:9000 -p 9001:9001 \
+ -e MINIO_ROOT_USER=minioadmin \
+ -e MINIO_ROOT_PASSWORD=minioadmin \
+ quay.io/minio/minio:RELEASE.2025-04-22T22-12-26Z server /data --console-address ":9001"
+
+# 3. 等待 MinIO 启动
+echo "Waiting for MinIO to start..."
+sleep 10
+
+# 4. 创建 bucket 并设置权限
+echo "Creating bucket and setting permissions..."
+docker run --rm \
+ --link lobe-minio:minio \
+ --entrypoint bash \
+ quay.io/minio/mc:RELEASE.2025-04-18T16-45-00Z \
+ -c "
+ mc config host add minio http://minio:9000 minioadmin minioadmin
+ mb_output=\$(mc mb minio/lobe-chat 2>&1)
+ mb_exit=\$?
+ if [ \$mb_exit -ne 0 ]; then
+ echo \"\$mb_output\" | grep -q 'Bucket already exists' || { echo \"Failed to create bucket: \$mb_output\"; exit \$mb_exit; }
+ fi
+ mc anonymous set public minio/lobe-chat
+ "
+
+# 5. 检查并添加 S3 配置
+if [ ! -f .env.desktop ]; then
+ echo "Creating .env.desktop from .env.example..."
+ cp .env.example .env.desktop
+fi
+
+if ! grep -q "S3_ACCESS_KEY_ID" .env.desktop 2>/dev/null; then
+ echo ""
+ echo "Adding S3 configuration to .env.desktop..."
+ echo "" >> .env.desktop
+ echo "# Image Upload Configuration (added by setup-image-dev.sh)" >> .env.desktop
+ echo "S3_ACCESS_KEY_ID=minioadmin" >> .env.desktop
+ echo "S3_SECRET_ACCESS_KEY=minioadmin" >> .env.desktop
+ echo "S3_ENDPOINT=http://localhost:9000" >> .env.desktop
+ echo "S3_BUCKET=lobe-chat" >> .env.desktop
+ echo "S3_REGION=us-east-1" >> .env.desktop
+ echo "S3_PUBLIC_DOMAIN=http://localhost:9000/lobe-chat" >> .env.desktop
+ echo "S3_ENABLE_PATH_STYLE=1" >> .env.desktop
+else
+ echo "S3 configuration already exists in .env.desktop"
+fi
+
+echo ""
+echo "✅ Image development environment ready!"
+echo ""
+echo "Services running:"
+echo " - PostgreSQL: postgres://postgres@localhost:5432/postgres (no password)"
+echo " - MinIO S3: http://localhost:9000"
+echo " - MinIO Console: http://localhost:9001 (minioadmin/minioadmin)"
+echo ""
+echo "Next step: pnpm dev:desktop"