Skip to content

Commit 7e56d8d

Browse files
committed
feat: Add security and system protocol schemas
- Introduced sharing.mdx for Organization-Wide Defaults and sharing rules. - Added territory.mdx for Territory Management Protocol and its schemas. - Created auth-config.mdx for Better-Auth Configuration Protocol. - Implemented metadata-persistence.mdx for Metadata Persistence protocol schemas. - Developed migration.mdx for Migration protocol schemas. - Established service-registry.mdx for Service Registry protocol schemas. - Launched worker.mdx for Worker System Protocol with task processing features.
1 parent 002bee7 commit 7e56d8d

File tree

111 files changed

+8250
-640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+8250
-640
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,3 @@ next-env.d.ts
7171
.source/
7272
apps/*/. source/
7373
apps/*/.next/docs/
74-
docs/

PLANNING.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# ObjectStack Project Master Plan & Status Report
2+
3+
**Date:** 2026-02-05
4+
**Version:** 1.0.0
5+
6+
## 1. Project Master Scheme (项目总体方案)
7+
8+
ObjectStack is designed as a **metadata-driven, post-SaaS operating system**. It virtualizes the application stack into strict Zod protocols, allowing business logic, UI, and data structures to be defined as code and executed by a universal runtime.
9+
10+
### 1.1 Architectural Layers
11+
12+
1. **Protocol Layer (`@objectstack/spec`)**
13+
* **Role:** The "DNA" of the system.
14+
* **Technology:** Pure TypeScript + Zod.
15+
* **Status:** **Complete**. Covers UI, Data, Security, Automation, AI, System.
16+
17+
2. **Kernel Layer (`@objectstack/core`)**
18+
* **Role:** The Microkernel. Handles plugin lifecycle, dependency injection, event bus, and logging.
19+
* **Status:** **Stable**.
20+
21+
3. **Engine Layer**
22+
* **ObjectQL (`@objectstack/objectql`)**: Universal data access abstraction.
23+
* **Runtime (`@objectstack/runtime`)**: The execution brain. Contains the `HttpDispatcher` which unifies request handling.
24+
* **Status:** **Stable (Memory-only)**.
25+
26+
4. **Interface Layer (Adapters & Plugins)**
27+
* **Server**: `@objectstack/plugin-hono-server` (Production HTTP), `@objectstack/adapter-nextjs` (Frontend Backend).
28+
* **Client**: `@objectstack/plugin-msw` (Browser Mocking), `@objectstack/client` (SDK).
29+
* **Status:** **Unified Architecture Implemented**.
30+
31+
5. **Infrastructure Layer (Drivers)**
32+
* **Data**: `driver-memory` (Dev/Test), `driver-sqlite` (Local), `driver-postgres` (Scale).
33+
* **Status:** **Partial** (Memory only).
34+
35+
---
36+
37+
## 2. Current Development Progress (当前开发进度)
38+
39+
### ✅ Completed Milestones
40+
41+
* **Protocol Definition:** All major protocols (UI, Data, API, security) are defined in Zod.
42+
* **Unified Dispatcher Architecture:**
43+
* Refactored `plugin-hono-server` to use `@objectstack/hono` factory.
44+
* Refactored `plugin-msw` to use shared `HttpDispatcher`.
45+
* **Result:** The mock server now behaves identically to the production server.
46+
* **CI/CD Stabilization:**
47+
* Fixed build and test pipelines for the monorepo.
48+
* Resolved integration test environment issues (skipping live-server tests in CI).
49+
* **Documentation:**
50+
* Updated `packages.mdx` with correct plugin architecture descriptions.
51+
52+
### 🚧 Works in Progress
53+
54+
* **Client SDK**: Basic structure exists, but needs stronger typing inference from Zod schemas.
55+
* **React Components**: `@objectstack/client-react` exists but is minimal.
56+
57+
---
58+
59+
## 3. Next Development Roadmap (下一步开发计划)
60+
61+
The immediate focus shifts from **Architecture/Kernel** stability to **Feature/Persistence** implementation.
62+
63+
### Phase 1: Persistence Strategy (Week 1-2)
64+
**Objective:** Move beyond in-memory data to persistent storage.
65+
1. **Create `@objectstack/driver-sqlite`**:
66+
* Implement `ObjectStackDriver` interface.
67+
* Target: `better-sqlite3` for fast local development.
68+
* Compliance: Pass the standard `driver-test-suite` (which runs on memory driver currently).
69+
2. **Create `@objectstack/driver-postgres`**:
70+
* Target: `pg` or `postgres.js`.
71+
* Support JSONB for flexible metadata storage.
72+
73+
### Phase 2: Metadata UI Engine (Week 3-4)
74+
**Objective:** Render UI directly from Zod Protocol definitions.
75+
1. **Enhance `@objectstack/client-react`**:
76+
* Implement `useObject(objectName)` hook.
77+
* Implement `useView(viewName)` hook.
78+
2. **Dynamic Form Builder**:
79+
* Create a component that takes a `ZodSchema` or Field Protocol and renders a form.
80+
* Support `auto-layout` based on field types.
81+
82+
### Phase 3: Automation Runtime (Week 5-6)
83+
**Objective:** Make the system "Active".
84+
1. **Implement `@objectstack/plugin-automation`**:
85+
* **Triggers:** Listen to `data:create`, `data:update` events.
86+
* **Flow Engine:** Interpreter for `src/automation/flow.zod.ts`.
87+
* **Actions:** Execute server-side logic defined in metadata.
88+
89+
### Phase 4: AI Agent Integration (Week 7+)
90+
**Objective:** Activate the "Post-SaaS" AI capabilities.
91+
1. **Agent Runtime**:
92+
* Implement `AgentExecutor` using `src/ai/agent.zod.ts`.
93+
* Connect Agents to `HttpDispatcher` as Tools.
94+
95+
---
96+
97+
## 4. Immediate Action Items (Today/Tomorrow)
98+
99+
1. **Scaffold `packages/plugins/driver-sqlite`**.
100+
2. **Extract Standard Driver Test Suite**: Ensure `packages/core/src/qa` has a reusable test suite that can be applied to new drivers immediately.

