🤯 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(dev): clarify feature organization patterns in tutorial (#9608)
Daniel Hofheinz7ce0d1fbc409
diff --git a/docs/development/basic/feature-development-frontend.mdx b/docs/development/basic/feature-development-frontend.mdxindex 98e9df630ab..6672707bca2 100644--- a/docs/development/basic/feature-development-frontend.mdx+++ b/docs/development/basic/feature-development-frontend.mdx@@ -5,7 +5,9 @@ LobeChat is built on the Next.js framework and uses TypeScript as the primary de1. Routing: Define routes (`src/app`).2. Data Structure: Define data structures (`src/types`).3. Business Logic Implementation: Zustand store (`src/store`).-4. Page Display: Write static components/pages (`src/app/<new-page>/features/<new-feature>.tsx`).+4. Page Display: Write static components/pages. Create features in:+ - `src/features/<feature-name>/` for **shared global features** (used across multiple pages)+ - `src/app/<new-page>/features/<feature-name>/` for **page-specific features** (only used in this page)5. Function Binding: Bind the store with page triggers (`const [state, function] = useNewStore(s => [s.state, s.function])`).Taking the "Chat Messages" feature as an example, here are the brief steps to implement this feature:@@ -60,7 +62,8 @@ export const useChatStore = create<ChatState>((set) => ({In `src/app/<new-page>/features/<new-feature>.tsx`, we need to create a new page or component to display "Chat Messages". In this file, we can use the Zustand Store created earlier and Ant Design components to build the UI:```jsx-// src/features/chat/index.tsx+// src/app/chat/features/ChatPage/index.tsx+// Note: Use src/app/<page>/features/ for page-specific componentsimport { List, Typography } from 'antd';import { useChatStore } from 'src/store/chatStore';@@ -82,6 +85,12 @@ const ChatPage = () => {export default ChatPage;```+> **Note on Feature Organization**: LobeChat uses two patterns for organizing features:+> - **Global features** (`src/features/`): Shared components like `ChatInput`, `Conversation` used across the app+> - **Page-specific features** (`src/app/<page>/features/`): Components used only within a specific page route+>+> Choose based on reusability. If unsure, start with page-specific and refactor to global if needed elsewhere.+## 5. Function BindingIn a page or component, we need to bind the Zustand Store's state and methods to the UI. In the example above, we have already bound the `messages` state to the `dataSource` property of the list. Now, we also need a method to add new messages. We can define this method in the Zustand Store and then use it in the page or component:diff --git a/docs/development/basic/feature-development-frontend.zh-CN.mdx b/docs/development/basic/feature-development-frontend.zh-CN.mdxindex f51a6a5a8d2..a36d3c43774 100644--- a/docs/development/basic/feature-development-frontend.zh-CN.mdx+++ b/docs/development/basic/feature-development-frontend.zh-CN.mdx@@ -5,7 +5,9 @@ LobeChat 基于 Next.js 框架构建,使用 TypeScript 作为主要开发语1. 路由:定义路由 (`src/app`)2. 数据结构: 定义数据结构 ( `src/types` )3. 业务功能实现: zustand store (`src/store`)-4. 页面展示:书写静态组件 / 页面 (`src/app/<new-page>/features/<new-feature>.tsx`)+4. 页面展示:书写静态组件 / 页面。根据以下方式创建功能组件:+ - `src/features/<feature-name>/` 用于 **全局共享功能**(跨多个页面使用)+ - `src/app/<new-page>/features/<feature-name>/` 用于 **页面专属功能**(仅在当前页面使用)5. 功能绑定:绑定 store 与页面的触发 (`const [state,function]= useNewStore(s=>[s.state,s.function])`)我们以 "会话消息" 功能为例,以下是实现这个功能的简要步骤:@@ -60,7 +62,8 @@ export const useChatStore = create<ChatState>((set) => ({在 `src/app/<new-page>/features/<new-feature>.tsx` 中,我们需要创建一个新的页面或组件来显示 "会话消息"。在这个文件中,我们可以使用上面创建的 Zustand Store,以及 Ant Design 的组件来构建 UI:```jsx-// src/features/chat/index.tsx+// src/app/chat/features/ChatPage/index.tsx+// 注意:使用 src/app/<page>/features/ 放置页面专属组件import { List, Typography } from 'antd';import { useChatStore } from 'src/store/chatStore';@@ -82,6 +85,12 @@ const ChatPage = () => {export default ChatPage;```+> **关于功能组件组织方式的说明**:LobeChat 使用两种模式来组织功能组件:+> - **全局功能**(`src/features/`):跨应用共享的组件,如 `ChatInput`、`Conversation` 等+> - **页面专属功能**(`src/app/<page>/features/`):仅在特定页面路由中使用的组件+>+> 根据可复用性选择合适的方式。如果不确定,可以先放在页面专属位置,需要时再重构为全局共享。+## 5. 功能绑定在页面或组件中,我们需要将 Zustand Store 的状态和方法绑定到 UI 上。在上面的示例中,我们已经将 `messages` 状态绑定到了列表的 `dataSource` 属性上。现在,我们还需要一个方法来添加新的消息。我们可以在 Zustand Store 中定义这个方法,然后在页面或组件中使用它: