Skip to content

Commit 4e85ae9

Browse files
committed
feat: 添加插件架构文档,更新 Manifest 和元数据结构,支持平台扩展注册
1 parent 429853f commit 4e85ae9

File tree

9 files changed

+137
-3
lines changed

9 files changed

+137
-3
lines changed

.cursorrules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You define what a "Package" looks like in ObjectStack.
1414
* type: app | plugin | driver | module.
1515
* permissions: Array of permission strings requested (e.g., ["system.user.read"]).
1616
* navigation: Structured navigation menu tree (for apps).
17+
* contributes: Register platform extensions (kind, etc).
1718
* entities: Glob patterns for ObjectQL files (e.g., ["./src/schema/*.gql"]).
1819
* extensions: Extension points (e.g., contributions to the UI).
1920
2. Directory Conventions (Law of Location)

.cursorrules.d/objectstack.prompt.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ File: objectstack.config.ts (or strict JSON inside package.json)
5353
Schema Location: packages/protocol/schemas/manifest.schema.json
5454
Key Fields:
5555
* type: app | plugin | driver
56-
* menus: Array of navigation items to inject into the OS sidebar.
56+
* navigation: Structured navigation menu tree.
57+
* contributes: Register platform extensions (e.g., custom kinds).
5758
* permissions: Array of requested capabilities (e.g., finance.read).
5859
* entities: Path patterns to auto-load Schema files (e.g., ./src/schemas/*.gql).
5960
* lifecycle: Hooks for onInstall, onEnable.

content/docs/concepts/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"manifesto",
66
"core-values",
77
"architecture",
8+
"plugin-architecture",
89
"security_architecture",
910
"enterprise-patterns",
1011
"ai-codex",
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: Plugin Architecture
3+
description: The Extension Model and Microkernel Philosophy of ObjectStack.
4+
---
5+
6+
# Plugin Architecture
7+
8+
ObjectStack follows a strict **Microkernel Architecture**. The core platform provides only the minimal runtime environment (Kernel), while all business capabilities, including standard ones like CRM or Project Management, are delivered as **Packages** (Apps or Plugins).
9+
10+
## 1. Philosophy: "Kernel + Plugins"
11+
12+
* **The Kernel**: Responsible for booting, identity, permission enforcement, and loading the manifest. It knows *nothing* about "Leads", "Tasks", or even "Kanban Boards" initially.
13+
* **The Plugins**: Teach the Kernel new tricks.
14+
* **Apps**: Combinations of data and UI for end-users (e.g., "Sales App").
15+
* **Plugins**: Extensions to the system capabilities (e.g., "BI Engine", "SAML Auth", "Stripe Payment").
16+
17+
This separation ensures the platform remains lightweight and un-opinionated, allowing it to evolve indefinitely.
18+
19+
## 2. Anatomy of a Plugin
20+
21+
A plugin is defined by its `Manifest` (objectstack.config.ts). The most critical part of a modern ObjectStack plugin is the `contributes` section.
22+
23+
### The `contributes` Protocol
24+
25+
Inspired by VS Code, we use a declarative approach to register capabilities.
26+
27+
```typescript
28+
// objectstack.config.ts
29+
export default {
30+
id: 'com.vendor.bi',
31+
type: 'plugin',
32+
33+
// DECLARATIVE: "I bring these new capabilities"
34+
contributes: {
35+
// 1. Define new Metadata Kinds (File Types)
36+
kinds: [
37+
{
38+
id: 'bi.dataset',
39+
globs: ['**/*.dataset.json'],
40+
description: 'BI Dataset Definition'
41+
}
42+
],
43+
// 2. Define new UI Locations
44+
views: [
45+
{
46+
id: 'bi.chart_renderer',
47+
location: 'dashboard.widget'
48+
}
49+
]
50+
},
51+
52+
// IMPERATIVE: "Here is the code to handle them"
53+
lifecycle: './src/index.ts'
54+
}
55+
```
56+
57+
## 3. Extension Capabilities
58+
59+
### A. New Metadata Kinds (CRDs)
60+
61+
This is the most powerful feature. A plugin can introduce entirely new concepts to the platform.
62+
63+
* **Example**: A "BI Plugin" introduces `*.dataset.json` and `*.report.json`.
64+
* **Mechanism**: The Kernel uses the `contributes.kinds` registry to map file extensions to the plugin's parser.
65+
* **Result**: The IDE (cursor/vscode) and Runtime automatically recognize these files.
66+
67+
### B. Service Providers
68+
69+
Plugins can implement standard interfaces defined by the system.
70+
71+
* **Auth Providers**: `plugin extends AuthProvider` (SAML, OAuth).
72+
* **Storage Drivers**: `plugin extends StorageDriver` (S3, MinIO).
73+
* **Notification Channels**: `plugin extends NotificationChannel` (Slack, SMS).
74+
75+
## 4. Plugin Lifecycle
76+
77+
The runtime manages the plugin states:
78+
79+
1. **Resolve**: Read Manifest, validate dependencies.
80+
2. **Install (`onInstall`)**: Run migration scripts, setup initial data.
81+
3. **Boot (`onBoot`)**: Register generic services (before App load).
82+
4. **Enable (`onEnable`)**: Active and serving traffic.
83+
84+
```typescript
85+
export class BiPlugin implements PluginLifecycle {
86+
async onEnable(context: PluginContext) {
87+
// Register the heavy engine only when enabled
88+
context.services.register('bi.engine', new BiAnalysisEngine());
89+
}
90+
}
91+
```

content/docs/references/system/config/Manifest.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ description: Manifest Schema Reference
1313
| **name** | `string` || Human-readable package name |
1414
| **description** | `string` | optional | Package description |
1515
| **permissions** | `string[]` | optional | Array of required permission strings |
16-
| **menus** | `object[]` | optional | Navigation menu structure |
1716
| **objects** | `string[]` | optional | Glob patterns for ObjectQL schemas files |
17+
| **contributes** | `object` | optional | Platform contributions (e.g. kinds) |
1818
| **extensions** | `Record<string, any>` | optional | Extension points and contributions |

content/prompts/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ title: Documentation
3939
* **[ ] 4. 插件清单协议 (`ManifestSchema`)**
4040
* **定义目标**: 描述一个软件包(插件/应用)。
4141
* **文件对应**: `objectstack.config.ts``package.json > objectstack`
42-
* **关键字段**: `id`, `version`, `type` (app/plugin/driver), `permissions` (申请权限), `menus` (导航注入)。
42+
* **关键字段**: `id`, `version`, `type`, `contributes` (注册能力), `permissions` (权限)。
4343
* **用途**: CLI 打包校验,应用商店展示。
4444

4545

content/prompts/objectstack.prompt.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Schema Location: packages/protocol/schemas/manifest.schema.json
5454
Key Fields:
5555
* type: app | plugin | driver
5656
* navigation: Structured navigation menu tree.
57+
* contributes: Register platform extensions (e.g., custom kinds).
5758
* permissions: Array of requested capabilities (e.g., finance.read).
5859
* entities: Path patterns to auto-load Schema files (e.g., ./src/schemas/*.gql).
5960
* lifecycle: Hooks for onInstall, onEnable.

packages/spec/src/system/manifest.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,29 @@ describe('ManifestSchema', () => {
196196
expect(() => ManifestSchema.parse(crmManifest)).not.toThrow();
197197
});
198198

199+
it('should accept bi plugin with custom kinds', () => {
200+
const biPlugin: ObjectStackManifest = {
201+
id: 'com.objectstack.bi',
202+
version: '1.0.0',
203+
type: 'plugin',
204+
name: 'Business Intelligence',
205+
contributes: {
206+
kinds: [
207+
{
208+
id: 'bi.dataset',
209+
globs: ['**/*.dataset.json']
210+
},
211+
{
212+
id: 'bi.dashboard',
213+
globs: ['**/*.bi-dash.json']
214+
}
215+
]
216+
}
217+
};
218+
219+
expect(() => ManifestSchema.parse(biPlugin)).not.toThrow();
220+
});
221+
199222
it('should accept authentication plugin manifest', () => {
200223
const authPlugin: ObjectStackManifest = {
201224
id: 'com.objectstack.auth.saml',

packages/spec/src/system/manifest.zod.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ export const ManifestSchema = z.object({
4949
*/
5050
objects: z.array(z.string()).optional().describe('Glob patterns for ObjectQL schemas files'),
5151

52+
/**
53+
* Contribution Points (VS Code Style).
54+
* formalized way to extend the platform capabilities.
55+
*/
56+
contributes: z.object({
57+
/**
58+
* Register new Metadata Kinds (CRDs).
59+
* Enables the system to parse and validate new file types.
60+
* Example: Registering a BI plugin to handle *.report.ts
61+
*/
62+
kinds: z.array(z.object({
63+
id: z.string().describe('The generic identifier of the kind (e.g., "sys.bi.report")'),
64+
globs: z.array(z.string()).describe('File patterns to watch (e.g., ["**/*.report.ts"])'),
65+
})).optional(),
66+
}).optional().describe('Platform contributions'),
67+
5268
/**
5369
* Extension points contributed by this package.
5470
* Allows packages to extend UI components, add functionality, etc.

0 commit comments

Comments
 (0)