nocobase-plugin-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGoal
目标
Guide an AI agent through the complete process of developing a NocoBase plugin — from requirement analysis to working code — producing a plugin that follows NocoBase conventions and can be enabled immediately.
引导AI Agent完成NocoBase插件的完整开发流程——从需求分析到可运行代码——产出符合NocoBase约定、可立即启用的插件。
Scope
适用范围
- Analyze user requirements and map them to NocoBase extension points.
- Scaffold a new plugin with .
yarn pm create - Generate server-side code: collections, ACL, custom APIs, migrations, install hooks.
- Generate client-side code: blocks, fields, actions, settings pages, routes.
- Generate i18n locale files.
- Enable and verify the plugin.
- Troubleshoot common issues using FAQ checklist and source code (when available).
- 分析用户需求并映射到NocoBase扩展点。
- 使用搭建新插件脚手架。
yarn pm create - 生成服务端代码:集合、ACL、自定义API、迁移脚本、安装钩子。
- 生成客户端代码:区块、字段、操作、设置页面、路由。
- 生成国际化(i18n)语言包文件。
- 启用并验证插件。
- 使用FAQ清单和源码(若可用)排查常见问题。
Non-Goals
不适用范围
- Do not build NocoBase applications through the UI (that's ).
nocobase-ui-builder - Do not handle plugin publishing to external registries.
- Do not modify NocoBase core code.
- Do not migrate existing plugins from client v1 to v2 (that's ).
nocobase-client-v2-plugin-migration
- 不通过UI构建NocoBase应用(该场景请使用)。
nocobase-ui-builder - 不处理插件发布到外部注册表的操作。
- 不修改NocoBase核心代码。
- 不处理现有插件从客户端v1到v2的迁移(该场景请使用)。
nocobase-client-v2-plugin-migration
Hard Constraints
硬性约束
These rules apply to ALL generated plugin code. Violating them is always wrong.
以下规则适用于所有生成的插件代码,违反规则即视为错误。
NEVER use this.app.use()
or React Providers
this.app.use()严禁使用this.app.use()
或React Providers
this.app.use()this.app.use()Providers add unnecessary React rendering layers, hurt performance, and make plugins harder to maintain. When implementing global effects (watermarks, overlays, theming, tracking, global listeners, etc.), use these approaches instead:
- FlowEngine mechanisms (preferred) — ,
registerModelLoaders,registerFlowfor UI capabilities.registerModels - FlowEngine context — holds global data (e.g.,
this.context,this.context.api,this.context.dataSourceManager). Read from it directly instead of creating Providers to pass data around. Note: some properties likethis.context.logger,user,viewer,messageare only available after React renders — use them in flow handlers or components, not inthemeToken.load() - API requests — if the plugin needs data, use to fetch it directly. Axios interceptors are allowed but should not be the first choice — prefer direct requests or reading from context when possible.
this.app.apiClient.request() - Pure DOM manipulation — operate on the DOM directly in for visual effects. No React component needed.
load() - EventBus — for reacting to app lifecycle events.
this.app.eventBus
If you find yourself thinking "I need a Provider for this", stop and reconsider. There is always a better alternative.
this.app.use()Providers会增加不必要的React渲染层,影响性能,且会提高插件维护难度。实现全局效果(水印、浮层、主题、追踪、全局监听器等)时,请改用以下方式:
- FlowEngine机制(首选)——使用、
registerModelLoaders、registerFlow实现UI能力。registerModels - FlowEngine上下文——包含全局数据(如
this.context、this.context.api、this.context.dataSourceManager)。直接从中读取数据,而非创建Providers传递数据。注意:部分属性如this.context.logger、user、viewer、message仅在React渲染后可用——请在流处理器或组件中使用,不要在themeToken中使用。load() - API请求——若插件需要数据,直接使用获取。允许使用Axios拦截器,但不应作为首选——优先选择直接请求或从上下文读取数据。
this.app.apiClient.request() - 纯DOM操作——在中直接操作DOM实现视觉效果,无需React组件。
load() - EventBus——使用响应应用生命周期事件。
this.app.eventBus
如果你在想“我需要用Provider来实现这个”,请停下来重新考虑。总有更好的替代方案。
Client code goes in client-v2
ONLY
client-v2客户端代码仅允许放在client-v2
目录
client-v2All client-side plugin code must be written in . The directory is for the legacy v1 client — do NOT write or modify any files there. Import from , never from .
src/client-v2/src/client/Plugin@nocobase/client-v2@nocobase/client所有客户端插件代码必须写在目录下。目录用于遗留v1客户端——请勿在该目录下编写或修改任何文件。从导入,绝对不要从导入。
src/client-v2/src/client/@nocobase/client-v2Plugin@nocobase/clientInput Contract
输入约定
| Input | Required | Default | Validation | Clarification Question |
|---|---|---|---|---|
| yes | none | non-empty natural language description | "What should this plugin do?" |
| yes | current working directory | must contain | "Where is your NocoBase project root directory?" |
| no | derived from requirement | | "What should the plugin package name be?" |
Rules:
- If is not provided, check if the current working directory is a NocoBase project.
nocobase_root - If is not provided, derive a reasonable name from the requirement and confirm with the user.
plugin_name - If user says "you decide", use documented defaults.
| 输入项 | 是否必填 | 默认值 | 验证规则 | 澄清问题 |
|---|---|---|---|---|
| 是 | 无 | 非空自然语言描述 | “该插件需要实现什么功能?” |
| 是 | 当前工作目录 | 必须包含带有 | “你的NocoBase项目根目录在哪里?” |
| 否 | 从需求推导 | 格式为 | “插件包名称应该是什么?” |
规则:
- 若未提供,检查当前工作目录是否为NocoBase项目。
nocobase_root - 若未提供,从需求中推导合理名称并与用户确认。
plugin_name - 若用户表示“由你决定”,使用文档中规定的默认值。
Mandatory Clarification Gate
强制澄清环节
- Max clarification rounds:
2 - Max questions per round:
3 - Mutation preconditions:
- is a valid NocoBase project with
nocobase_rootavailable.yarn - is clear enough to determine which extension points are needed.
requirement - Functional plan has been confirmed by the user in plain language.
- If preconditions are not met after two rounds, stop and report what's missing.
CRITICAL: You MUST always confirm the plan with the user before writing any code or running any scaffold command — even if the requirement seems perfectly clear. Users often have unstated assumptions, edge cases they haven't considered, or preferences about scope. The plan confirmation step (Step 2) is a hard gate, not a suggestion. Never skip it.
- 最大澄清轮次:
2 - 每轮最多提问数:
3 - 前置条件:
- 是有效的NocoBase项目且可用
nocobase_root。yarn - 足够清晰,可确定所需的扩展点。
requirement - 功能方案已通过用户用自然语言确认。
- 若两轮后仍未满足前置条件,停止操作并告知缺失的内容。
重要提示:在编写任何代码或运行任何脚手架命令之前,必须与用户确认方案——即使需求看起来非常清晰。 用户通常会有未说明的假设、未考虑到的边缘情况,或对范围的偏好。方案确认步骤(步骤2)是硬性关卡,而非建议。绝不能跳过。
Workflow
工作流程
Step 0: Environment Check
步骤0:环境检查
- Verify contains a valid NocoBase project (
nocobase_rootwithpackage.json).@nocobase/server - Verify is available.
yarn - Detect environment type:
- Source install: exists → AI can read source code for troubleshooting.
packages/core/ - create-nocobase-app: no → rely on documentation and online references only.
packages/core/
- Source install:
- 验证包含有效的NocoBase项目(带有
nocobase_root的@nocobase/server)。package.json - 验证可用。
yarn - 检测环境类型:
- 源码安装:存在目录 → AI可读取源码进行故障排查。
packages/core/ - create-nocobase-app安装:无目录 → 仅依赖文档和在线参考资料。
packages/core/
- 源码安装:存在
Step 1: Requirement Analysis
步骤1:需求分析
Analyze the user's requirement and determine which extension points are needed:
- Server-side: collections, custom REST APIs, ACL, cron jobs, migrations, event listeners
- Client-side: blocks (BlockModel/TableBlockModel), fields (FieldModel), actions (ActionModel), settings pages, routes
- Both: full-stack plugins with server data + client UI
Do NOT ask the user about technical details (e.g., "Do you need a BlockModel or TableBlockModel?"). Map requirements to extension points internally.
分析用户需求并确定所需的扩展点:
- 服务端:集合、自定义REST API、ACL、定时任务、迁移脚本、事件监听器
- 客户端:区块(BlockModel/TableBlockModel)、字段(FieldModel)、操作(ActionModel)、设置页面、路由
- 全栈:包含服务端数据+客户端UI的全栈插件
请勿询问用户技术细节(如“你需要BlockModel还是TableBlockModel?”)。内部将需求映射到扩展点即可。
Step 2: Plan Confirmation (HARD GATE)
步骤2:方案确认(硬性关卡)
This step is mandatory and must not be skipped, regardless of how clear the requirement appears. Even seemingly straightforward requirements can have unstated edge cases, scope preferences, or assumptions the user hasn't mentioned. Always present the plan and wait for explicit confirmation before proceeding to Step 3.
Present a functional plan in plain language the user can understand. Proactively highlight decisions the user may not have considered (e.g., "Should the data persist after plugin disable?", "Do you need a settings page for configuration?"). Example:
"Here's my plan:
- Create a settings page where you can configure the API key
- Add a scheduled task that syncs data every 5 minutes
- Create a data table to store the synced records
- The table will be available as a block in the UI
A few things to confirm:
- Should the synced data be cleared when the plugin is disabled?
- Do you need permission control for who can access the settings?
Does this look right?"
Do NOT run or write any code until the user explicitly confirms.
yarn pm create此步骤为强制要求,无论需求看起来多么清晰,都不能跳过。 即使看似简单的需求也可能存在未说明的边缘情况、范围偏好或用户未提及的假设。在进入步骤3之前,必须始终呈现方案并等待用户明确确认。
用用户能理解的自然语言呈现功能方案。主动指出用户可能未考虑到的决策(如“插件禁用后数据是否需要保留?”、“是否需要设置页面用于配置?”)。示例:
“我的方案如下:
- 创建一个可配置API密钥的设置页面
- 添加一个每5分钟同步数据的定时任务
- 创建一个数据表存储同步的记录
- 该数据表将作为区块在UI中可用
需要确认几点:
- 插件禁用后,同步的数据是否需要清除?
- 是否需要权限控制来限制谁可以访问设置页面?
这个方案是否符合你的需求?”
在用户明确确认之前,请勿运行或编写任何代码。
yarn pm createStep 3: Scaffold Plugin
步骤3:搭建插件脚手架
The exact command is:
bash
yarn pm create <plugin_name>正确命令如下:
bash
yarn pm create <plugin_name>Example: yarn pm create @nocobase-sample/plugin-hello
示例:yarn pm create @nocobase-sample/plugin-hello
Creates: packages/plugins/@nocobase-sample/plugin-hello/
创建目录: packages/plugins/@nocobase-sample/plugin-hello/
This is the only correct command. Do NOT use `create-plugin`, `generate`, or any other variant. Do NOT look up alternatives — just run it.
Read `references/getting-started.md` for the expected project structure.
这是唯一正确的命令。请勿使用`create-plugin`、`generate`或任何其他变体。请勿查找替代方案——直接运行该命令即可。
阅读`references/getting-started.md`了解预期的项目结构。Step 4: Generate Code (MUST Read References First)
步骤4:生成代码(必须先阅读参考文档)
You MUST read the relevant reference files BEFORE writing any code. Do NOT skip this by searching source code, reading examples, or relying on prior knowledge. The references contain project-specific conventions that override general knowledge.
Read to locate the relevant reference files, then read the ones needed for this plugin.
references/index.md在编写任何代码之前,必须先阅读相关参考文件。 请勿通过搜索源码、查看示例或依赖已有知识跳过此步骤。参考文档包含项目专属约定,优先级高于通用知识。
阅读定位相关参考文件,然后阅读当前插件所需的文件。
references/index.mdMandatory Reference Rules
强制参考规则
These are hard gates, not suggestions. Read the file BEFORE editing the corresponding code:
| When you edit... | You MUST first read |
|---|---|
| |
| |
Any file in | |
Any file in | |
这些是硬性关卡,而非建议。编辑对应代码之前必须先阅读指定文件:
| 当你编辑... | 必须先阅读 |
|---|---|
| |
| |
| |
| |
Keyword-Triggered References
关键字触发的参考文档
If your implementation involves any of these concepts, you MUST also read the corresponding reference:
| Keywords in your code | MUST read |
|---|---|
| |
| |
| |
| |
| |
| |
| |
如果你的实现涉及以下概念,还必须阅读对应的参考文档:
| 代码中的关键字 | 必须阅读 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
Generation Order
生成顺序
Flexible — adapt to the plugin's needs:
- Server-first when the plugin has data tables and APIs.
- Client-first when the plugin is purely frontend.
- Interleaved when both sides are tightly coupled.
Checkpoint before writing client code: Review the "Hard Constraints" section. Never use or Providers. Use FlowEngine, context, pure DOM, or EventBus instead.
this.app.use()灵活调整——适配插件需求:
- 若插件包含数据表和API,优先开发服务端。
- 若插件纯前端,优先开发客户端。
- 若前后端紧密耦合,可交替开发。
编写客户端代码前的检查点:回顾“硬性约束”部分。绝不使用或Providers。改用FlowEngine、上下文、纯DOM或EventBus。
this.app.use()Step 5: Internationalization
步骤5:国际化
Default behavior (do NOT ask):
- Always generate and
src/locale/zh-CN.json.src/locale/en-US.json - Use the plugin's auto-generated for
locale.tsandtExprimports.useT
Only ask about additional languages if:
- The user explicitly mentions other languages, OR
- The user is communicating in a language other than Chinese or English.
默认行为(无需询问):
- 始终生成和
src/locale/zh-CN.json文件。src/locale/en-US.json - 使用插件自动生成的导入
locale.ts和tExpr。useT
仅在以下情况询问是否需要额外语言:
- 用户明确提及其他语言,或
- 用户使用中文或英文以外的语言沟通。
Step 6: Enable and Verify
步骤6:启用并验证
bash
yarn pm enable <plugin_name>After enabling, describe what the user should see in the UI and how to test the plugin.
bash
yarn pm enable <plugin_name>启用后,告知用户在UI中应看到的内容以及如何测试插件。
Default Behaviors
默认行为
These defaults apply unless the user explicitly requests otherwise. Do NOT ask about them.
| Decision | Default | When to ask |
|---|---|---|
| Client version | | Never |
| Model registration | | Never |
| Route registration | | Never |
| Settings page registration | | Never |
| ACL | | User mentions fine-grained permissions |
| Locale files | | User mentions other languages |
| Do NOT add — recommend UI "Data Source Management" instead | Only as a demo; if needed, use |
| Do NOT add | User mentions preset/demo data |
| From plugin's | Never |
| Do NOT use — use FlowEngine mechanisms or pure DOM instead. See | Never |
以下默认行为适用于用户未明确要求的情况。无需询问。
| 决策 | 默认值 | 询问时机 |
|---|---|---|
| 客户端版本 | 仅使用 | 绝不 |
| 模型注册 | 使用 | 绝不 |
| 路由注册 | 使用 | 绝不 |
| 设置页面注册 | 使用 | 绝不 |
| ACL | 使用 | 用户提及细粒度权限时 |
| 语言包文件 | | 用户提及其他语言时 |
| 不添加——推荐使用UI“数据源管理”功能 | 仅用于演示;若确实需要,使用 |
| 不添加 | 用户提及预设/演示数据时 |
| 从插件的 | 绝不 |
| 不使用——改用FlowEngine机制或纯DOM操作。详见 | 绝不 |
Troubleshooting
故障排查
When the plugin doesn't work as expected:
当插件未按预期工作时:
FAQ Checklist
FAQ清单
- Plugin not appearing in plugin manager → Check has correct NocoBase metadata. Run
package.json.yarn pm enable <name> - Collection not showing in block picker → Recommend user to add the table via NocoBase UI "Data Source Management". If code-level registration is needed (demo only), use with
addCollectionandfilterTargetKey: 'id'pattern. SeeeventBus.client/plugin.md - Settings page shows blank → Verify using (not
componentLoader) for client-v2.Component - Model not appearing in menus → Check and
define({ label: tExpr('...') })in pluginregisterModelLoaders.load() - database query fails →
load()runs before DB sync. Move DB operations toload()or request handlers.install() - i18n not working → First-time locale files require app restart. Check is imported from
tExprnotlocale.ts.@nocobase/flow-engine - registerFlow handler not firing → Check event name. Use
onfor buttons,'click'for initialization.'beforeRender'
- 插件未出现在插件管理器中 → 检查是否包含正确的NocoBase元数据。运行
package.json。yarn pm enable <name> - 集合未出现在区块选择器中 → 建议用户通过NocoBase UI“数据源管理”添加数据表。若需要代码级注册(仅用于演示),使用并搭配
addCollection和filterTargetKey: 'id'模式。详见eventBus。client/plugin.md - 设置页面显示空白 → 验证客户端v2是否使用(而非
componentLoader)。Component - 模型未出现在菜单中 → 检查以及插件
define({ label: tExpr('...') })中的load()。registerModelLoaders - 数据库查询失败 →
load()在数据库同步前运行。将数据库操作移至load()或请求处理器中。install() - 国际化不生效 → 首次添加语言包文件需要重启应用。检查是否从
tExpr导入,而非locale.ts。@nocobase/flow-engine - registerFlow处理器未触发 → 检查事件名称。按钮使用
on,初始化使用'click'。'beforeRender'
Source Code Debugging (Source Install Only)
源码调试(仅源码安装环境)
If the environment is a source install, the AI agent may read NocoBase core source code to debug issues:
packages/core/server/src/ — Server core
packages/core/client/src/ — Client core (v1, reference only)
packages/core/client-v2/src/ — Client core (v2, recommended)
packages/core/database/src/ — Database layer
packages/core/flow-engine/src/ — FlowEngine若环境为源码安装,AI Agent可读取NocoBase核心源码排查问题:
packages/core/server/src/ — 服务端核心
packages/core/client/src/ — 客户端核心(v1,仅作参考)
packages/core/client-v2/src/ — 客户端核心(v2,推荐)
packages/core/database/src/ — 数据库层
packages/core/flow-engine/src/ — FlowEngineComplete Example Plugins
完整示例插件
When a full working example is needed:
- Source install: Read for working example plugins.
packages/plugins/@nocobase-example/ - Non-source install: Browse https://github.com/nocobase/nocobase/tree/develop/packages/plugins/%40nocobase-example/
当需要完整的可运行示例时:
- 源码安装:阅读目录下的可运行示例插件。
packages/plugins/@nocobase-example/ - 非源码安装:浏览https://github.com/nocobase/nocobase/tree/develop/packages/plugins/%40nocobase-example/
Reference Loading Map
参考文档加载映射
| Reference | Use When | Notes |
|---|---|---|
| references/index.md | Always, after Step 1 | Global index — read this to find relevant module references |
| references/getting-started.md | Step 3 (scaffolding) | Plugin scaffold + project structure |
| references/server/*.md | Plugin needs server-side code | One file per server module |
| references/client/*.md | Plugin needs client-side code | One file per client module |
| references/build.md | User asks about building/packaging | Build and distribution |
| 参考文档 | 使用时机 | 说明 |
|---|---|---|
| references/index.md | 步骤1之后,始终使用 | 全局索引——阅读此文档查找相关模块参考 |
| references/getting-started.md | 步骤3(搭建脚手架) | 插件脚手架+项目结构 |
| references/server/*.md | 插件需要服务端代码时 | 每个服务端模块对应一个文件 |
| references/client/*.md | 插件需要客户端代码时 | 每个客户端模块对应一个文件 |
| references/build.md | 用户询问构建/打包相关问题时 | 构建与分发 |
Safety Gate
安全关卡
High-impact actions:
- Running (creates files in user's project)
yarn pm create - Running (modifies database state)
yarn pm enable - Modifying existing plugin files (if plugin already exists)
Secondary confirmation template:
- "I'm about to run in
{{command}}. This will {{impact}}. Should I proceed?"{{directory}}
Rollback guidance:
- If produced wrong scaffold → delete the generated directory and re-run.
yarn pm create - If plugin code has bugs after enable → fix the code, the plugin can be disabled with .
yarn pm disable <name> - Never run without explicit user confirmation — it resets the database.
yarn nocobase install -f
高影响操作:
- 运行(在用户项目中创建文件)
yarn pm create - 运行(修改数据库状态)
yarn pm enable - 修改现有插件文件(若插件已存在)
二次确认模板:
- “我将在目录下运行
{{directory}},这会{{impact}}。是否继续?”{{command}}
回滚指南:
- 若生成了错误的脚手架 → 删除生成的目录并重新运行。
yarn pm create - 若启用后插件代码存在bug → 修复代码,可使用禁用插件。
yarn pm disable <name> - 未经用户明确确认,绝不运行——该命令会重置数据库。
yarn nocobase install -f
Verification Checklist
验证清单
- NocoBase project root is valid and is available.
yarn - Environment type (source vs create-nocobase-app) is detected.
- User requirement is analyzed and extension points are identified.
- Functional plan is confirmed by user before code generation.
- Plugin scaffold is created successfully.
- All generated files follow NocoBase conventions (client-v2, lazy loading, locale.ts).
- No or React Provider patterns in generated code (Hard Constraint).
this.app.use() - and
zh-CN.jsonare generated with all translatable strings.en-US.json - Plugin can be enabled with without errors.
yarn pm enable - Generated code matches the patterns in reference templates.
- FAQ checklist is consulted when issues arise.
- NocoBase项目根目录有效且可用。
yarn - 已检测环境类型(源码安装vs create-nocobase-app安装)。
- 已分析用户需求并确定扩展点。
- 功能方案已通过用户确认后才开始生成代码。
- 插件脚手架已成功创建。
- 所有生成文件符合NocoBase约定(client-v2、懒加载、locale.ts)。
- 生成代码中无或React Provider模式(硬性约束)。
this.app.use() - 已生成和
zh-CN.json,包含所有可翻译字符串。en-US.json - 插件可通过成功启用且无错误。
yarn pm enable - 生成代码与参考模板中的模式一致。
- 出现问题时已查阅FAQ清单。
Minimal Test Scenarios
最小测试场景
- User requests a simple settings page plugin → scaffold + server API + client settings page.
- User requests a custom block plugin → scaffold + BlockModel + registerFlow + i18n.
- User requests a full-stack CRUD plugin → scaffold + defineCollection + ACL + TableBlockModel + custom field + custom action.
- User provides vague requirement → clarification gate triggers, plan is confirmed before coding.
- Plugin enable fails → FAQ checklist is consulted, source code is read if available.
- 用户请求简单的设置页面插件 → 脚手架+服务端API+客户端设置页面。
- 用户请求自定义区块插件 → 脚手架+BlockModel+registerFlow+国际化。
- 用户请求全栈CRUD插件 → 脚手架+defineCollection+ACL+TableBlockModel+自定义字段+自定义操作。
- 用户提供模糊需求 → 触发澄清环节,编码前确认方案。
- 插件启用失败 → 查阅FAQ清单,若可用则读取源码。
Output Contract
输出约定
Final response must include:
- What was requested (user's original requirement).
- What was created (list of generated files).
- How to enable and test (commands + expected UI behavior).
- What assumptions/defaults were applied.
- Known limitations or next steps (if any).
最终响应必须包含:
- 用户的原始需求。
- 创建的内容(生成文件列表)。
- 启用和测试方法(命令+预期UI行为)。
- 应用的假设/默认值。
- 已知限制或后续步骤(若有)。
References
参考资料
- Reference Index: global index of all reference files.
- Getting Started: plugin scaffold and project structure.
- Online Docs — Plugin Development: full plugin development documentation. [verified: 2026-04-10]
- Online Docs — FlowEngine: FlowEngine complete reference. [verified: 2026-04-10]
- Example Plugins (GitHub): working example plugins. [verified: 2026-04-10]
- 参考索引:所有参考文件的全局索引。
- 快速开始:插件脚手架与项目结构。
- 在线文档——插件开发:完整的插件开发文档。[验证时间:2026-04-10]
- 在线文档——FlowEngine:FlowEngine完整参考。[验证时间:2026-04-10]
- 示例插件(GitHub):可运行的示例插件。[验证时间:2026-04-10]