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: update app directory structure documentation (#9582)

Arvin Xuc83d7afbe6b4
diff --git a/docs/development/basic/folder-structure.mdx b/docs/development/basic/folder-structure.mdx
index f74fe632a6c..7fcc42922f2 100644
--- a/docs/development/basic/folder-structure.mdx
+++ b/docs/development/basic/folder-structure.mdx
@@ -4,37 +4,88 @@ The directory structure of LobeChat is as follows:
```bash
src
-โ”œโ”€โ”€ app # Main logic and state management related code for the application
+โ”œโ”€โ”€ app # Next.js App Router implementation with route groups and API routes
โ”œโ”€โ”€ components # Reusable UI components
โ”œโ”€โ”€ config # Application configuration files, including client-side and server-side environment variables
-โ”œโ”€โ”€ const # Used to define constants, such as action types, route names, etc.
โ”œโ”€โ”€ features # Function modules related to business functions, such as agent settings, plugin development pop-ups, etc.
โ”œโ”€โ”€ hooks # Custom utility hooks reused throughout the application
โ”œโ”€โ”€ layout # Application layout components, such as navigation bars, sidebars, etc.
+โ”œโ”€โ”€ libs # Third-party integrations (analytics, OIDC, etc.)
โ”œโ”€โ”€ locales # Internationalization language files
+โ”œโ”€โ”€ server # Server-side modules and services
โ”œโ”€โ”€ services # Encapsulated backend service interfaces, such as HTTP requests
โ”œโ”€โ”€ store # Zustand store for state management
+โ”œโ”€โ”€ styles # Global styles and CSS-in-JS configurations
โ”œโ”€โ”€ types # TypeScript type definition files
โ””โ”€โ”€ utils # Common utility functions
```
## app
-In the `app` folder, we organize each route page according to the app router's [Route Groups](https://nextjs.org/docs/app/building-your-application/routing/route-groups) to separately handle the implementation of desktop and mobile code. Taking the file structure of the `welcome` page as an example:
+The `app` directory follows Next.js 13+ App Router conventions with a sophisticated architecture using [Route Groups](https://nextjs.org/docs/app/building-your-application/routing/route-groups) to organize backend services, platform variants, and application routes:
```bash
-welcome
-โ”œโ”€โ”€ (desktop) # Desktop implementation
-โ”‚ โ”œโ”€โ”€ features # Desktop-specific features
-โ”‚ โ”œโ”€โ”€ index.tsx # Main entry file for desktop
-โ”‚ โ””โ”€โ”€ layout.desktop.tsx # Desktop layout component
-โ”œโ”€โ”€ (mobile) # Mobile implementation
-โ”‚ โ”œโ”€โ”€ features # Mobile-specific features
-โ”‚ โ”œโ”€โ”€ index.tsx # Main entry file for mobile
-โ”‚ โ””โ”€โ”€ layout.mobile.tsx # Mobile layout component
-โ”œโ”€โ”€ features # This folder contains features code shared by both desktop and mobile, such as the Banner component
-โ”‚ โ””โ”€โ”€ Banner
-โ””โ”€โ”€ page.tsx # This is the main entry file for the page, used to load desktop or mobile code based on the device type
+app
+โ”œโ”€โ”€ (backend)/ # Backend API routes and services
+โ”‚ โ”œโ”€โ”€ api/ # REST API endpoints
+โ”‚ โ”‚ โ”œโ”€โ”€ auth/ # Authentication routes
+โ”‚ โ”‚ โ””โ”€โ”€ webhooks/ # Webhook handlers
+โ”‚ โ”œโ”€โ”€ middleware/ # Request middleware
+โ”‚ โ”œโ”€โ”€ oidc/ # OpenID Connect routes
+โ”‚ โ”œโ”€โ”€ trpc/ # tRPC API endpoints
+โ”‚ โ”‚ โ”œโ”€โ”€ async/ # Async tRPC routes
+โ”‚ โ”‚ โ”œโ”€โ”€ desktop/ # Desktop-specific tRPC routes
+โ”‚ โ”‚ โ”œโ”€โ”€ edge/ # Edge runtime tRPC routes
+โ”‚ โ”‚ โ”œโ”€โ”€ lambda/ # Lambda tRPC routes
+โ”‚ โ”‚ โ””โ”€โ”€ tools/ # Tools tRPC routes
+โ”‚ โ””โ”€โ”€ webapi/ # Web API endpoints
+โ”‚ โ”œโ”€โ”€ chat/ # Chat-related APIs
+โ”‚ โ”œโ”€โ”€ models/ # Model management APIs
+โ”‚ โ”œโ”€โ”€ tts/ # Text-to-speech APIs
+โ”‚ โ””โ”€โ”€ ...
+โ”œโ”€โ”€ [variants]/ # Platform and device variants
+โ”‚ โ”œโ”€โ”€ (auth)/ # Authentication pages
+โ”‚ โ”‚ โ”œโ”€โ”€ login/
+โ”‚ โ”‚ โ”œโ”€โ”€ signup/
+โ”‚ โ”‚ โ””โ”€โ”€ next-auth/
+โ”‚ โ”œโ”€โ”€ (main)/ # Main application routes
+โ”‚ โ”‚ โ”œโ”€โ”€ (mobile)/ # Mobile-specific routes
+โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ me/ # Mobile profile pages
+โ”‚ โ”‚ โ”œโ”€โ”€ _layout/ # Layout components
+โ”‚ โ”‚ โ”œโ”€โ”€ chat/ # Chat interface
+โ”‚ โ”‚ โ”œโ”€โ”€ discover/ # Discovery pages
+โ”‚ โ”‚ โ”œโ”€โ”€ files/ # File management
+โ”‚ โ”‚ โ”œโ”€โ”€ image/ # Image generation
+โ”‚ โ”‚ โ”œโ”€โ”€ profile/ # User profile
+โ”‚ โ”‚ โ”œโ”€โ”€ repos/ # Repository management
+โ”‚ โ”‚ โ””โ”€โ”€ settings/ # Application settings
+โ”‚ โ””โ”€โ”€ @modal/ # Parallel modal routes
+โ”‚ โ”œโ”€โ”€ (.)changelog/
+โ”‚ โ””โ”€โ”€ _layout/
+โ”œโ”€โ”€ desktop/ # Desktop-specific routes
+โ”‚ โ””โ”€โ”€ devtools/
+โ”œโ”€โ”€ manifest.ts # PWA manifest
+โ”œโ”€โ”€ robots.tsx # Robots.txt generation
+โ”œโ”€โ”€ sitemap.tsx # Sitemap generation
+โ””โ”€โ”€ sw.ts # Service worker
```
-In this way, we can clearly distinguish and manage desktop and mobile code, while also easily reusing code required on both devices, thereby improving development efficiency and maintaining code cleanliness and maintainability.
+### Architecture Explanation
+
+**Route Groups:**
+- `(backend)` - Contains all server-side API routes, middleware, and backend services
+- `[variants]` - Dynamic route group handling different platform variants and main application pages
+- `@modal` - Parallel routes for modal dialogs using Next.js parallel routing
+
+**Platform Organization:**
+- The architecture supports multiple platforms (web, desktop, mobile) through route organization
+- Desktop-specific routes are in the `desktop/` directory
+- Mobile-specific routes are organized under `(main)/(mobile)/`
+- Shared layouts and components are in `_layout/` directories
+
+**API Architecture:**
+- REST APIs in `(backend)/api/` and `(backend)/webapi/`
+- tRPC endpoints organized by runtime environment (edge, lambda, async, desktop)
+- Authentication and OIDC handling in dedicated route groups
+
+This architecture provides clear separation of concerns while maintaining flexibility for different deployment targets and runtime environments.
diff --git a/docs/development/basic/folder-structure.zh-CN.mdx b/docs/development/basic/folder-structure.zh-CN.mdx
index 0368a94714c..16f2a8fa7dd 100644
--- a/docs/development/basic/folder-structure.zh-CN.mdx
+++ b/docs/development/basic/folder-structure.zh-CN.mdx
@@ -4,37 +4,88 @@ LobeChat ็š„ๆ–‡ไปถๅคน็›ฎๅฝ•ๆžถๆž„ๅฆ‚ไธ‹๏ผš
```bash
src
-โ”œโ”€โ”€ app # ๅบ”็”จไธป่ฆ้€ป่พ‘ๅ’Œ็Šถๆ€็ฎก็†็›ธๅ…ณ็š„ไปฃ็ 
+โ”œโ”€โ”€ app # Next.js App Router ๅฎž็Žฐ๏ผŒๅŒ…ๅซ่ทฏ็”ฑ็ป„ๅ’Œ API ่ทฏ็”ฑ
โ”œโ”€โ”€ components # ๅฏๅค็”จ็š„ UI ็ป„ไปถ
โ”œโ”€โ”€ config # ๅบ”็”จ็š„้…็ฝฎๆ–‡ไปถ๏ผŒๅŒ…ๅซๅฎขๆˆท็ซฏ็Žฏๅขƒๅ˜้‡ไธŽๆœๅŠก็ซฏ็Žฏๅขƒๅ˜้‡
-โ”œโ”€โ”€ const # ็”จไบŽๅฎšไน‰ๅธธ้‡๏ผŒๅฆ‚ action ็ฑปๅž‹ใ€่ทฏ็”ฑๅ็ญ‰
โ”œโ”€โ”€ features # ไธŽไธšๅŠกๅŠŸ่ƒฝ็›ธๅ…ณ็š„ๅŠŸ่ƒฝๆจกๅ—๏ผŒๅฆ‚ Agent ่ฎพ็ฝฎใ€ๆ’ไปถๅผ€ๅ‘ๅผน็ช—็ญ‰
โ”œโ”€โ”€ hooks # ๅ…จๅบ”็”จๅค็”จ่‡ชๅฎšไน‰็š„ๅทฅๅ…ท Hooks
โ”œโ”€โ”€ layout # ๅบ”็”จ็š„ๅธƒๅฑ€็ป„ไปถ๏ผŒๅฆ‚ๅฏผ่ˆชๆ ใ€ไพง่พนๆ ็ญ‰
+โ”œโ”€โ”€ libs # ็ฌฌไธ‰ๆ–น้›†ๆˆ๏ผˆๅˆ†ๆžใ€OIDC ็ญ‰๏ผ‰
โ”œโ”€โ”€ locales # ๅ›ฝ้™…ๅŒ–็š„่ฏญ่จ€ๆ–‡ไปถ
+โ”œโ”€โ”€ server # ๆœๅŠก็ซฏๆจกๅ—ๅ’ŒๆœๅŠก
โ”œโ”€โ”€ services # ๅฐ่ฃ…็š„ๅŽ็ซฏๆœๅŠกๆŽฅๅฃ๏ผŒๅฆ‚ HTTP ่ฏทๆฑ‚
โ”œโ”€โ”€ store # ็”จไบŽ็Šถๆ€็ฎก็†็š„ zustand store
+โ”œโ”€โ”€ styles # ๅ…จๅฑ€ๆ ทๅผๅ’Œ CSS-in-JS ้…็ฝฎ
โ”œโ”€โ”€ types # TypeScript ็š„็ฑปๅž‹ๅฎšไน‰ๆ–‡ไปถ
โ””โ”€โ”€ utils # ้€š็”จ็š„ๅทฅๅ…ทๅ‡ฝๆ•ฐ
```
## app
-ๅœจ `app` ๆ–‡ไปถๅคนไธญ๏ผŒๆˆ‘ไปฌๅฐ†ๆฏไธช่ทฏ็”ฑ้กต้ขๆŒ‰็…ง app router ็š„ [Route Groups](https://nextjs.org/docs/app/building-your-application/routing/route-groups) ่ฟ›่กŒ็ป„็ป‡๏ผŒไปฅๆญคๆฅๅˆ†ๅˆซๅค„็†ๆกŒ้ข็ซฏๅ’Œ็งปๅŠจ็ซฏ็š„ไปฃ็ ๅฎž็Žฐใ€‚ไปฅ `welcome` ้กต้ข็š„ๆ–‡ไปถ็ป“ๆž„ไธบไพ‹๏ผš
+`app` ็›ฎๅฝ•้ตๅพช Next.js 13+ App Router ็บฆๅฎš๏ผŒ้‡‡็”จๅคๆ‚็š„ๆžถๆž„๏ผŒไฝฟ็”จ [่ทฏ็”ฑ็ป„](https://nextjs.org/docs/app/building-your-application/routing/route-groups) ๆฅ็ป„็ป‡ๅŽ็ซฏๆœๅŠกใ€ๅนณๅฐๅ˜ไฝ“ๅ’Œๅบ”็”จ่ทฏ็”ฑ๏ผš
```bash
-welcome
-โ”œโ”€โ”€ (desktop) # ๆกŒ้ข็ซฏๅฎž็Žฐ
-โ”‚ โ”œโ”€โ”€ features # ๆกŒ้ข็ซฏ็‰นๆœ‰็š„ๅŠŸ่ƒฝ
-โ”‚ โ”œโ”€โ”€ index.tsx # ๆกŒ้ข็ซฏ็š„ไธปๅ…ฅๅฃๆ–‡ไปถ
-โ”‚ โ””โ”€โ”€ layout.desktop.tsx # ๆกŒ้ข็ซฏ็š„ๅธƒๅฑ€็ป„ไปถ
-โ”œโ”€โ”€ (mobile) # ็งปๅŠจ็ซฏๅฎž็Žฐ
-โ”‚ โ”œโ”€โ”€ features # ็งปๅŠจ็ซฏ็‰นๆœ‰็š„ๅŠŸ่ƒฝ
-โ”‚ โ”œโ”€โ”€ index.tsx # ็งปๅŠจ็ซฏ็š„ไธปๅ…ฅๅฃๆ–‡ไปถ
-โ”‚ โ””โ”€โ”€ layout.mobile.tsx # ็งปๅŠจ็ซฏ็š„ๅธƒๅฑ€็ป„ไปถ
-โ”œโ”€โ”€ features # ๆญคๆ–‡ไปถๅคนๅŒ…ๅซๅŒ็ซฏๅ…ฑไบซ็š„็‰นๆ€งไปฃ็ ๏ผŒๅฆ‚ Banner ็ป„ไปถ
-โ”‚ โ””โ”€โ”€ Banner
-โ””โ”€โ”€ page.tsx # ๆญคไธบ้กต้ข็š„ไธปๅ…ฅๅฃๆ–‡ไปถ๏ผŒ็”จไบŽๆ นๆฎ่ฎพๅค‡็ฑปๅž‹้€‰ๆ‹ฉๅŠ ่ฝฝๆกŒ้ข็ซฏๆˆ–็งปๅŠจ็ซฏ็š„ไปฃ็ 
+app
+โ”œโ”€โ”€ (backend)/ # ๅŽ็ซฏ API ่ทฏ็”ฑๅ’ŒๆœๅŠก
+โ”‚ โ”œโ”€โ”€ api/ # REST API ็ซฏ็‚น
+โ”‚ โ”‚ โ”œโ”€โ”€ auth/ # ่บซไปฝ้ชŒ่ฏ่ทฏ็”ฑ
+โ”‚ โ”‚ โ””โ”€โ”€ webhooks/ # Webhook ๅค„็†ๅ™จ
+โ”‚ โ”œโ”€โ”€ middleware/ # ่ฏทๆฑ‚ไธญ้—ดไปถ
+โ”‚ โ”œโ”€โ”€ oidc/ # OpenID Connect ่ทฏ็”ฑ
+โ”‚ โ”œโ”€โ”€ trpc/ # tRPC API ็ซฏ็‚น
+โ”‚ โ”‚ โ”œโ”€โ”€ async/ # ๅผ‚ๆญฅ tRPC ่ทฏ็”ฑ
+โ”‚ โ”‚ โ”œโ”€โ”€ desktop/ # ๆกŒ้ข็ซฏไธ“็”จ tRPC ่ทฏ็”ฑ
+โ”‚ โ”‚ โ”œโ”€โ”€ edge/ # Edge ่ฟ่กŒๆ—ถ tRPC ่ทฏ็”ฑ
+โ”‚ โ”‚ โ”œโ”€โ”€ lambda/ # Lambda tRPC ่ทฏ็”ฑ
+โ”‚ โ”‚ โ””โ”€โ”€ tools/ # ๅทฅๅ…ท tRPC ่ทฏ็”ฑ
+โ”‚ โ””โ”€โ”€ webapi/ # Web API ็ซฏ็‚น
+โ”‚ โ”œโ”€โ”€ chat/ # ่Šๅคฉ็›ธๅ…ณ API
+โ”‚ โ”œโ”€โ”€ models/ # ๆจกๅž‹็ฎก็† API
+โ”‚ โ”œโ”€โ”€ tts/ # ๆ–‡ๆœฌ่ฝฌ่ฏญ้Ÿณ API
+โ”‚ โ””โ”€โ”€ ...
+โ”œโ”€โ”€ [variants]/ # ๅนณๅฐๅ’Œ่ฎพๅค‡ๅ˜ไฝ“
+โ”‚ โ”œโ”€โ”€ (auth)/ # ่บซไปฝ้ชŒ่ฏ้กต้ข
+โ”‚ โ”‚ โ”œโ”€โ”€ login/
+โ”‚ โ”‚ โ”œโ”€โ”€ signup/
+โ”‚ โ”‚ โ””โ”€โ”€ next-auth/
+โ”‚ โ”œโ”€โ”€ (main)/ # ไธปๅบ”็”จ่ทฏ็”ฑ
+โ”‚ โ”‚ โ”œโ”€โ”€ (mobile)/ # ็งปๅŠจ็ซฏไธ“็”จ่ทฏ็”ฑ
+โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ me/ # ็งปๅŠจ็ซฏไธชไบบ่ต„ๆ–™้กต้ข
+โ”‚ โ”‚ โ”œโ”€โ”€ _layout/ # ๅธƒๅฑ€็ป„ไปถ
+โ”‚ โ”‚ โ”œโ”€โ”€ chat/ # ่Šๅคฉ็•Œ้ข
+โ”‚ โ”‚ โ”œโ”€โ”€ discover/ # ๅ‘็Žฐ้กต้ข
+โ”‚ โ”‚ โ”œโ”€โ”€ files/ # ๆ–‡ไปถ็ฎก็†
+โ”‚ โ”‚ โ”œโ”€โ”€ image/ # ๅ›พๅƒ็”Ÿๆˆ
+โ”‚ โ”‚ โ”œโ”€โ”€ profile/ # ็”จๆˆท่ต„ๆ–™
+โ”‚ โ”‚ โ”œโ”€โ”€ repos/ # ไป“ๅบ“็ฎก็†
+โ”‚ โ”‚ โ””โ”€โ”€ settings/ # ๅบ”็”จ่ฎพ็ฝฎ
+โ”‚ โ””โ”€โ”€ @modal/ # ๅนถ่กŒๆจกๆ€ๆก†่ทฏ็”ฑ
+โ”‚ โ”œโ”€โ”€ (.)changelog/
+โ”‚ โ””โ”€โ”€ _layout/
+โ”œโ”€โ”€ desktop/ # ๆกŒ้ข็ซฏไธ“็”จ่ทฏ็”ฑ
+โ”‚ โ””โ”€โ”€ devtools/
+โ”œโ”€โ”€ manifest.ts # PWA ๆธ…ๅ•
+โ”œโ”€โ”€ robots.tsx # Robots.txt ็”Ÿๆˆ
+โ”œโ”€โ”€ sitemap.tsx # ็ซ™็‚นๅœฐๅ›พ็”Ÿๆˆ
+โ””โ”€โ”€ sw.ts # Service Worker
```
-้€š่ฟ‡่ฟ™็งๆ–นๅผ๏ผŒๆˆ‘ไปฌๅฏไปฅๆธ…ๆ™ฐๅœฐๅŒบๅˆ†ๅ’Œ็ฎก็†ๆกŒ้ข็ซฏๅ’Œ็งปๅŠจ็ซฏ็š„ไปฃ็ ๏ผŒๅŒๆ—ถไนŸ่ƒฝๆ–นไพฟๅœฐๅค็”จๅœจไธค็ง่ฎพๅค‡ไธŠ้ƒฝ้œ€่ฆ็š„ไปฃ็ ๏ผŒไปŽ่€Œๆ้ซ˜ๅผ€ๅ‘ๆ•ˆ็އๅนถไฟๆŒไปฃ็ ็š„ๆ•ดๆดๅ’Œๅฏ็ปดๆŠคๆ€งใ€‚
+### ๆžถๆž„่ฏดๆ˜Ž
+
+**่ทฏ็”ฑ็ป„๏ผš**
+- `(backend)` - ๅŒ…ๅซๆ‰€ๆœ‰ๆœๅŠก็ซฏ API ่ทฏ็”ฑใ€ไธญ้—ดไปถๅ’ŒๅŽ็ซฏๆœๅŠก
+- `[variants]` - ๅค„็†ไธๅŒๅนณๅฐๅ˜ไฝ“ๅ’Œไธปๅบ”็”จ้กต้ข็š„ๅŠจๆ€่ทฏ็”ฑ็ป„
+- `@modal` - ไฝฟ็”จ Next.js ๅนถ่กŒ่ทฏ็”ฑ็š„ๆจกๆ€ๆก†ๅฏน่ฏๆก†ๅนถ่กŒ่ทฏ็”ฑ
+
+**ๅนณๅฐ็ป„็ป‡๏ผš**
+- ๆžถๆž„้€š่ฟ‡่ทฏ็”ฑ็ป„็ป‡ๆ”ฏๆŒๅคšไธชๅนณๅฐ๏ผˆWebใ€ๆกŒ้ข็ซฏใ€็งปๅŠจ็ซฏ๏ผ‰
+- ๆกŒ้ข็ซฏไธ“็”จ่ทฏ็”ฑไฝไบŽ `desktop/` ็›ฎๅฝ•ไธญ
+- ็งปๅŠจ็ซฏไธ“็”จ่ทฏ็”ฑ็ป„็ป‡ๅœจ `(main)/(mobile)/` ไธ‹
+- ๅ…ฑไบซๅธƒๅฑ€ๅ’Œ็ป„ไปถไฝไบŽ `_layout/` ็›ฎๅฝ•ไธญ
+
+**API ๆžถๆž„๏ผš**
+- `(backend)/api/` ๅ’Œ `(backend)/webapi/` ไธญ็š„ REST API
+- ๆŒ‰่ฟ่กŒๆ—ถ็Žฏๅขƒ็ป„็ป‡็š„ tRPC ็ซฏ็‚น๏ผˆedgeใ€lambdaใ€asyncใ€desktop๏ผ‰
+- ไธ“็”จ่ทฏ็”ฑ็ป„ไธญ็š„่บซไปฝ้ชŒ่ฏๅ’Œ OIDC ๅค„็†
+
+่ฟ™็งๆžถๆž„ๅœจไฟๆŒไธๅŒ้ƒจ็ฝฒ็›ฎๆ ‡ๅ’Œ่ฟ่กŒๆ—ถ็Žฏๅขƒ็ตๆดปๆ€ง็š„ๅŒๆ—ถ๏ผŒๆไพ›ไบ†ๆธ…ๆ™ฐ็š„ๅ…ณๆณจ็‚นๅˆ†็ฆปใ€‚