apps/docs/mdx-components.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { MDXComponents } from 'mdx/types';
2+
import defaultComponents from 'fumadocs-ui/mdx';
3+
4+
export function useMDXComponents(components: MDXComponents): MDXComponents {
5+
return {
6+
...defaultComponents,
7+
...components,
8+
};
9+
}

apps/docs/scripts/debug-docs.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
import { docs } from '../.source/server';
3+
import path from 'path';
4+
5+
console.log('CWD:', process.cwd());
6+
console.log('Resolved Content Path (Reference):', path.resolve(process.cwd(), '../../content/docs'));
7+
8+
console.log('--- Loaded Docs ---');
9+
// docs is a collection.
10+
// It might be an array or map depending on implementation.
11+
// Fumadocs collections usually export the list of items.
12+
13+
// Check if docs is array or object
14+
if (Array.isArray(docs)) {
15+
console.log(`Found ${docs.length} docs.`);
16+
docs.forEach((doc: any) => {
17+
console.log(`- ${doc.data.title} (${doc.file.path})`);
18+
});
19+
} else {
20+
console.log('Docs object:', docs);
21+
}
File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Architecture
3+
description: Deep dive into the ObjectKernel architecture
4+
---
5+
6+
# Core Architecture
7+
8+
The ObjectKernel architecture follows a strict **Life-Cycle** process to ensure system stability.
9+
10+
## The Bootstrap Lifecycle
11+
12+
When you request `kernel.bootstrap()`, the following sequence occurs:
13+
14+
```mermaid
15+
graph TD
16+
A[Bootstrap Start] --> B[Discovery]
17+
B --> C[Validation]
18+
C --> D[Resolution]
19+
D --> E[Init Phase]
20+
E --> F[Start Phase]
21+
F --> G[Ready State]
22+
```
23+
24+
### 1. Discovery Phase
25+
The kernel scans for registered plugins. In a typical app, plugins are explicitly registered via code, but the kernel also supports scanning `package.json` for auto-discovery in certain environments.
26+
27+
### 2. Validation Phase
28+
Each plugin's manifest is validated against the **Plugin Protocol** specific in `@objectstack/spec`.
29+
- **Name**: Must be unique.
30+
- **Version**: SemVer compatible.
31+
- **Dependencies**: Declared dependencies must be present.
32+
33+
### 3. Resolution Phase (Topological Sort)
34+
The kernel builds a dependency graph of all plugins. If Plugin A depends on Plugin B, Plugin B is guaranteed to be initialized first. Circular dependencies will throw a fatal error.
35+
36+
### 4. Init Phase (Synchronous Setup)
37+
The `init(ctx)` hook is called for every plugin in order.
38+
- **Purpose**: Register Services, Validate Configuration.
39+
- **Restriction**: NO side effects (e.g., do not connect to DB, do not start HTTP server).
40+
- **Outcome**: The Service Registry is fully populated.
41+
42+
### 5. Start Phase (Async Execution)
43+
The `start(ctx)` hook is called.
44+
- **Purpose**: Connect to databases, bind network ports, start background jobs.
45+
- **Outcome**: The system is live.
46+
47+
## Error Handling
48+
49+
The Kernel implements a **Rollback Mechanism**. If any plugin fails during the `start` phase, the kernel attempts to stop all previously started plugins in reverse order to ensure a clean exit.
50+
51+
```typescript
52+
const kernel = new ObjectKernel({
53+
rollbackOnFailure: true, // Default: true
54+
defaultStartupTimeout: 30000 // 30s timeout per plugin
55+
});
56+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Events & Hooks
3+
description: System-wide event bus
4+
---
5+
6+
# Events & Hooks
7+
8+
The Kernel provides a high-performance, typed Event Bus for loose coupling.
9+
10+
## Lifecycle Events
11+
12+
These events are emitted by the Kernel itself during the bootstrap process.
13+
14+
| Event | Description |
15+
| :--- | :--- |
16+
| `kernel:init` | The kernel has started initialization. |
17+
| `kernel:ready` | All plugins have successfully started. System is live. |
18+
| `kernel:shutdown` | Shutdown signal received. |
19+
20+
## Data Events
21+
22+
The Data Engine emits events for record mutations.
23+
24+
| Event | Payload |
25+
| :--- | :--- |
26+
| `data:beforeCreate` | `{ object, record }` - Can modify record or throw error to cancel. |
27+
| `data:afterCreate` | `{ object, record, id }` - Post-processing. |
28+
| `data:beforeUpdate` | `{ object, id, record }` |
29+
| `data:afterUpdate` | ... |
30+
31+
## Usage
32+
33+
### Listening to Events
34+
35+
```typescript
36+
ctx.hook('kernel:ready', async () => {
37+
ctx.logger.info("System is ready! Sending startup notification...");
38+
});
39+
40+
ctx.hook('data:beforeCreate', async ({ object, record }) => {
41+
if (object === 'order' && record.amount > 10000) {
42+
ctx.logger.warn('Large order detected!');
43+
}
44+
});
45+
```
46+
47+
### Emitting Events
48+
49+
```typescript
50+
// Custom business event
51+
ctx.emit('order:shipped', { orderId: '123' });
52+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Introduction
3+
description: The Core Microkernel of ObjectStack
4+
---
5+
6+
# ObjectStack Core
7+
8+
The `@objectstack/core` package is the **Microkernel** of the ObjectStack operating system. It provides the minimal runtime environment required to load plugins, manage dependencies, and orchestrate the system lifecycle.
9+
10+
Similar to how the Linux Kernel manages hardware drivers and processes, the ObjectStack Core manages **Protocol Plugins** and **Services**.
11+
12+
## Why a Microkernel?
13+
14+
ObjectStack is designed to be:
15+
1. **Modular**: Every feature, including the API Server, Database Driver, and UI Engine, is a plugin.
16+
2. **Extensible**: You can replace any default component with your own implementation.
17+
3. **Environment Agnostic**: Runs on Node.js, Bun, Edge Runtimes (Cloudflare Workers), or even in the Browser (via Mock Service Worker).
18+
19+
## Key Responsibilities
20+
21+
1. **Plugin Lifecycle Management**: Loading, validating, initializing, and starting plugins in the correct dependency order.
22+
2. **Dependency Injection (DI)**: A central registry for services to communicate without tight coupling.
23+
3. **Event Bus**: System-wide hook system for intercepting logic (e.g., `data:beforeCreate`, `kernel:ready`).
24+
4. **Configuration Management**: Standardized configuration loading using Zod validation.
25+
26+
## Installation
27+
28+
```bash
29+
pnpm add @objectstack/core
30+
```
31+
32+
## Basic Usage
33+
34+
```typescript
35+
import { ObjectKernel } from '@objectstack/core';
36+
37+
// 1. Create the Kernel
38+
const kernel = new ObjectKernel({
39+
logger: { level: 'info' }
40+
});
41+
42+
// 2. Register Plugins
43+
kernel.use({
44+
name: 'my-custom-plugin',
45+
version: '1.0.0',
46+
async init(ctx) {
47+
ctx.logger.info('Initializing my plugin...');
48+
},
49+
async start(ctx) {
50+
ctx.logger.info('Plugin started!');
51+
}
52+
});
53+
54+
// 3. Boot system
55+
await kernel.bootstrap();
56+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"title": "Core (Microkernel)",
3+
"pages": [
4+
"index",
5+
"architecture",
6+
"plugins",
7+
"services",
8+
"events",
9+
"types"
10+
]
11+
}

0 commit comments

Comments
 (0)