Skip to content

Commit d097976

Browse files
committed
feat: Refactor framework documentation and remove deprecated files
1 parent 7e56d8d commit d097976

26 files changed

+194
-359
lines changed

content/docs/framework/cli.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Command Line Interface
3+
description: Guide for using the ObjectStack CLI
4+
---
5+
6+
# @objectstack/cli
7+
8+
Command Line Interface for developing and managing ObjectStack applications.
9+
10+
## Installation
11+
12+
```bash
13+
pnpm add -D @objectstack/cli
14+
```
15+
16+
## Commands
17+
18+
### Development
19+
20+
- **`os serve`**: Start the backend server.
21+
- Auto-detects configuration.
22+
- Auto-loads `ObjectQL` and `InMemoryDriver` if not specified.
23+
- **`os dev`**: Start in development mode (with watch).
24+
- **`os doctor`**: Check environment health.
25+
26+
### Scaffolding
27+
28+
- **`os create`**: Scaffold new projects.
29+
30+
## Configuration
31+
32+
The CLI automatically looks for `objectstack.config.ts` in the current directory to load the runtime configuration.
33+
34+
```typescript
35+
// objectstack.config.ts
36+
export default {
37+
metadata: {
38+
// ...
39+
},
40+
plugins: [
41+
// ...
42+
]
43+
}
44+
```

content/docs/framework/cli/meta.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

content/docs/framework/core/architecture.mdx

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,55 @@ The kernel scans for registered plugins. In a typical app, plugins are explicitl
2828
Each plugin's manifest is validated against the **Plugin Protocol** specific in `@objectstack/spec`.
2929
- **Name**: Must be unique.
3030
- **Version**: SemVer compatible.
31-
- **Dependencies**: Declared dependencies must be present.
3231

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.
32+
### 3. Resolution Phase
33+
The kernel resolves the dependency graph. If Plugin A depends on Plugin B, the kernel ensures Plugin B is loaded first. Circular dependencies are detected and will throw an error.
3534

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.
35+
### 4. Init Phase (`onInit`)
36+
The `onInit` hook is called for all plugins in dependency order. This is where plugins should:
37+
- Register Services involved in Dependency Injection.
38+
- Register Event Listeners.
39+
- **NOT** perform async IO (like database connections) if possible.
4140

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.
41+
### 5. Start Phase (`onStart`)
42+
After all plugins have successfully initialized, the `onStart` hook is called in dependency order. This is where the application "comes alive":
43+
- Database connections are established.
44+
- HTTP servers start listening.
45+
- Background jobs are scheduled.
4646

47-
## Error Handling
47+
## IKernel Interface Reference
4848

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.
49+
The `IKernel` is the central orchestrator exposed to the host application.
5050

5151
```typescript
52-
const kernel = new ObjectKernel({
53-
rollbackOnFailure: true, // Default: true
54-
defaultStartupTimeout: 30000 // 30s timeout per plugin
55-
});
52+
export interface IKernel {
53+
/**
54+
* Start the Kernel
55+
* Initializes and starts all registered plugins and drivers.
56+
*/
57+
start(): Promise<void>;
58+
59+
/**
60+
* Stop the Kernel
61+
* Gracefully shuts down all plugins.
62+
*/
63+
stop(): Promise<void>;
64+
65+
/**
66+
* Get a Service
67+
* Retrieves a registered service by ID.
68+
*/
69+
getService<T>(id: string): T;
70+
71+
/**
72+
* Register a Service
73+
* Manually register a service instance (dynamic registration).
74+
*/
75+
registerService(id: string, instance: any): void;
76+
77+
/**
78+
* Check Service Availability
79+
*/
80+
hasService(id: string): boolean;
81+
}
5682
```

content/docs/framework/core/meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"architecture",
66
"plugins",
77
"services",
8-
"events",
9-
"types"
8+
"events"
109
]
1110
}

content/docs/framework/core/plugins.mdx

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,71 @@ export class MyPlugin implements Plugin {
2828
apiKey: z.string()
2929
});
3030

