๐คฏ 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
๐ docs: update app directory structure documentation (#9582)
Arvin Xuc83d7afbe6b4
diff --git a/docs/development/basic/folder-structure.mdx b/docs/development/basic/folder-structure.mdxindex 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:```bashsrc-โโโ 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.mdxindex 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 ็ๆไปถๅคน็ฎๅฝๆถๆๅฆไธ๏ผ```bashsrc-โโโ 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 ๅค็++่ฟ็งๆถๆๅจไฟๆไธๅ้จ็ฝฒ็ฎๆ ๅ่ฟ่กๆถ็ฏๅข็ตๆดปๆง็ๅๆถ๏ผๆไพไบๆธ ๆฐ็ๅ ณๆณจ็นๅ็ฆปใ