31-
// 1. Initialization
32-
async init(ctx: PluginContext) {
33-
// Register services here
34-
const myService = new MyService();
35-
ctx.registerService('my-service', myService);
31+
/**
32+
* Initialization Phase
33+
* Use this to register services, listeners, or other early setup.
34+
*/
35+
async onInit(ctx: PluginContext) {
36+
// Register a service
37+
ctx.services.register('myService', new MyService());
3638
}
3739

38-
// 2. Startup
39-
async start(ctx: PluginContext) {
40-
// Resolve other services
41-
const db = ctx.getService('database');
42-
await db.connect();
43-
}
44-
45-
// 3. Shutdown
46-
async stop(ctx: PluginContext) {
47-
// Cleanup
40+
/**
41+
* Start Phase
42+
* The system is fully initialized. Use this to start servers or background jobs.
43+
*/
44+
async onStart(ctx: PluginContext) {
45+
console.log('MyPlugin started!');
4846
}
4947
}
5048
```
5149

52-
## The Plugin Context
50+
## RuntimePlugin Interface Reference
51+
52+
The `RuntimePlugin` interface defines the contract that all functionality modules must implement.
53+
54+
```typescript
55+
export interface RuntimePlugin {
56+
/**
57+
* Plugin Unique Identifier
58+
* Recommended format: com.organization.plugin-name
59+
*/
60+
name: string;
61+
62+
/**
63+
* Plugin Version
64+
* Must follow Semantic Versioning (SemVer)
65+
*/
66+
version?: string;
5367

54-
The `PluginContext` is passed to every lifecycle hook. It is the plugin's gateway to the Kernel.
68+
/**
69+
* Description
70+
* Brief explanation of the plugin's purpose.
71+
*/
72+
description?: string;
5573

56-
| Method | Description |
57-
| :--- | :--- |
58-
| `ctx.logger` | A structured logger scoped to this plugin (e.g., labeled `[com.example.plugin]`). |
59-
| `ctx.registerService(name, impl)` | Expose a capability to other plugins. |
60-
| `ctx.getService(name)` | Retrieve a capability from another plugin. |
61-
| `ctx.hook(event, callback)` | Listen for system events. |
62-
| `ctx.emit(event, payload)` | Broadcast an event. |
74+
/**
75+
* Initialization Hook
76+
* Called during Kernel bootstrap. Use this to:
77+
* - Register Services
78+
* - Register Event Listeners
79+
* - Extend Metadata
80+
*/
81+
onInit?: (context: PluginContext) => Promise<void>;
6382

64-
## Best Practices
83+
/**
84+
* Start Hook
85+
* Called after all plugins are initialized. Use this to:
86+
* - Start HTTP servers
87+
* - Connect to databases
88+
* - Start background workers
89+
*/
90+
onStart?: (context: PluginContext) => Promise<void>;
6591

66-
1. **Prefix Names**: Use reverse domain notation (e.g., `com.mycompany.plugin`) to avoid collisions.
67-
2. **Define Contracts**: If your plugin exposes a service, export a TypeScript interface for it so consumers can type-check.
68-
3. **Config Validation**: Use `configSchema` (Zod) to validate user input. The Kernel automatically validates this before `init` is called.
92+
/**
93+
* Stop Hook
94+
* Called during Kernel shutdown. cleanup resources here.
95+
*/
96+
onStop?: (context: PluginContext) => Promise<void>;
97+
}
98+
```

content/docs/framework/core/types/IKernel.mdx

Lines changed: 0 additions & 30 deletions
This file was deleted.

content/docs/framework/core/types/RuntimePlugin.mdx

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Database Drivers
3+
description: Configuration reference for supported database drivers
4+
---
5+
6+
# Database Drivers
7+
8+
ObjectStack supports multiple database backends through a unified driver configurations.
9+
10+
## MongoDB
11+
12+
Configuration properties for the MongoDB driver.
13+
14+
| Property | Type | Required | Description |
15+
| :--- | :--- | :--- | :--- |
16+
| **url** | `string` | optional | Connection URI |
17+
| **database** | `string` || Database Name |
18+
| **host** | `string` | optional | Host address |
19+
| **port** | `number` | optional | Port number |
20+
| **username** | `string` | optional | Auth User |
21+
| **password** | `string` | optional | Auth Password |
22+
| **authSource** | `string` | optional | Authentication Database |
23+
| **ssl** | `boolean` | optional | Enable SSL |
24+
| **replicaSet** | `string` | optional | Replica Set Name |
25+
| **readPreference** | `Enum` | optional | Read Preference ('primary', 'secondary', etc.) |
26+
| **maxPoolSize** | `number` | optional | Max Connection Pool Size |
27+
| **minPoolSize** | `number` | optional | Min Connection Pool Size |
28+
29+
## PostgreSQL
30+
31+
Configuration properties for the PostgreSQL driver (node-postgres / pg).
32+
33+
| Property | Type | Required | Description |
34+
| :--- | :--- | :--- | :--- |
35+
| **url** | `string` | optional | Connection URI |
36+
| **database** | `string` || Database Name |
37+
| **host** | `string` | optional | Host address |
38+
| **port** | `number` | optional | Port number |
39+
| **username** | `string` | optional | Auth User |
40+
| **password** | `string` | optional | Auth Password |
41+
| **schema** | `string` | optional | Default Schema (defaults to 'public') |
42+
| **ssl** | `boolean \| object` | optional | Enable SSL |
43+
| **applicationName** | `string` | optional | Application Name |
44+
| **max** | `number` | optional | Max Pool Size |
45+
| **min** | `number` | optional | Min Pool Size |

content/docs/framework/driver/datasource/Datasource.mdx

Lines changed: 0 additions & 18 deletions
This file was deleted.

content/docs/framework/driver/datasource/DatasourceCapabilities.mdx

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)