From ff0ced2202264cfc2cd5169756da63d9891bb7e0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:22:47 +0000 Subject: [PATCH 1/4] Initial plan From d66eedcd30b33095b752e36dd3bd887b48fd27d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:27:53 +0000 Subject: [PATCH 2/4] Add mini-kernel docs, protocol reference index, and simplify README Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- README.md | 191 +++------- content/docs/developers/meta.json | 1 + content/docs/developers/mini-kernel.mdx | 453 ++++++++++++++++++++++++ content/docs/references/index.mdx | 204 +++++++++++ 4 files changed, 700 insertions(+), 149 deletions(-) create mode 100644 content/docs/developers/mini-kernel.mdx create mode 100644 content/docs/references/index.mdx diff --git a/README.md b/README.md index 3ff122788..094a7b3db 100644 --- a/README.md +++ b/README.md @@ -8,137 +8,38 @@ This repository contains the core specifications, schemas, and protocols that power the ObjectStack ecosystem. It defines how data, UI, and system configurations are expressed as code. -## ๐ŸŽ‰ Recent Updates (2026-01-27) +## ๐ŸŽฏ What is ObjectStack? -**ObjectQL (Data Layer) now at 100% completion!** ๐ŸŽฏ +ObjectStack is a metadata-driven platform built on three foundational protocols: -We've completed all advanced query features and AI/ML field types: -- โœ… **Window Functions** - ROW_NUMBER, RANK, LAG, LEAD, and aggregate window functions -- โœ… **HAVING Clause** - Filter aggregated results in GROUP BY queries -- โœ… **DISTINCT Queries** - Full support for SELECT DISTINCT -- โœ… **Subqueries** - Nested queries in JOIN clauses -- โœ… **Vector Field Type** - AI/ML embeddings for semantic search and RAG workflows -- โœ… **Location Field Type** - GPS coordinates for geospatial applications +- **ObjectQL** (Data Layer) - Define data structure and queries +- **ObjectOS** (Control Layer) - Runtime, permissions, and workflows +- **ObjectUI** (View Layer) - Presentation and user interaction -**See [PROTOCOL_EXTENSIONS_COMPLETED.md](./PROTOCOL_EXTENSIONS_COMPLETED.md) for complete details.** +**Learn more:** [Architecture Overview](./content/docs/introduction/architecture.mdx) ## ๐Ÿ“š Documentation -### Protocol Reference -* **[Protocol Index](./PROTOCOL_INDEX.md):** ๐Ÿ“‘ **Quick navigation index** to all 70 protocol specifications with direct links -* **[Protocol Reference](./PROTOCOL_REFERENCE.md):** ๐Ÿ“– **Complete inventory** with detailed descriptions, usage examples, and organization by module -* **[Protocol Organization](./PROTOCOL_ORGANIZATION.md):** ๐Ÿ—บ๏ธ **Visual diagrams and maps** showing protocol structure, dependencies, and relationships +๐Ÿ“– **[Read the Full Documentation](./content/docs/)** -### Quick Start -* **[Protocol Index](./PROTOCOL_INDEX.md):** Quick navigation to all protocol specifications -* **[Contributing Guide](./CONTRIBUTING.md):** How to contribute to the project +### Quick Links -### Architecture & Design -* **[Architecture Overview](./ARCHITECTURE.md):** Deep dive into the three-layer architecture -* **[Protocol Organization](./PROTOCOL_ORGANIZATION.md):** Visual diagrams showing protocol structure and dependencies +- **Getting Started:** + - [Introduction](./content/docs/introduction/) - Core concepts and architecture + - [Quick Start Examples](./examples/) - CRM, Todo, and plugin examples + +- **Protocol References:** + - [Protocol Reference](./content/docs/references/) - All 70 protocol specifications + - [ObjectQL](./content/docs/objectql/) - Data layer documentation + - [ObjectUI](./content/docs/objectui/) - UI layer documentation + - [ObjectOS](./content/docs/objectos/) - System layer documentation -### Standards & Best Practices -* **[Contributing Guide](./CONTRIBUTING.md):** Includes coding standards and best practices -* **[Protocol Reference](./PROTOCOL_REFERENCE.md):** Detailed documentation with usage examples +- **Development:** + - [MiniKernel Architecture](./content/docs/developers/mini-kernel.mdx) - Plugin architecture guide + - [Writing Plugins](./content/docs/developers/writing-plugins.mdx) - Plugin development guide + - [Contributing Guide](./CONTRIBUTING.md) - How to contribute -### Documentation Site -The official documentation is built with Fumadocs and Next.js. - -* **[Documentation Content](./content/docs/):** MDX documentation files (concepts, specifications, references) -* **[Documentation Site](./apps/docs/):** Fumadocs-powered Next.js app -* **[Live Site](http://localhost:3000/docs):** Run `pnpm docs:dev` to view locally - -### Planning & Internal Docs -* **[Protocol Extensions Completed](./PROTOCOL_EXTENSIONS_COMPLETED.md):** Recently completed features and updates -* **[Contributing Guide](./CONTRIBUTING.md):** Development workflow and guidelines - -## ๐Ÿ“ฆ Monorepo Structure - -| Package | Description | Status | -| :--- | :--- | :--- | -| **[`@objectstack/spec`](packages/spec)** | **THE PROTOCOL**. Contains all Zod definitions, Types, and JSON Schemas. | ๐ŸŸข **Active** | -| **[`@objectstack/docs`](apps/docs)** | Documentation site built with Fumadocs and Next.js. | ๐ŸŸข **Active** | -| `content/docs/` | Documentation content (MDX files). Shared resource. | ๐ŸŸข **Active** | -| **Examples** | Reference implementations demonstrating protocol features | | -| โ””โ”€ [`examples/crm`](examples/crm) | **Full-featured CRM** - 6 objects, workflows, validations, views, dashboards, reports | ๐ŸŸข **Complete** | -| โ””โ”€ [`examples/todo`](examples/todo) | **Quick-start** - Simple task management with 7 field types | ๐ŸŸข **Active** | -| โ””โ”€ [`examples/host`](examples/host) | Server runtime with kernel/plugin loading pattern | ๐ŸŸก **Experimental** | -| โ””โ”€ [`examples/plugin-bi`](examples/plugin-bi) | Business Intelligence plugin example | ๐ŸŸก **Experimental** | -| *Other packages* | *Legacy/Migration in progress* | ๐ŸŸก *Legacy* | - -## ๐Ÿ› ๏ธ The Protocol Architecture - -The ObjectStack Protocol (`@objectstack/spec`) contains **70 protocol specifications** organized into 11 modules. See **[PROTOCOL_REFERENCE.md](./PROTOCOL_REFERENCE.md)** for the complete inventory. - -### Core Modules (Summary) - -### 1. Data Protocol (ObjectQL) - 8 Protocols -Defines the "Shape of Data" and business logic. -- **Schema:** Objects, Fields (44 types including text, number, select, lookup, formula, autonumber, slider, qrcode, **vector** (AI/ML), **location** (GPS), etc.) -- **Logic:** Workflows, Triggers, Validation Rules, Formulas, Lifecycle Hooks -- **Security:** Permissions, Sharing Rules -- **Query:** Abstract Syntax Tree (AST) for unified data access across drivers with **Window Functions**, **HAVING**, **DISTINCT**, **Subqueries** -- **Automation:** Flow definitions, Dataset mappings - -### 2. UI Protocol (ObjectUI) - 10 Protocols -Defines the "Shape of Interaction" for rendering interfaces. -- **Views:** Grid, Kanban, Calendar, Gantt, List configurations -- **Pages:** FlexiPage layouts with regions and components -- **Navigation:** App menus and navigation structures -- **Analytics:** Reports (Tabular, Summary, Matrix), Dashboards with widgets -- **Actions:** Script, URL, Modal, Flow-triggered actions -- **Theming:** Color palettes, typography, breakpoints, animations -- **Widgets:** Custom field components - -### 3. System Protocol (ObjectOS) - 14 Protocols -Defines the "Runtime Environment" and platform capabilities. -- **Manifest:** Application packaging (`objectstack.config.ts`) with support for 7 package types: `app`, `plugin`, `driver`, `module`, `objectql`, `gateway`, `adapter` -- **Identity:** Authentication, Roles, Territories, Licenses, Organizations -- **Integration:** Webhooks, API contracts, ETL Mappings -- **Datasource:** Driver definitions for PostgreSQL, MongoDB, and extensible drivers -- **Discovery:** Plugin discovery and loading mechanisms -- **I18n:** Translation and internationalization support -- **Platform:** Events, Real-time sync, Audit logging, Background jobs, Feature flags - -### 4. AI Protocol - 8 Protocols -Defines AI agent integration capabilities. -- **Agent:** AI agent definitions and configurations -- **Model Registry:** LLM registry and selection -- **RAG Pipeline:** Retrieval-augmented generation -- **NLQ:** Natural language query processing (NL to ObjectQL) -- **Conversation:** Conversation management and memory -- **Cost Tracking:** AI cost tracking and budget management -- **Predictive:** Predictive analytics models -- **Orchestration:** AI-powered workflow automation - -### 5. API Protocol - 6 Protocols -Defines standardized API contracts. -- **Contracts:** API endpoint definitions and specifications -- **Endpoints:** REST endpoint definitions with rate limiting -- **Router:** API routing configuration -- **OData:** OData query protocol support -- **Realtime:** WebSocket/SSE real-time subscriptions -- **Discovery:** API discovery and introspection - -### Additional Modules -- **Automation Protocol** (7): Workflows, Flows, Approvals, ETL, Webhooks, Sync, Connectors -- **Auth Protocol** (6): Identity, Roles, Organizations, OAuth/SAML/SSO, SCIM, Policies -- **Permission Protocol** (4): Object permissions, Sharing rules, Row-level security, Territories -- **Hub Protocol** (5): Marketplace, Licensing, Multi-tenancy, Workspaces, Dependencies -- **Shared Protocol** (1): Common identifiers and utilities -- **Stack Protocol** (1): Root stack definition - -**๐Ÿ‘‰ See [PROTOCOL_REFERENCE.md](./PROTOCOL_REFERENCE.md) for detailed documentation of all 70 protocols.** - -## ๐Ÿš€ Development - -This project uses **PNPM** workspaces. - -### Prerequisites -- Node.js >= 18 -- PNPM >= 8 - -### Quick Start +## ๐Ÿš€ Quick Start ```bash # 1. Install dependencies @@ -146,45 +47,37 @@ pnpm install # 2. Build the Protocol (Generates Schemas & Docs) pnpm --filter @objectstack/spec build -# Output: -# - packages/spec/dist/ (Compiled TS) -# - packages/spec/json-schema/ (JSON Schemas) # 3. Start Documentation Site pnpm docs:dev # Visit http://localhost:3000/docs ``` -## ๐Ÿค Contributing - -We welcome contributions! Please read our **[Contributing Guide](./CONTRIBUTING.md)** for detailed guidelines. - -### Quick Start for Contributors - -1. **Read the Docs**: Review [CONTRIBUTING.md](./CONTRIBUTING.md) for complete guidelines -2. **Understand Architecture**: Read [ARCHITECTURE.md](./ARCHITECTURE.md) for system overview -3. **Explore Protocols**: See [PROTOCOL_REFERENCE.md](./PROTOCOL_REFERENCE.md) for detailed specifications -4. **Check Recent Work**: Review [PROTOCOL_EXTENSIONS_COMPLETED.md](./PROTOCOL_EXTENSIONS_COMPLETED.md) for latest updates +## ๐Ÿ“ฆ Monorepo Structure -### Key Standards +| Package | Description | Status | +| :--- | :--- | :--- | +| **[`@objectstack/spec`](packages/spec)** | Core protocol definitions (Zod schemas, Types, JSON Schemas) | ๐ŸŸข Active | +| **[`@objectstack/docs`](apps/docs)** | Documentation site (Fumadocs + Next.js) | ๐ŸŸข Active | +| [`examples/crm`](examples/crm) | Full-featured CRM example | ๐ŸŸข Complete | +| [`examples/todo`](examples/todo) | Simple todo app example | ๐ŸŸข Active | -- **Naming Conventions**: Follow consistent naming across the codebase - - Configuration keys (TypeScript properties): `camelCase` (e.g., `maxLength`, `referenceFilters`) - - Machine names (data values): `snake_case` (e.g., `name: 'project_task'`, `object: 'account'`) -- **Zod-First Design**: All schemas must be defined using Zod with runtime validation -- **TypeScript**: Use strict TypeScript with comprehensive JSDoc comments +## ๐Ÿค Contributing -### PR Checklist +We welcome contributions! Please read our **[Contributing Guide](./CONTRIBUTING.md)** for: -- [ ] Zod schema follows naming conventions -- [ ] Comprehensive JSDoc comments with `@description` -- [ ] Unit tests with 80%+ coverage -- [ ] Documentation with examples -- [ ] JSON schema generated successfully -- [ ] All existing tests pass +- Development workflow and setup +- Coding standards (Zod-first, camelCase config, snake_case data) +- Testing requirements +- Documentation guidelines -See [CONTRIBUTING.md](./CONTRIBUTING.md) for complete details. +**Key Standards:** +- All schemas defined using **Zod** with runtime validation +- Configuration keys: `camelCase` (e.g., `maxLength`) +- Machine names: `snake_case` (e.g., `project_task`) +- Comprehensive JSDoc comments +- 80%+ test coverage ## ๐Ÿ“„ License -Apach2 2.0 ยฉ ObjectStack +Apache 2.0 ยฉ ObjectStack diff --git a/content/docs/developers/meta.json b/content/docs/developers/meta.json index 456a1fe79..e28e54114 100644 --- a/content/docs/developers/meta.json +++ b/content/docs/developers/meta.json @@ -2,6 +2,7 @@ "title": "๐Ÿ”ง Development & Extension", "root": true, "pages": [ + "mini-kernel", "writing-plugins", "custom-widgets", "server-drivers", diff --git a/content/docs/developers/mini-kernel.mdx b/content/docs/developers/mini-kernel.mdx new file mode 100644 index 000000000..e230c6716 --- /dev/null +++ b/content/docs/developers/mini-kernel.mdx @@ -0,0 +1,453 @@ +--- +title: MiniKernel Architecture +description: Understanding ObjectStack's micro-kernel plugin architecture for building extensible applications +--- + +# MiniKernel Architecture + +ObjectStack uses a **micro-kernel architecture** that separates core functionality from business logic. Like the Linux kernel, the ObjectKernel provides minimal essential services while all features are loaded as plugins. + +## Overview + +The MiniKernel architecture enables: +- โœ… Pluggable ObjectQL instances (bring your own query engine) +- โœ… Service registry for dependency injection (DI) +- โœ… Standardized plugin lifecycle (init/start/destroy) +- โœ… Event-driven communication between plugins +- โœ… Easy testing with mockable services + +## Architecture Diagram + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ ObjectKernel (Core) โ”‚ +โ”‚ โ€ข Plugin Lifecycle Manager โ”‚ +โ”‚ โ€ข Service Registry (DI Container) โ”‚ +โ”‚ โ€ข Event Bus (Hook System) โ”‚ +โ”‚ โ€ข Dependency Resolver โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ โ”‚ โ”‚ โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ” + โ”‚ ObjectQL โ”‚ โ”‚ Driver โ”‚ โ”‚ Hono โ”‚ โ”‚ Custom โ”‚ + โ”‚ Plugin โ”‚ โ”‚ Plugin โ”‚ โ”‚Serverโ”‚ โ”‚ Plugin โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +## Core Components + +### 1. ObjectKernel + +The kernel manages plugin lifecycle and provides core services. + +**Location:** `packages/runtime/src/mini-kernel.ts` + +**API:** +```typescript +import { ObjectKernel } from '@objectstack/runtime'; + +const kernel = new ObjectKernel(); + +// Register plugins +kernel.use(plugin); + +// Start the kernel +await kernel.bootstrap(); + +// Access services +const ql = kernel.getService('objectql'); + +// Shutdown +await kernel.shutdown(); +``` + +### 2. Plugin Interface + +All plugins must implement the Plugin interface. + +**Location:** `packages/runtime/src/types.ts` + +**Definition:** +```typescript +interface Plugin { + name: string; + dependencies?: string[]; + init(ctx: PluginContext): Promise; + start?(ctx: PluginContext): Promise; + destroy?(): Promise; +} +``` + +### 3. Plugin Lifecycle + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ idle โ”‚ +โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜ + โ”‚ kernel.use(plugin) + โ–ผ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ init โ”‚ โ† Register services, subscribe to events +โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜ + โ”‚ kernel.bootstrap() + โ–ผ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ start โ”‚ โ† Connect to databases, start servers +โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ + โ”‚ + โ–ผ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ running โ”‚ +โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ kernel.shutdown() + โ–ผ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ destroy โ”‚ โ† Clean up resources +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +### 4. PluginContext + +The context provides access to kernel services and hooks. + +**API:** +```typescript +interface PluginContext { + // Service Registry + registerService(name: string, service: any): void; + getService(name: string): T; + + // Event System + hook(name: string, handler: Function): void; + trigger(name: string, ...args: any[]): Promise; + + // Logger + logger: Logger; +} +``` + +## Built-in Plugins + +### ObjectQLPlugin + +Registers the ObjectQL query engine as a service. + +```typescript +import { ObjectKernel, ObjectQLPlugin } from '@objectstack/runtime'; + +const kernel = new ObjectKernel(); + +// Default ObjectQL instance +kernel.use(new ObjectQLPlugin()); + +// Or bring your own instance +import { ObjectQL } from '@objectstack/objectql'; +const customQL = new ObjectQL({ /* config */ }); +kernel.use(new ObjectQLPlugin(customQL)); +``` + +**Registers service:** `objectql` + +### DriverPlugin + +Registers a database driver with ObjectQL. + +```typescript +import { DriverPlugin } from '@objectstack/runtime'; +import { createMemoryDriver } from '@objectstack/driver-memory'; + +const driver = createMemoryDriver(); +kernel.use(new DriverPlugin(driver, 'memory')); +``` + +**Dependencies:** `['com.objectstack.engine.objectql']` + +### HonoServerPlugin + +Starts an HTTP server using Hono. + +```typescript +import { HonoServerPlugin } from '@objectstack/plugin-hono-server'; + +kernel.use(new HonoServerPlugin({ port: 3000 })); +``` + +## Creating Custom Plugins + +### Basic Plugin Example + +```typescript +import { Plugin, PluginContext } from '@objectstack/runtime'; + +export class MyPlugin implements Plugin { + name = 'com.mycompany.my-plugin'; + dependencies = ['com.objectstack.engine.objectql']; + + async init(ctx: PluginContext): Promise { + ctx.logger.info('MyPlugin initializing'); + + // Register a service + ctx.registerService('my-service', { + doSomething: () => console.log('Hello!'), + }); + + // Subscribe to events + ctx.hook('kernel:ready', async () => { + ctx.logger.info('Kernel is ready!'); + }); + } + + async start(ctx: PluginContext): Promise { + ctx.logger.info('MyPlugin starting'); + + // Get other services + const ql = ctx.getService('objectql'); + + // Register objects, start servers, etc. + } + + async destroy(): Promise { + // Clean up resources + } +} +``` + +### Plugin with Dependencies + +```typescript +export class AnalyticsPlugin implements Plugin { + name = 'com.mycompany.analytics'; + dependencies = [ + 'com.objectstack.engine.objectql', + 'com.mycompany.my-plugin', + ]; + + async init(ctx: PluginContext): Promise { + // This plugin will init AFTER its dependencies + const myService = ctx.getService('my-service'); + myService.doSomething(); + } +} +``` + +## Event System + +Plugins communicate via events (hooks). + +### Standard Events + +```typescript +// Kernel lifecycle +'kernel:init' // Before plugins init +'kernel:ready' // After all plugins start +'kernel:shutdown' // Before shutdown + +// Data lifecycle +'data:record:beforeCreate' // { table, data } +'data:record:afterCreate' // { table, record } +'data:record:beforeUpdate' // { table, id, data } +'data:record:afterUpdate' // { table, id, record } +'data:record:beforeDelete' // { table, id } +'data:record:afterDelete' // { table, id } + +// Server lifecycle +'server:route:register' // { method, path, handler } +'server:ready' // { port, url } +'server:request' // { method, path, query, body } +``` + +### Using Events + +```typescript +// Subscribe to events +ctx.hook('data:record:afterCreate', async (event) => { + console.log('Record created:', event.record); +}); + +// Trigger events +await ctx.trigger('my:custom:event', { data: 'value' }); +``` + +## Dependency Resolution + +The kernel automatically resolves plugin dependencies using topological sort. + +```typescript +const kernel = new ObjectKernel(); + +// These will be initialized in dependency order +kernel.use(new DriverPlugin(driver, 'memory')); // depends on ObjectQL +kernel.use(new ObjectQLPlugin()); // no dependencies +kernel.use(new MyAnalyticsPlugin()); // depends on both + +await kernel.bootstrap(); +// Order: ObjectQL โ†’ Driver โ†’ Analytics +``` + +## Testing with MiniKernel + +### Mock Services + +```typescript +import { ObjectKernel } from '@objectstack/runtime'; + +// Create test kernel +const kernel = new ObjectKernel(); + +// Register mock ObjectQL +kernel.use({ + name: 'objectql-mock', + async init(ctx) { + ctx.registerService('objectql', { + getSchema: () => mockSchema, + query: () => mockData, + }); + }, +}); + +// Test your plugin +kernel.use(new MyPlugin()); +await kernel.bootstrap(); +``` + +### Integration Tests + +```typescript +import { describe, it, expect } from 'vitest'; +import { ObjectKernel, ObjectQLPlugin } from '@objectstack/runtime'; + +describe('MyPlugin', () => { + it('should register service', async () => { + const kernel = new ObjectKernel(); + kernel.use(new ObjectQLPlugin()); + kernel.use(new MyPlugin()); + + await kernel.bootstrap(); + + const service = kernel.getService('my-service'); + expect(service).toBeDefined(); + + await kernel.shutdown(); + }); +}); +``` + +## Configuration-Driven Loading + +Load plugins from a configuration file: + +```typescript +// objectstack.config.ts +export default { + plugins: [ + { name: '@objectstack/runtime#ObjectQLPlugin' }, + { name: '@objectstack/driver-memory#MemoryDriverPlugin' }, + { name: '@objectstack/plugin-hono-server#HonoServerPlugin', config: { port: 3000 } }, + ], +}; +``` + +```typescript +// Runtime loader +import { loadConfig } from '@objectstack/config'; +import { ObjectKernel } from '@objectstack/runtime'; + +const config = await loadConfig('./objectstack.config.ts'); +const kernel = new ObjectKernel(); + +for (const pluginDef of config.plugins) { + const PluginClass = await import(pluginDef.name); + kernel.use(new PluginClass(pluginDef.config)); +} + +await kernel.bootstrap(); +``` + +## Best Practices + +### 1. Use Dependency Injection + +```typescript +// โŒ Bad: Direct import +import { objectql } from './global-instance'; + +// โœ… Good: Get from context +const ql = ctx.getService('objectql'); +``` + +### 2. Handle Errors in Lifecycle Methods + +```typescript +async init(ctx: PluginContext): Promise { + try { + await this.setupDatabase(); + } catch (error) { + ctx.logger.error('Failed to setup database', { error }); + throw error; // Kernel will halt bootstrap + } +} +``` + +### 3. Clean Up in destroy() + +```typescript +async destroy(): Promise { + // Close connections + await this.db.close(); + + // Stop timers + clearInterval(this.syncTimer); + + // Unsubscribe from events + this.eventUnsubscribe(); +} +``` + +### 4. Use Meaningful Event Names + +```typescript +// โŒ Bad: Generic names +ctx.hook('update', handler); + +// โœ… Good: Specific, namespaced names +ctx.hook('analytics:metric:updated', handler); +``` + +## Migration from Monolithic Architecture + +### Before (Monolithic) + +```typescript +import { ObjectQL } from '@objectstack/objectql'; +import { createMemoryDriver } from '@objectstack/driver-memory'; + +const ql = new ObjectQL(); +const driver = createMemoryDriver(); +await ql.addDriver(driver, 'memory'); +await ql.loadObjects([Account, Contact]); +``` + +### After (MiniKernel) + +```typescript +import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime'; + +const kernel = new ObjectKernel(); +kernel.use(new ObjectQLPlugin()); +kernel.use(new DriverPlugin(driver, 'memory')); +kernel.use(new CRMPlugin()); // Loads Account, Contact + +await kernel.bootstrap(); +const ql = kernel.getService('objectql'); +``` + +## Related Documentation + +- [Writing Plugins](/docs/developers/writing-plugins) - Complete plugin development guide +- [ObjectQL Plugin Reference](/docs/references/objectql) - ObjectQL plugin API +- [Server Drivers](/docs/developers/server-drivers) - Creating custom drivers + +--- + +**Quick Start:** See [examples/host](https://github.com/objectstack-ai/spec/tree/main/examples/host) for a complete MiniKernel implementation. diff --git a/content/docs/references/index.mdx b/content/docs/references/index.mdx new file mode 100644 index 000000000..cd495737b --- /dev/null +++ b/content/docs/references/index.mdx @@ -0,0 +1,204 @@ +--- +title: Protocol Reference +description: Complete reference of all 70 ObjectStack protocol specifications +--- + +# Protocol Reference + +This is the complete reference for all protocol specifications in the ObjectStack ecosystem. Each protocol is implemented as a Zod schema providing runtime validation and TypeScript type safety. + +## Quick Navigation + +| Module | Protocols | Description | +| :--- | :---: | :--- | +| [Data Protocol](#data-protocol) | 8 | Core business logic and data modeling (ObjectQL) | +| [UI Protocol](#ui-protocol) | 10 | User interface definitions and interactions (ObjectUI) | +| [System Protocol](#system-protocol) | 14 | Runtime environment and platform capabilities (ObjectOS) | +| [AI Protocol](#ai-protocol) | 8 | AI/ML integration and agent orchestration | +| [API Protocol](#api-protocol) | 6 | Standardized API contracts and communication | +| [Automation Protocol](#automation-protocol) | 7 | Workflow automation and integration | +| [Auth Protocol](#auth-protocol) | 6 | Identity, authentication, and authorization | +| [Permission Protocol](#permission-protocol) | 4 | Access control and security policies | +| [Hub Protocol](#hub-protocol) | 5 | Marketplace and multi-tenancy | +| [Shared Protocol](#shared-protocol) | 1 | Common utilities and identifiers | +| [Stack Protocol](#stack-protocol) | 1 | Root stack definition | + +**Total: 70 protocols** + +--- + +## Data Protocol (ObjectQL) + +**Location:** `packages/spec/src/data/` +**Count:** 8 protocols + +Defines the "Shape of Data" and business logic. + +| File | Schema | Purpose | +| :--- | :--- | :--- | +| `field.zod.ts` | `FieldSchema` | Field definitions with 44 types (text, number, select, lookup, formula, vector, location, etc.) | +| `object.zod.ts` | `ObjectSchema` | Object/table definitions with fields, indexes, and capabilities | +| `query.zod.ts` | `QuerySchema` | Abstract query AST supporting window functions, HAVING, DISTINCT, subqueries | +| `validation.zod.ts` | `ValidationRuleSchema` | Validation rules for data integrity | +| `filter.zod.ts` | `FilterSchema` | Query filtering and conditions | +| `dataset.zod.ts` | `DatasetSchema` | Dataset definitions for reporting and analytics | +| `mapping.zod.ts` | `FieldMappingSchema` | Field mapping configurations for data transformation | +| `hook.zod.ts` | `HookSchema` | Lifecycle hooks (before/after insert, update, delete) | + +**Key Features:** +- 44 field types including AI/ML vectors and GPS locations +- Advanced query capabilities (window functions, HAVING, DISTINCT, subqueries) +- Validation rules and formulas +- Lifecycle hooks for business logic + +**Learn more:** [ObjectQL Documentation](/docs/objectql) + +--- + +## UI Protocol (ObjectUI) + +**Location:** `packages/spec/src/ui/` +**Count:** 10 protocols + +Defines the "Shape of Interaction" for rendering interfaces. + +| File | Schema | Purpose | +| :--- | :--- | :--- | +| `view.zod.ts` | `ViewSchema` | List views (grid, kanban, calendar, gantt) and form layouts | +| `page.zod.ts` | `PageSchema` | FlexiPage layouts with regions and components | +| `app.zod.ts` | `AppSchema` | Application structure and navigation menus | +| `dashboard.zod.ts` | `DashboardSchema` | Dashboard layouts with grid-based widgets | +| `report.zod.ts` | `ReportSchema` | Report definitions (tabular, summary, matrix, chart) | +| `action.zod.ts` | `ActionSchema` | UI actions (buttons, scripts, URLs, flows) | +| `component.zod.ts` | `ComponentSchema` | Reusable UI components | +| `block.zod.ts` | `BlockSchema` | UI block definitions | +| `theme.zod.ts` | `ThemeSchema` | Theming (colors, typography, breakpoints, animations) | +| `widget.zod.ts` | `WidgetSchema` | Custom field widgets with lifecycle hooks | + +**Key Features:** +- Server-driven UI with multiple view types +- Flexible page layouts with component regions +- Rich dashboard and reporting capabilities +- Comprehensive theming system + +**Learn more:** [ObjectUI Documentation](/docs/objectui) + +--- + +## System Protocol (ObjectOS) + +**Location:** `packages/spec/src/system/` +**Count:** 14 protocols + +Defines the "Runtime Environment" and platform capabilities. + +| File | Schema | Purpose | +| :--- | :--- | :--- | +| `manifest.zod.ts` | `ManifestSchema` | Application/plugin manifest (`objectstack.config.ts`) with 7 package types | +| `datasource.zod.ts` | `DatasourceSchema` | Data source connection configurations | +| `driver.zod.ts` | `DriverSchema` | Database driver definitions and options | +| `driver/postgres.zod.ts` | `PostgresConfigSchema` | PostgreSQL-specific driver configuration | +| `driver/mongo.zod.ts` | `MongoConfigSchema` | MongoDB-specific driver configuration | +| `plugin.zod.ts` | `PluginSchema` | Plugin lifecycle and interface definitions | +| `context.zod.ts` | `KernelContextSchema` | Kernel execution context with user, org, tenant info | +| `events.zod.ts` | `EventSchema` | Event bus and pub/sub patterns | +| `job.zod.ts` | `JobSchema` | Background job scheduling (cron, interval, delayed) | +| `audit.zod.ts` | `AuditEventSchema` | Audit logging for compliance | +| `logger.zod.ts` | `LoggerConfigSchema` | Structured logging configuration | +| `translation.zod.ts` | `TranslationSchema` | i18n/l10n support | +| `feature.zod.ts` | `FeatureFlagSchema` | Feature flag definitions | +| `scoped-storage.zod.ts` | `ScopedStorageSchema` | Scoped key-value storage | + +**Package Types:** +- `app` - Business application package +- `plugin` - General-purpose functionality extension +- `driver` - Database/external service adapter +- `module` - Reusable code library +- `objectql` - Core data engine implementation +- `gateway` - API protocol entry point (GraphQL, REST, RPC) +- `adapter` - Runtime container (Express, Hono, Fastify, Serverless) + +**Learn more:** [ObjectOS Documentation](/docs/objectos) + +--- + +## AI Protocol + +**Location:** `packages/spec/src/ai/` +**Count:** 8 protocols + +Defines AI agent integration capabilities. + +| File | Schema | Purpose | +| :--- | :--- | :--- | +| `agent.zod.ts` | `AgentSchema` | AI agent definitions and configurations | +| `model-registry.zod.ts` | `ModelRegistrySchema` | LLM registry and selection | +| `rag-pipeline.zod.ts` | `RAGPipelineSchema` | Retrieval-augmented generation | +| `nlq.zod.ts` | `NLQSchema` | Natural language query processing (NL to ObjectQL) | +| `conversation.zod.ts` | `ConversationSchema` | Conversation management and memory | +| `cost.zod.ts` | `CostTrackingSchema` | AI cost tracking and budget management | +| `predictive.zod.ts` | `PredictiveModelSchema` | Predictive analytics models | +| `orchestration.zod.ts` | `OrchestrationSchema` | AI-powered workflow automation | + +**Learn more:** [AI Protocol Reference](/docs/references/ai) + +--- + +## API Protocol + +**Location:** `packages/spec/src/api/` +**Count:** 6 protocols + +Defines standardized API contracts. + +| File | Schema | Purpose | +| :--- | :--- | :--- | +| `contract.zod.ts` | `APIContractSchema` | API endpoint definitions and specifications | +| `endpoint.zod.ts` | `EndpointSchema` | REST endpoint definitions with rate limiting | +| `router.zod.ts` | `RouterSchema` | API routing configuration | +| `odata.zod.ts` | `ODataSchema` | OData query protocol support | +| `realtime.zod.ts` | `RealtimeSchema` | WebSocket/SSE real-time subscriptions | +| `discovery.zod.ts` | `DiscoverySchema` | API discovery and introspection | + +**Learn more:** [API Protocol Reference](/docs/references/api) + +--- + +## Recent Additions (2026-01-27) + +**ObjectQL Advanced Features:** +- โœ… **Window Functions** - ROW_NUMBER, RANK, LAG, LEAD, and aggregate window functions +- โœ… **HAVING Clause** - Filter aggregated results in GROUP BY queries +- โœ… **DISTINCT Queries** - Full support for SELECT DISTINCT +- โœ… **Subqueries** - Nested queries in JOIN clauses +- โœ… **Vector Field Type** - AI/ML embeddings for semantic search and RAG workflows +- โœ… **Location Field Type** - GPS coordinates for geospatial applications + +--- + +## Schema Conventions + +All schemas follow these conventions: + +### Naming +- **Configuration Keys (TS Props):** `camelCase` (e.g., `maxLength`, `referenceFilters`) +- **Machine Names (Data Values):** `snake_case` (e.g., `name: 'project_task'`, `object: 'account'`) + +### Validation +- All schemas use **Zod** for runtime validation +- TypeScript types are inferred via `z.infer` +- JSON schemas are auto-generated for IDE support + +### Documentation +- Each schema includes comprehensive JSDoc comments +- Examples are provided for complex configurations +- Deprecated fields are marked with `@deprecated` + +--- + +## Next Steps + +- **Explore by Module:** Navigate to specific protocol sections above +- **See Examples:** Check [examples/crm](https://github.com/objectstack-ai/spec/tree/main/examples/crm) for real-world usage +- **Build Plugins:** Read [Writing Plugins](/docs/developers/writing-plugins) +- **Contribute:** Review [Contributing Guide](/docs/introduction/contributing) From 5087cae9b34a93eca1ee2dd397c33d778a14de16 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:29:17 +0000 Subject: [PATCH 3/4] Add releases page with protocol extensions and update navigation Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- content/docs/introduction/meta.json | 3 +- content/docs/introduction/releases.mdx | 300 +++++++++++++++++++++++++ 2 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 content/docs/introduction/releases.mdx diff --git a/content/docs/introduction/meta.json b/content/docs/introduction/meta.json index 236d84595..2ab3374d2 100644 --- a/content/docs/introduction/meta.json +++ b/content/docs/introduction/meta.json @@ -7,6 +7,7 @@ "metadata-driven", "architecture", "design-principles", - "terminology" + "terminology", + "releases" ] } diff --git a/content/docs/introduction/releases.mdx b/content/docs/introduction/releases.mdx new file mode 100644 index 000000000..57c20934d --- /dev/null +++ b/content/docs/introduction/releases.mdx @@ -0,0 +1,300 @@ +--- +title: Recent Updates & Releases +description: Latest features, improvements, and protocol extensions in ObjectStack +--- + +# Recent Updates & Releases + +Stay up-to-date with the latest features and improvements to the ObjectStack protocol. + +## Latest Release (2026-01-27) + +### ๐ŸŽฏ ObjectQL (Data Layer) - 100% Completion! + +We've completed all advanced query features and AI/ML field types, bringing ObjectQL to feature parity with enterprise database systems. + +#### Window Functions โœ… + +Full support for analytical window functions: + +**Ranking Functions:** +- `ROW_NUMBER()` - Sequential numbering within partitions +- `RANK()` - Ranking with gaps for ties +- `DENSE_RANK()` - Ranking without gaps +- `NTILE(n)` - Distribution into n buckets + +**Navigation Functions:** +- `LAG(field, offset)` - Access previous row values +- `LEAD(field, offset)` - Access next row values +- `FIRST_VALUE(field)` - First value in window +- `LAST_VALUE(field)` - Last value in window + +**Aggregate Window Functions:** +- `SUM()`, `AVG()`, `COUNT()`, `MIN()`, `MAX()` - With OVER clause + +**Example Usage:** +```typescript +import { ObjectQL } from '@objectstack/objectql'; + +const query = { + from: 'opportunity', + select: [ + 'account_name', + 'amount', + { + window: { + function: 'ROW_NUMBER', + partitionBy: ['account_name'], + orderBy: [{ field: 'amount', direction: 'desc' }], + }, + as: 'rank_in_account' + }, + { + window: { + function: 'SUM', + field: 'amount', + partitionBy: ['account_name'], + }, + as: 'total_account_revenue' + } + ], +}; +``` + +#### HAVING Clause โœ… + +Filter aggregated results in GROUP BY queries: + +```typescript +const query = { + from: 'opportunity', + select: [ + 'stage', + { aggregate: 'SUM', field: 'amount', as: 'total_revenue' }, + { aggregate: 'COUNT', field: 'id', as: 'deal_count' }, + ], + groupBy: ['stage'], + having: [ + { field: 'total_revenue', operator: 'greaterThan', value: 1000000 }, + { field: 'deal_count', operator: 'greaterThan', value: 10 }, + ], +}; +``` + +#### DISTINCT Queries โœ… + +Full support for SELECT DISTINCT: + +```typescript +// Distinct single field +const query = { + from: 'contact', + select: ['industry'], + distinct: true, +}; + +// Distinct multiple fields +const query = { + from: 'opportunity', + select: ['stage', 'type'], + distinct: true, +}; + +// Distinct with aggregate +const query = { + from: 'account', + select: [ + { aggregate: 'COUNT', field: 'industry', distinct: true, as: 'unique_industries' }, + ], +}; +``` + +#### Subqueries โœ… + +Nested queries in JOIN clauses: + +```typescript +const query = { + from: 'account', + select: ['name', 'industry', 'total_deals'], + joins: [ + { + type: 'left', + subquery: { + from: 'opportunity', + select: [ + 'account_id', + { aggregate: 'COUNT', field: 'id', as: 'total_deals' }, + ], + groupBy: ['account_id'], + }, + alias: 'deal_stats', + on: [{ left: 'id', operator: 'equals', right: 'deal_stats.account_id' }], + }, + ], +}; +``` + +#### Vector Field Type โœ… + +AI/ML embeddings for semantic search and RAG workflows: + +```typescript +import { Field } from '@objectstack/spec'; + +const KnowledgeArticle = { + name: 'knowledge_article', + fields: { + title: Field.text({ required: true }), + content: Field.textarea({ required: true }), + + // Store embeddings for semantic search + content_embedding: Field.vector({ + label: 'Content Embedding', + dimensions: 1536, // OpenAI ada-002 + description: 'Vector representation for semantic search', + }), + }, +}; + +// Query by semantic similarity +const similarArticles = await ql.query({ + from: 'knowledge_article', + where: [ + { + field: 'content_embedding', + operator: 'similar_to', + value: queryEmbedding, + threshold: 0.8, // Cosine similarity threshold + }, + ], + limit: 5, +}); +``` + +**Supported Operations:** +- `similar_to` - Cosine similarity search +- `knn` - K-nearest neighbors +- Integration with vector databases (Pinecone, Weaviate, pgvector) + +#### Location Field Type โœ… + +GPS coordinates for geospatial applications: + +```typescript +import { Field } from '@objectstack/spec'; + +const Store = { + name: 'store', + fields: { + name: Field.text({ required: true }), + address: Field.address(), + + // Store GPS coordinates + location: Field.location({ + label: 'Store Location', + description: 'GPS coordinates for mapping', + }), + }, +}; + +// Query by distance +const nearbyStores = await ql.query({ + from: 'store', + where: [ + { + field: 'location', + operator: 'within_radius', + value: { + lat: 37.7749, + lng: -122.4194, + radius: 10, // kilometers + }, + }, + ], + orderBy: [ + { + field: 'location', + direction: 'distance_from', + value: { lat: 37.7749, lng: -122.4194 }, + }, + ], +}); +``` + +**Supported Operations:** +- `within_radius` - Find locations within distance +- `within_bounds` - Find locations in bounding box +- `distance_from` - Calculate distance +- Integration with mapping services (Google Maps, Mapbox) + +--- + +## Previous Releases + +### v1.3.0 (2026-01-15) - Advanced Query Features + +- Added support for Common Table Expressions (CTE) +- Improved query optimizer performance +- Added transaction isolation levels + +### v1.2.0 (2025-12-20) - AI Protocol + +- Complete AI protocol suite (8 schemas) +- Agent orchestration and RAG pipeline +- Natural language query processing +- AI cost tracking and budgeting + +### v1.1.0 (2025-11-30) - UI Enhancements + +- Advanced theming system +- Custom widget lifecycle hooks +- Dashboard grid layouts +- Report builder improvements + +### v1.0.0 (2025-10-15) - Initial Release + +- Core ObjectQL, ObjectUI, ObjectOS protocols +- PostgreSQL and MongoDB drivers +- Basic plugin system +- Documentation site + +--- + +## Migration Guides + +### Upgrading to v1.4.0 + +The new window functions and vector/location field types are backward compatible. No breaking changes. + +**To use vector fields:** +1. Update `@objectstack/spec` to `^1.4.0` +2. Add vector database driver (e.g., `@objectstack/driver-pgvector`) +3. Define vector fields in your objects + +**To use location fields:** +1. Update `@objectstack/spec` to `^1.4.0` +2. Use with any driver (coordinates stored as JSON) +3. For advanced geospatial queries, use PostGIS driver + +--- + +## Roadmap + +### Q1 2026 +- [ ] GraphQL Gateway +- [ ] Real-time subscriptions (WebSocket) +- [ ] Multi-tenant data isolation + +### Q2 2026 +- [ ] Performance monitoring dashboard +- [ ] Advanced caching strategies +- [ ] Plugin marketplace + +--- + +## Get Involved + +- **Report Issues:** [GitHub Issues](https://github.com/objectstack-ai/spec/issues) +- **Contribute:** [Contributing Guide](/docs/introduction/contributing) +- **Discuss:** [GitHub Discussions](https://github.com/objectstack-ai/spec/discussions) From d709ecce688cd7e26d172721b179b92d8a083de6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Jan 2026 04:29:50 +0000 Subject: [PATCH 4/4] Remove redundant markdown files from root directory Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- ADVANCED_FEATURES.md | 443 ---------------- ARCHITECTURE.md | 558 -------------------- MINI_KERNEL_ARCHITECTURE.md | 382 -------------- MINI_KERNEL_GUIDE.md | 344 ------------- MINI_KERNEL_IMPLEMENTATION.md | 359 ------------- MINI_KERNEL_INDEX.md | 89 ---- MINI_KERNEL_SUMMARY.md | 439 ---------------- OBJECTQL_PLUGIN_QUICKSTART.md | 215 -------- PROTOCOL_EXTENSIONS_COMPLETED.md | 447 ---------------- PROTOCOL_INDEX.md | 204 -------- PROTOCOL_OPTIMIZATION_PLAN.md | 849 ------------------------------- PROTOCOL_ORGANIZATION.md | 245 --------- PROTOCOL_REFERENCE.md | 387 -------------- docs-structure-proposal.md | 90 ---- 14 files changed, 5051 deletions(-) delete mode 100644 ADVANCED_FEATURES.md delete mode 100644 ARCHITECTURE.md delete mode 100644 MINI_KERNEL_ARCHITECTURE.md delete mode 100644 MINI_KERNEL_GUIDE.md delete mode 100644 MINI_KERNEL_IMPLEMENTATION.md delete mode 100644 MINI_KERNEL_INDEX.md delete mode 100644 MINI_KERNEL_SUMMARY.md delete mode 100644 OBJECTQL_PLUGIN_QUICKSTART.md delete mode 100644 PROTOCOL_EXTENSIONS_COMPLETED.md delete mode 100644 PROTOCOL_INDEX.md delete mode 100644 PROTOCOL_OPTIMIZATION_PLAN.md delete mode 100644 PROTOCOL_ORGANIZATION.md delete mode 100644 PROTOCOL_REFERENCE.md delete mode 100644 docs-structure-proposal.md diff --git a/ADVANCED_FEATURES.md b/ADVANCED_FEATURES.md deleted file mode 100644 index 08176e3aa..000000000 --- a/ADVANCED_FEATURES.md +++ /dev/null @@ -1,443 +0,0 @@ -# ObjectStack ้ซ˜็บง็‰นๆ€งๅฎž็ŽฐๆŒ‡ๅ— - -## ๆฆ‚่ฟฐ - -ๆœฌๆ–‡ๆกฃๅฑ•็คบๅฆ‚ไฝ•ไฝฟ็”จ MiniKernel ๆžถๆž„ๅฎž็Žฐไธ‰ไธชๅ…ณ้”ฎ็š„้ซ˜็บง็‰นๆ€ง๏ผš - -1. **ไบ‹ไปถ้ฉฑๅŠจๆœบๅˆถ (Event Bus)** - ๅฎž็Žฐๆ’ไปถ้—ด็š„่งฃ่€ฆ้€šไฟก -2. **UI ๅผ•ๆ“ŽๅŠจๆ€ๆŒ‚่ฝฝ** - ๅŠจๆ€่ทฏ็”ฑๆณจๅ†Œๅ’Œ้กต้ขๆธฒๆŸ“ -3. **้…็ฝฎ้ฉฑๅŠจๅŠ ่ฝฝ** - ้€š่ฟ‡ JSON ้…็ฝฎๆ–‡ไปถๅŠ ่ฝฝๆ’ไปถ - -## โœ… ็‰นๆ€ง 1: ไบ‹ไปถ้ฉฑๅŠจๆœบๅˆถ (Event Bus) - -### ๆžถๆž„่ฏดๆ˜Ž - -ๅฝ“ๅ‰ MiniKernel ๅทฒ็ปๅฎž็Žฐไบ†ๅฎŒๆ•ด็š„ไบ‹ไปถ็ณป็ปŸ๏ผš - -```typescript -interface PluginContext { - hook(name: string, handler: (...args: any[]) => void | Promise): void; - trigger(name: string, ...args: any[]): Promise; -} -``` - -### ๆ ‡ๅ‡†ๅŒ–้’ฉๅญ - -ๆŽจ่็š„ๆ ‡ๅ‡†ๅŒ–ไบ‹ไปถ้’ฉๅญ๏ผš - -#### ๆ•ฐๆฎ็”Ÿๅ‘ฝๅ‘จๆœŸไบ‹ไปถ - -```typescript -// ๆ•ฐๆฎๅˆ›ๅปบ -'data:record:beforeCreate' // { table, data } -'data:record:afterCreate' // { table, data } - -// ๆ•ฐๆฎๆ›ดๆ–ฐ -'data:record:beforeUpdate' // { table, id, data, oldRecord } -'data:record:afterUpdate' // { table, id, data, changes } - -// ๆ•ฐๆฎๅˆ ้™ค -'data:record:beforeDelete' // { table, id } -'data:record:afterDelete' // { table, id } -``` - -#### ๆœๅŠกๅ™จ็”Ÿๅ‘ฝๅ‘จๆœŸไบ‹ไปถ - -```typescript -'server:route:register' // { method, path, handler } -'server:ready' // { port, url } -'server:request' // { method, path, query, body } -``` - -#### ๅ†…ๆ ธ็”Ÿๅ‘ฝๅ‘จๆœŸไบ‹ไปถ - -```typescript -'kernel:ready' // Kernel bootstrap complete -'kernel:shutdown' // Kernel shutting down -``` - -### ๅฎž็Žฐ็คบไพ‹ - -#### 1. Data Engine (ไบ‹ไปถ็”Ÿไบง่€…) - -```typescript -export class DataEnginePlugin implements Plugin { - name = 'com.objectstack.engine.data'; - - async init(ctx: PluginContext) { - const db = { - insert: async (table: string, data: any) => { - // ่งฆๅ‘ๅ‰็ฝฎ้’ฉๅญ - ๅ…่ฎธไฟฎๆ”นๆ•ฐๆฎ - await ctx.trigger('data:record:beforeCreate', { table, data }); - - // ๆ‰ง่กŒๆ’ๅ…ฅ - const record = { id: generateId(), ...data }; - - // ่งฆๅ‘ๅŽ็ฝฎ้’ฉๅญ - ็”จไบŽ่‡ชๅŠจๅŒ– (้ž้˜ปๅกž) - ctx.trigger('data:record:afterCreate', { table, data: record }) - .catch(err => console.error('Hook error:', err)); - - return record; - } - }; - - ctx.registerService('db', db); - } -} -``` - -#### 2. Flow Engine (ไบ‹ไปถๆถˆ่ดน่€…) - -```typescript -export class FlowEnginePlugin implements Plugin { - name = 'com.objectstack.engine.flow'; - - async start(ctx: PluginContext) { - // ็›‘ๅฌๆ•ฐๆฎๅˆ›ๅปบไบ‹ไปถ - ctx.hook('data:record:afterCreate', async ({ table, data }) => { - console.log(`[Flow] New ${table} record:`, data.id); - - // ๆ นๆฎๆกไปถ่งฆๅ‘ไธๅŒ็š„ๆต็จ‹ - if (table === 'orders' && data.status === 'pending') { - await this.executeFlow('process_order', data); - } - }); - - // ็›‘ๅฌๆ•ฐๆฎๆ›ดๆ–ฐไบ‹ไปถ - ctx.hook('data:record:afterUpdate', async ({ table, data, changes }) => { - if (table === 'orders' && changes.status === 'shipped') { - await this.executeFlow('notify_shipping', data); - } - }); - } - - private async executeFlow(flowName: string, data: any) { - console.log(`[Flow] โšก๏ธ Executing: ${flowName}`); - // ๅฎž้™…็š„ๅทฅไฝœๆตๆ‰ง่กŒ้€ป่พ‘ - } -} -``` - -### ๅ…ณ้”ฎไผ˜ๅŠฟ - -โœ… **ๅฎŒๅ…จ่งฃ่€ฆ**: Flow Engine ไธ้œ€่ฆ็Ÿฅ้“ Data Engine ็š„ๅญ˜ๅœจ -โœ… **ๅฏๆ‰ฉๅฑ•**: ๅฏไปฅๆทปๅŠ ไปปๆ„ๆ•ฐ้‡็š„ไบ‹ไปถ็›‘ๅฌๅ™จ -โœ… **ๅผ‚ๆญฅๆ‰ง่กŒ**: ๅŽ็ฝฎ้’ฉๅญไธ้˜ปๅกžไธปๆต็จ‹ -โœ… **็ฑปๅž‹ๅฎ‰ๅ…จ**: TypeScript ๆ”ฏๆŒๅฎŒๆ•ด็š„็ฑปๅž‹ๆŽจๅฏผ - -### ไฝฟ็”จ็คบไพ‹ - -```typescript -const kernel = new ObjectKernel(); - -kernel - .use(new DataEnginePlugin()) // ็”Ÿไบงไบ‹ไปถ - .use(new FlowEnginePlugin()); // ๆถˆ่ดนไบ‹ไปถ - -await kernel.bootstrap(); - -// ่งฆๅ‘ๆ•ฐๆฎๆ“ไฝœ๏ผŒ่‡ชๅŠจ่งฆๅ‘ๅทฅไฝœๆต -const db = kernel.getService('db'); -await db.insert('orders', { - customer: 'John', - total: 299.99, - status: 'pending' -}); -// โ†’ ่‡ชๅŠจ่งฆๅ‘ 'process_order' ๅทฅไฝœๆต -``` - -## โœ… ็‰นๆ€ง 2: UI ๅผ•ๆ“ŽๅŠจๆ€ๆŒ‚่ฝฝ - -### ๆžถๆž„่ฏดๆ˜Ž - -UI Engine ้€š่ฟ‡ๆœๅŠกๆณจๅ†Œ่กจ่Žทๅ– HTTP Server๏ผŒ็„ถๅŽๅŠจๆ€ๆณจๅ†Œ่ทฏ็”ฑใ€‚ - -### ๅฎž็Žฐ็คบไพ‹ - -```typescript -export class UiEnginePlugin implements Plugin { - name = 'com.objectstack.engine.ui'; - dependencies = ['com.objectstack.server.hono']; // ไพ่ต– HTTP ๆœๅŠกๅ™จ - - async init(ctx: PluginContext) { - // ๆณจๅ†Œ UI ๅผ•ๆ“ŽๆœๅŠก - const uiEngine = { - renderPage: (route: string, data: any) => { - return ` - - ObjectStack - ${route} - -

Current Route: ${route}

-
${JSON.stringify(data, null, 2)}
- - `; - } - }; - - ctx.registerService('ui-engine', uiEngine); - } - - async start(ctx: PluginContext) { - // ่Žทๅ– HTTP ๆœๅŠกๅ™จ - const app = ctx.getService('http-server'); - const uiEngine = ctx.getService('ui-engine'); - - // ๆณจๅ†Œ UI ่ทฏ็”ฑ - app.get('/app/*', (c) => { - const html = uiEngine.renderPage(c.req.path, { - timestamp: new Date().toISOString() - }); - return c.html(html); - }); - - // ๆณจๅ†Œๅˆ—่กจ่ง†ๅ›พ่ทฏ็”ฑ - app.get('/ui/list/:object', (c) => { - const objectName = c.req.param('object'); - const html = uiEngine.renderPage(`/ui/list/${objectName}`, { - object: objectName, - view: 'list' - }); - return c.html(html); - }); - - // ๆณจๅ†Œ่กจๅ•่ง†ๅ›พ่ทฏ็”ฑ - app.get('/ui/form/:object/:id?', (c) => { - const objectName = c.req.param('object'); - const id = c.req.param('id'); - const html = uiEngine.renderPage(`/ui/form/${objectName}/${id || 'new'}`, { - object: objectName, - id: id || null, - view: 'form' - }); - return c.html(html); - }); - - console.log('[UI] Routes mounted: /app/*, /ui/list/:object, /ui/form/:object/:id'); - } -} -``` - -### ไฝฟ็”จ็คบไพ‹ - -```typescript -const kernel = new ObjectKernel(); - -kernel - .use(new HonoServerPlugin({ port: 3000 })) // HTTP ๆœๅŠกๅ™จ - .use(new UiEnginePlugin()); // UI ๅผ•ๆ“Ž - -await kernel.bootstrap(); - -// ่ฎฟ้—ฎ: -// - http://localhost:3000/app/ -// - http://localhost:3000/ui/list/contacts -// - http://localhost:3000/ui/form/orders/12345 -``` - -## โœ… ็‰นๆ€ง 3: ้…็ฝฎ้ฉฑๅŠจๅŠ ่ฝฝ - -### ๆžถๆž„่ฏดๆ˜Ž - -้€š่ฟ‡ JSON ้…็ฝฎๆ–‡ไปถๅฎšไน‰่ฆๅŠ ่ฝฝ็š„ๆ’ไปถ๏ผŒๅฎž็Žฐ็œŸๆญฃ็š„ "ไฝŽไปฃ็ " ๅนณๅฐ็‰นๆ€งใ€‚ - -### ้…็ฝฎๆ–‡ไปถๆ ผๅผ - -```json -{ - "version": "1.0.0", - "plugins": [ - { - "name": "objectstack-objectql", - "enabled": true, - "options": { - "env": "production" - } - }, - { - "name": "objectstack-data", - "enabled": true, - "options": { - "enableHooks": true - } - }, - { - "name": "objectstack-flow", - "enabled": false - }, - { - "name": "objectstack-ui", - "enabled": true - } - ] -} -``` - -### ้…็ฝฎๅŠ ่ฝฝๅ™จๅฎž็Žฐ - -```typescript -// ๆ’ไปถๆณจๅ†Œ่กจ -export class PluginRegistry { - private static registry = new Map Plugin>(); - - static register(name: string, factory: () => Plugin) { - this.registry.set(name, factory); - } - - static get(name: string) { - return this.registry.get(name); - } -} - -// ไปŽ้…็ฝฎๅˆ›ๅปบๅ†…ๆ ธ -export async function createKernelFromConfig(configPath: string) { - const config = JSON.parse(readFileSync(configPath, 'utf-8')); - const kernel = new ObjectKernel(); - - for (const pluginConfig of config.plugins) { - if (!pluginConfig.enabled) { - console.log(`Skipping disabled plugin: ${pluginConfig.name}`); - continue; - } - - const factory = PluginRegistry.get(pluginConfig.name); - if (!factory) { - console.warn(`Plugin not found: ${pluginConfig.name}`); - continue; - } - - const plugin = factory(); - kernel.use(plugin); - console.log(`โœ… Loaded: ${pluginConfig.name}`); - } - - return kernel; -} -``` - -### ไฝฟ็”จ็คบไพ‹ - -```typescript -// 1. ๆณจๅ†Œๆ‰€ๆœ‰ๅฏ็”จ็š„ๆ’ไปถ -PluginRegistry.register('objectstack-objectql', () => new ObjectQLPlugin()); -PluginRegistry.register('objectstack-data', () => new DataEnginePlugin()); -PluginRegistry.register('objectstack-flow', () => new FlowEnginePlugin()); -PluginRegistry.register('objectstack-ui', () => new UiEnginePlugin()); - -// 2. ไปŽ้…็ฝฎๆ–‡ไปถๅˆ›ๅปบๅ†…ๆ ธ -const kernel = await createKernelFromConfig('./objectstack.config.json'); - -// 3. ๅฏๅŠจ -await kernel.bootstrap(); -``` - -### ้…็ฝฎ้ฉฑๅŠจ็š„ไผ˜ๅŠฟ - -โœ… **ๆ— ้œ€ไฟฎๆ”นไปฃ็ **: ๅช้œ€ไฟฎๆ”น JSON ๆ–‡ไปถ -โœ… **็Žฏๅขƒ็‰นๅฎš้…็ฝฎ**: ๅผ€ๅ‘/ๆต‹่ฏ•/็”Ÿไบง็ŽฏๅขƒไธๅŒ้…็ฝฎ -โœ… **ๆŒ‰้œ€ๅŠ ่ฝฝ**: ๅชๅŠ ่ฝฝ้œ€่ฆ็š„ๆ’ไปถ -โœ… **็‰ˆๆœฌๆŽงๅˆถๅ‹ๅฅฝ**: ้…็ฝฎๆ–‡ไปถๅฏไปฅ็‰ˆๆœฌ็ฎก็† - -## ๅฎŒๆ•ด็คบไพ‹ - -### ๅœบๆ™ฏ๏ผš่ฎขๅ•ๅค„็†็ณป็ปŸ - -```typescript -// 1. ๆณจๅ†Œๆ’ไปถ -PluginRegistry.register('objectstack-objectql', () => new ObjectQLPlugin()); -PluginRegistry.register('objectstack-data', () => new DataEnginePlugin()); -PluginRegistry.register('objectstack-server', () => new HonoServerPlugin({ port: 3000 })); -PluginRegistry.register('objectstack-flow', () => new FlowEnginePlugin()); -PluginRegistry.register('objectstack-ui', () => new UiEnginePlugin()); - -// 2. ไปŽ้…็ฝฎๅŠ ่ฝฝ -const kernel = await createKernelFromConfig('./objectstack.config.json'); -await kernel.bootstrap(); - -// 3. ไฝฟ็”จ -const db = kernel.getService('db'); - -// ๅˆ›ๅปบ่ฎขๅ• โ†’ ่‡ชๅŠจ่งฆๅ‘ๅทฅไฝœๆต โ†’ UI ๅฏไปฅๆŸฅ็œ‹ -await db.insert('orders', { - customer: 'Alice', - items: ['Product A', 'Product B'], - total: 599.99, - status: 'pending' -}); - -// Flow Engine ่‡ชๅŠจๆ‰ง่กŒ: -// - ๅบ“ๅญ˜ๆฃ€ๆŸฅ -// - ๆ”ฏไป˜ๅค„็† -// - ๅ‘่ดง้€š็Ÿฅ -// - ้‚ฎไปถ้€š็Ÿฅ - -// UI Engine ๆไพ›: -// - ่ฎขๅ•ๅˆ—่กจ: http://localhost:3000/ui/list/orders -// - ่ฎขๅ•่ฏฆๆƒ…: http://localhost:3000/ui/form/orders/12345 -``` - -## ่ฟ›้˜ถๆจกๅผ - -### 1. ๆกไปถๅŒ–ๅทฅไฝœๆต - -```typescript -ctx.hook('data:record:afterCreate', async ({ table, data }) => { - // ๆ นๆฎๆ•ฐๆฎ่งฆๅ‘ไธๅŒ็š„ๆต็จ‹ - if (table === 'orders') { - if (data.total > 1000) { - await executeFlow('vip_order_processing', data); - } else { - await executeFlow('standard_order_processing', data); - } - } -}); -``` - -### 2. ๅคš็Žฏๅขƒ้…็ฝฎ - -```json -// objectstack.dev.json -{ - "plugins": [ - { "name": "objectstack-data", "enabled": true }, - { "name": "objectstack-flow", "enabled": false } // ๅผ€ๅ‘็Žฏๅขƒ็ฆ็”จ - ] -} - -// objectstack.prod.json -{ - "plugins": [ - { "name": "objectstack-data", "enabled": true }, - { "name": "objectstack-flow", "enabled": true } // ็”Ÿไบง็Žฏๅขƒๅฏ็”จ - ] -} -``` - -### 3. ๅŠจๆ€ๆ’ไปถ้€‰้กน - -```typescript -// ๆ นๆฎ้…็ฝฎไผ ้€’้€‰้กน็ป™ๆ’ไปถ -const kernel = new ObjectKernel(); - -for (const cfg of config.plugins) { - const factory = PluginRegistry.get(cfg.name); - const plugin = factory(cfg.options); // ไผ ้€’้€‰้กน - kernel.use(plugin); -} -``` - -## ๆ€ป็ป“ - -โœ… **ไบ‹ไปถ้ฉฑๅŠจ**: ๅทฒๅฎŒๅ…จๅฎž็Žฐ๏ผŒ้€š่ฟ‡ `hook()` ๅ’Œ `trigger()` -โœ… **UI ๆŒ‚่ฝฝ**: ๅทฒๅฎŒๅ…จๆ”ฏๆŒ๏ผŒ้€š่ฟ‡ๆœๅŠกๆณจๅ†Œ่กจ่Žทๅ– HTTP ๆœๅŠกๅ™จ -โœ… **้…็ฝฎๅŠ ่ฝฝ**: ๆไพ›ๅฎŒๆ•ด็š„ๅ‚่€ƒๅฎž็Žฐๅ’Œ็คบไพ‹ - -**ๅฝ“ๅ‰ MiniKernel ๆžถๆž„ๅทฒ็ปๅ…ทๅค‡็”Ÿไบง็Žฏๅขƒๆ‰€้œ€็š„ๆ‰€ๆœ‰ๆ ธๅฟƒ่ƒฝๅŠ›๏ผ** - -## ๅ‚่€ƒๆ–‡ไปถ - -- ๅฎŒๆ•ด็คบไพ‹: `/examples/complete-event-driven-example.ts` -- Flow Engine: `/examples/flow-engine-plugin.ts` -- Data Engine: `/examples/data-engine-plugin.ts` -- UI Engine: `/examples/ui-engine-plugin.ts` -- ้…็ฝฎๅŠ ่ฝฝๅ™จ: `/examples/config-loader.ts` -- ้…็ฝฎ็คบไพ‹: `/examples/objectstack.config.json` diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md deleted file mode 100644 index 6a851abd5..000000000 --- a/ARCHITECTURE.md +++ /dev/null @@ -1,558 +0,0 @@ -# ObjectStack Protocol - Architecture Diagrams - -> Visual reference for understanding the complete ObjectStack ecosystem and protocol layers. - ---- - -## ๐Ÿ—๏ธ Three-Layer Architecture - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectUI (View Layer) โ”‚ -โ”‚ Server-Driven UI Protocol - Define "How Users Interact" โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ€ข App & Navigation โ€ข Dashboard & Widgets โ”‚ -โ”‚ โ€ข ListView (Grid/Kanban) โ€ข FormView (Simple/Tabbed) โ”‚ -โ”‚ โ€ข Report & Analytics โ€ข Action Buttons โ”‚ -โ”‚ โ€ข Page Layouts โ€ข Theme Configuration โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ฒ - โ”‚ Render - โ”‚ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectOS (Control Layer) โ”‚ -โ”‚ Runtime Kernel - Define "How System Operates" โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ€ข Manifest & Packaging โ€ข Identity & Roles (IAM) โ”‚ -โ”‚ โ€ข Plugin Lifecycle โ€ข Event Bus & Jobs โ”‚ -โ”‚ โ€ข API Gateway (Rest/GQL)โ€ข Real-time (Socket/SSE) โ”‚ -โ”‚ โ€ข Multi-tenancy โ€ข Audit & Compliance โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ฒ - โ”‚ Execute - โ”‚ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectQL (Data Layer) โ”‚ -โ”‚ Business Kernel - Define "What Data Exists" โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ€ข Object & Field Schema โ€ข AI Agents & Orchestration โ”‚ -โ”‚ โ€ข Query AST (Filter/Sort) โ€ข RAG & Vector Search โ”‚ -โ”‚ โ€ข Validation Rules โ€ข Permission & Sharing โ”‚ -โ”‚ โ€ข Workflow & Flow โ€ข Driver & Datasource (IO) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -โ”‚ driver-postgres โ”‚ driver-mongodb โ”‚ driver-salesforce โ”‚ -โ”‚ driver-mysql โ”‚ driver-redis โ”‚ driver-excel โ”‚ -โ”‚ driver-sqlite โ”‚ driver-s3 โ”‚ driver-airtable โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - ---- - -## ๐Ÿ“ฆ Package Structure & Protocol Flow - -``` -@objectstack/spec -โ”œโ”€โ”€ Data Protocol (ObjectQL) -โ”‚ โ”œโ”€โ”€ field.zod.ts โ†’ Field types, constraints, relationships -โ”‚ โ”œโ”€โ”€ object.zod.ts โ†’ Object definition, capabilities -โ”‚ โ”œโ”€โ”€ validation.zod.ts โ†’ Business rules, error messages -โ”‚ โ”œโ”€โ”€ permission.zod.ts โ†’ CRUD, field-level security -โ”‚ โ”œโ”€โ”€ sharing.zod.ts โ†’ Sharing rules, ownership -โ”‚ โ”œโ”€โ”€ workflow.zod.ts โ†’ State machine, transitions -โ”‚ โ”œโ”€โ”€ flow.zod.ts โ†’ Visual flow automation -โ”‚ โ”œโ”€โ”€ query.zod.ts โ†’ AST for queries (filter, sort, join) -โ”‚ โ”œโ”€โ”€ filter.zod.ts โ†’ Query filter conditions -โ”‚ โ”œโ”€โ”€ dataset.zod.ts โ†’ Virtual datasets -โ”‚ โ”œโ”€โ”€ mapping.zod.ts โ†’ ETL transformations -โ”‚ โ””โ”€โ”€ trigger.zod.ts โ†’ Trigger context -โ”‚ -โ”œโ”€โ”€ UI Protocol (ObjectUI) -โ”‚ โ”œโ”€โ”€ app.zod.ts โ†’ App structure, navigation tree -โ”‚ โ”œโ”€โ”€ view.zod.ts โ†’ List/Form/Calendar views -โ”‚ โ”œโ”€โ”€ dashboard.zod.ts โ†’ Dashboard layouts, widgets -โ”‚ โ”œโ”€โ”€ report.zod.ts โ†’ Report types, grouping -โ”‚ โ”œโ”€โ”€ action.zod.ts โ†’ Button actions, navigation -โ”‚ โ”œโ”€โ”€ page.zod.ts โ†’ FlexiPage regions, components -โ”‚ โ”œโ”€โ”€ theme.zod.ts โ†’ Color, typography, spacing -โ”‚ โ””โ”€โ”€ widget.zod.ts โ†’ Custom field components -โ”‚ -โ”œโ”€โ”€ System Protocol (ObjectOS) -โ”‚ โ”œโ”€โ”€ manifest.zod.ts โ†’ Package definition (objectstack.config.ts) -โ”‚ โ”œโ”€โ”€ datasource.zod.ts โ†’ External data connections -โ”‚ โ”œโ”€โ”€ api.zod.ts โ†’ REST/GraphQL contracts -โ”‚ โ”œโ”€โ”€ identity.zod.ts โ†’ User, session management -โ”‚ โ”œโ”€โ”€ role.zod.ts โ†’ RBAC definitions -โ”‚ โ”œโ”€โ”€ policy.zod.ts โ†’ Global policies -โ”‚ โ”œโ”€โ”€ territory.zod.ts โ†’ Territory hierarchy -โ”‚ โ”œโ”€โ”€ license.zod.ts โ†’ License types, restrictions -โ”‚ โ”œโ”€โ”€ webhook.zod.ts โ†’ HTTP callbacks -โ”‚ โ”œโ”€โ”€ translation.zod.ts โ†’ i18n definitions -โ”‚ โ”œโ”€โ”€ discovery.zod.ts โ†’ Metadata introspection -โ”‚ โ”œโ”€โ”€ plugin.zod.ts โ†’ Plugin lifecycle -โ”‚ โ”œโ”€โ”€ driver.zod.ts โ†’ Database driver interface -โ”‚ โ”œโ”€โ”€ tenant.zod.ts โ†’ Multi-tenancy -โ”‚ โ”œโ”€โ”€ events.zod.ts โ†’ Event bus -โ”‚ โ”œโ”€โ”€ realtime.zod.ts โ†’ WebSocket sync -โ”‚ โ”œโ”€โ”€ organization.zod.ts โ†’ Organization management -โ”‚ โ”œโ”€โ”€ audit.zod.ts โ†’ Audit logging -โ”‚ โ””โ”€โ”€ job.zod.ts โ†’ Background jobs -โ”‚ -โ”œโ”€โ”€ AI Protocol -โ”‚ โ”œโ”€โ”€ agent.zod.ts โ†’ AI agent configuration -โ”‚ โ”œโ”€โ”€ model-registry.zod.ts โ†’ LLM registry -โ”‚ โ”œโ”€โ”€ rag-pipeline.zod.ts โ†’ RAG pipeline -โ”‚ โ”œโ”€โ”€ nlq.zod.ts โ†’ Natural language query -โ”‚ โ”œโ”€โ”€ conversation.zod.ts โ†’ Conversation management -โ”‚ โ”œโ”€โ”€ cost.zod.ts โ†’ AI cost tracking -โ”‚ โ”œโ”€โ”€ predictive.zod.ts โ†’ Predictive analytics -โ”‚ โ””โ”€โ”€ workflow-automation.zod.ts โ†’ AI workflow automation -โ”‚ -โ””โ”€โ”€ API Protocol - โ””โ”€โ”€ contract.zod.ts โ†’ Request/response envelopes -``` - ---- - -## ๐Ÿ”„ Data Flow: User Request to Database - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ Browser โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ ObjectUI โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ ObjectOS โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ ObjectQL โ”‚โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚ Driver โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ - โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ - โ–ผ โ–ผ โ–ผ โ–ผ โ–ผ -User clicks Lookup view Check user Parse query Execute SQL -"Show Accounts" definition from permissions to AST on Postgres - app.navigation (role-based) (filter/sort) - - Apply field- Optimize Return rows - level security (joins/index) - - Run triggers Generate SQL - (beforeFind) dialect -``` - -### Detailed Steps: - -1. **User Interaction** (Browser) - - User clicks "Accounts" in navigation - - Browser sends: `GET /api/data/account?view=all` - -2. **UI Resolution** (ObjectUI) - - Lookup `app.navigation` โ†’ find `ObjectNavItem(objectName: "account")` - - Lookup `view.zod` โ†’ find ListView definition for "all" view - - Determine columns, filters, sort order - -3. **Security Check** (ObjectOS) - - Validate user session (JWT token) - - Check `role.zod` โ†’ user has "read" permission on "account"? - - Check `permission.zod` โ†’ field-level security (hide SSN field) - - Apply sharing rules (only show accounts owned by user's team) - -4. **Query Translation** (ObjectQL) - - Parse filters from UI โ†’ Query AST - - Apply validation rules - - Run triggers: `beforeFind(ctx)` - - Optimize query (index hints) - -5. **Database Execution** (Driver) - - Driver translates AST โ†’ SQL dialect (Postgres, MySQL, etc.) - - Execute query with connection pooling - - Return raw rows - -6. **Response Formatting** (ObjectOS โ†’ ObjectUI) - - Format response per `api/contract.zod` schema - - Apply field formatting (currency, date) - - Return JSON to browser - -7. **Rendering** (Browser) - - React/Vue/Svelte renders ListView component - - Display grid with pagination - ---- - -## ๐Ÿงฉ Plugin Architecture - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectStack Kernel โ”‚ -โ”‚ (ObjectOS Runtime) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ฒ - โ”‚ - โ”‚ Plugin Lifecycle Hooks - โ”‚ (onInstall, onEnable, onDisable) - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ โ”‚ - โ–ผ โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Plugin: CRM โ”‚ โ”‚ Plugin: BI โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ€ข Objects โ”‚ โ”‚ โ€ข Objects โ”‚ -โ”‚ - Account โ”‚ โ”‚ - Report โ”‚ -โ”‚ - Contact โ”‚ โ”‚ - Dataset โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ€ข Views โ”‚ โ”‚ โ€ข Views โ”‚ -โ”‚ - AccountList โ”‚ โ”‚ - ReportBuilder โ”‚ -โ”‚ - ContactForm โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Actions โ”‚ -โ”‚ โ€ข Dashboards โ”‚ โ”‚ - ExportToExcel โ”‚ -โ”‚ - SalesPipeline โ”‚ โ”‚ - ScheduleReportโ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ€ข APIs โ”‚ โ”‚ โ€ข Drivers โ”‚ -โ”‚ - /convert-lead โ”‚ โ”‚ - driver-excel โ”‚ -โ”‚ โ”‚ โ”‚ - driver-bigqueryโ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Each plugin: -1. Declares manifest (objectstack.config.ts) -2. Exports objects, views, dashboards, etc. -3. Implements lifecycle hooks (optional) -4. Receives runtime context (ctx.ql, ctx.os, ctx.logger) -5. Can extend existing objects (add fields) -6. Can register custom field widgets -``` - ---- - -## ๐Ÿ“ฆ Package Types & Microkernel Architecture - -ObjectStack follows a **microkernel architecture** where different package types serve distinct roles in the system lifecycle. The `type` field in the manifest (`objectstack.config.ts`) determines a package's role and initialization order. - -### Package Type Hierarchy - -``` -External Request (Browser/Mobile) - โ”‚ - โ–ผ -[ adapter ] โ†โ”€ HTTP Server Container (Express, Hono, Fastify, Serverless) - โ”‚ โ€ข Role: Runtime host/container - โ”‚ โ€ข Cardinality: Singleton (one per runtime) - โ”‚ โ€ข Examples: @objectstack/adapter-express, @objectstack/adapter-hono - โ–ผ -[ gateway ] โ†โ”€ API Protocol Layer (GraphQL, REST, RPC, OData) - โ”‚ โ€ข Role: Protocol translation - โ”‚ โ€ข Cardinality: Multiple (can coexist) - โ”‚ โ€ข Examples: @objectstack/gateway-graphql, @objectstack/gateway-rest - โ–ผ -[ Kernel ] โ†โ”€ Core orchestration (ObjectOS Runtime) - โ”‚ - โ–ผ -[ objectql] โ†โ”€ Core Data Engine - โ”‚ โ€ข Role: Query engine and business logic layer - โ”‚ โ€ข Examples: @objectstack/objectql - โ–ผ -[ driver ] โ†โ”€ Southbound: Database/External Service Adapters - โ”‚ โ€ข Role: Data persistence and external integrations - โ”‚ โ€ข Examples: @objectstack/driver-postgres, @objectstack/driver-mongodb - โ–ผ - Database -``` - -### Package Type Definitions - -| Type | Description | Cardinality | Layer | Examples | -|:-----|:------------|:------------|:------|:---------| -| **adapter** | Runtime container - HTTP server adapter | Singleton | Outermost | Express, Hono, Fastify, Lambda | -| **gateway** | API protocol entry point | Multiple | North | GraphQL, REST, RPC, OData | -| **objectql** | Core data engine implementation | Singleton | Core | Query engine, business logic | -| **driver** | Database/external service adapter | Multiple | South | Postgres, MongoDB, S3, Salesforce | -| **plugin** | General-purpose functionality extension | Multiple | App | CRM, BI, Analytics | -| **app** | Business application package | Multiple | App | Sales App, Service App | -| **module** | Reusable code library/shared module | Multiple | Lib | Utilities, helpers | - -### Lifecycle Ordering - -The kernel initializes packages in a specific order to ensure proper dependency resolution: - -1. **Adapter** preparation (HTTP server setup) -2. **ObjectQL** engine initialization (core data layer) -3. **Driver** connections (database, external services) -4. **Gateway** registration (API protocol handlers) -5. **App/Plugin** loading (business logic) - -This ordering ensures that: -- The HTTP server is ready before routes are registered -- The data engine is initialized before drivers connect -- Drivers are connected before gateways need to query data -- Gateways are ready before apps register business endpoints - -### Adapter vs Gateway Distinction - -**Key Architectural Difference:** - -- **Adapter** = The "what" and "where" (which HTTP framework, which runtime environment) - - Handles raw HTTP Request/Response objects - - Manages server lifecycle (listen, close) - - One adapter per runtime instance - - Cannot coexist (can't run Express + Hono on same port) - -- **Gateway** = The "how" (which API protocol) - - Translates protocol to internal `Call` format - - Multiple gateways can coexist - - Registers routes on the adapter - - Example: Same server can expose both GraphQL and REST APIs - ---- - -## ๐Ÿ” Security & Permission Model - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Permission Evaluation Flow โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Request: user.read('account', id=123) - โ”‚ - โ”œโ”€โ”€โ–ถ Step 1: Object-Level Permission (CRUD) - โ”‚ role.zod: Does user's role allow "read" on "account"? - โ”‚ โ”œโ”€โ”€ โœ… Yes โ†’ Continue - โ”‚ โ””โ”€โ”€ โŒ No โ†’ Return 403 Forbidden - โ”‚ - โ”œโ”€โ”€โ–ถ Step 2: Sharing Rules - โ”‚ sharing.zod: Is record owned by user or shared with them? - โ”‚ โ”œโ”€โ”€ โœ… Yes โ†’ Continue - โ”‚ โ””โ”€โ”€ โŒ No โ†’ Return 404 Not Found (hide existence) - โ”‚ - โ”œโ”€โ”€โ–ถ Step 3: Field-Level Security - โ”‚ permission.zod: Which fields can user read? - โ”‚ Example: Hide "annual_revenue" for non-managers - โ”‚ โ”œโ”€โ”€ Filter out restricted fields - โ”‚ โ””โ”€โ”€ Continue with allowed fields - โ”‚ - โ”œโ”€โ”€โ–ถ Step 4: Validation Rules - โ”‚ validation.zod: Check conditional visibility - โ”‚ Example: "Show SSN only if country = USA" - โ”‚ - โ”œโ”€โ”€โ–ถ Step 5: Territory Hierarchy - โ”‚ territory.zod: Check geographic access - โ”‚ Example: "APAC sales can only see APAC accounts" - โ”‚ - โ””โ”€โ”€โ–ถ Step 6: Policy Enforcement - policy.zod: Global data access policies - Example: "No access to records older than 7 years (GDPR)" - - โœ… All checks passed โ†’ Return record with allowed fields -``` - ---- - -## ๐Ÿค– AI Integration Architecture - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ AI-Powered Features โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -1. Natural Language Query (NLQ) - User: "Show me all accounts in California with revenue > $1M" - โ”‚ - โ”œโ”€โ”€โ–ถ AI Model (GPT-4, Claude) - โ”‚ Prompt: "Convert to ObjectQL AST" - โ”‚ - โ””โ”€โ”€โ–ถ Generated AST: - { - object: "account", - filters: [ - { field: "state", operator: "=", value: "CA" }, - { field: "annual_revenue", operator: ">", value: 1000000 } - ] - } - -2. Auto-Schema Generation - User: "Create a project management app" - โ”‚ - โ”œโ”€โ”€โ–ถ AI Agent (agent.zod.ts) - โ”‚ Context: ObjectStack protocol documentation - โ”‚ - โ””โ”€โ”€โ–ถ Generated Schemas: - - object/project.ts (name, status, due_date) - - object/task.ts (title, assigned_to, project_id) - - view/project_kanban.ts - - dashboard/project_stats.ts - -3. Intelligent Suggestions - User: Creating a "Contact" object - โ”‚ - โ”œโ”€โ”€โ–ถ RAG Pipeline (rag.zod.ts) - โ”‚ Query similar objects in knowledge base - โ”‚ - โ””โ”€โ”€โ–ถ Suggestions: - - "Add 'phone' field (used in 95% of contact objects)" - - "Add lookup to 'account' (common pattern)" - - "Enable field history tracking?" - -4. Code Generation - User: "Add validation: email must be unique" - โ”‚ - โ”œโ”€โ”€โ–ถ AI Model + Protocol Knowledge - โ”‚ - โ””โ”€โ”€โ–ถ Generated validation.zod.ts: - { - name: "unique_email", - condition: "!DUPLICATE(email)", - errorMessage: "Email already exists", - active: true - } -``` - ---- - -## ๐Ÿš€ Deployment Topologies - -### Topology 1: Monolith (Single Server) -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Single VM/Container โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ ObjectStack Kernel โ”‚ โ”‚ -โ”‚ โ”‚ (ObjectOS + All Plugins) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ PostgreSQL Database โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Use Case: Small teams, prototyping, local development -``` - -### Topology 2: Multi-Tenant SaaS -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Load Balancer (NGINX) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ - โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Kernel โ”‚ โ”‚ Kernel โ”‚ โ”‚ Kernel โ”‚ โ—€โ”€โ”€ Stateless - โ”‚ #1 โ”‚ โ”‚ #2 โ”‚ โ”‚ #3 โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ PostgreSQL (Multi-tenant) โ”‚ - โ”‚ โ€ข tenant_id on every table โ”‚ - โ”‚ โ€ข Row-level security (RLS) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Redis (Session, Cache) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Use Case: SaaS providers, high availability -``` - -### Topology 3: Microservices (Enterprise) -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ API Gateway (Kong) โ”‚ -โ”‚ Rate Limiting, Auth, Routing โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ โ”‚ - โ–ผ โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Data โ”‚ โ”‚ Auth โ”‚ โ”‚ Flow โ”‚ โ”‚Workflowโ”‚ - โ”‚Service โ”‚ โ”‚Service โ”‚ โ”‚ Engine โ”‚ โ”‚ Engine โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Event Bus (Kafka) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚Postgresโ”‚ โ”‚ Redis โ”‚ โ”‚ S3 โ”‚ - โ”‚ (Data) โ”‚ โ”‚(Cache) โ”‚ โ”‚(Files) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Use Case: Large enterprises, high scale, service isolation -``` - ---- - -## ๐Ÿ“Š Protocol Dependency Graph - -``` - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ manifest โ”‚ (Root - defines app) - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ object โ”‚ โ”‚ app โ”‚ โ”‚ datasourceโ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ” โ”‚ โ””โ”€โ”€โ–ถ driver - โ–ผ โ–ผ โ–ผ โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ” โ”‚ - โ”‚fieldโ”‚ โ”‚permโ”‚ โ”‚flowโ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”˜ โ”‚ - โ”‚ โ”‚ โ”‚ โ”‚ - โ–ผ โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ validation, workflow โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ query โ”‚ (AST - universal query language) - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Dependencies (imports): -โ€ข object.zod.ts imports field.zod.ts -โ€ข validation.zod.ts imports field.zod.ts -โ€ข permission.zod.ts imports object.zod.ts -โ€ข app.zod.ts imports object.zod.ts, dashboard.zod.ts -โ€ข manifest.zod.ts imports object.zod.ts, app.zod.ts, datasource.zod.ts -``` - ---- - -## ๐ŸŒ Cross-Platform Rendering - -``` - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ ObjectUI Protocol โ”‚ - โ”‚ (Platform Agnostic) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Web โ”‚ โ”‚ Mobile โ”‚ โ”‚ Desktop โ”‚ - โ”‚ Renderer โ”‚ โ”‚ Renderer โ”‚ โ”‚ Renderer โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ - โ–ผ โ–ผ โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ React โ”‚ โ”‚ React โ”‚ โ”‚ Electron โ”‚ - โ”‚ +Tailwindโ”‚ โ”‚ Native โ”‚ โ”‚ +React โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -Same Protocol โ†’ Different Renderers: -โ€ข view.zod โ†’ React grid component (Web) -โ€ข view.zod โ†’ FlatList component (Mobile) -โ€ข view.zod โ†’ Electron table widget (Desktop) -``` - ---- - -**For more details, see:** -- [DEVELOPMENT_ROADMAP.md](./internal/planning/DEVELOPMENT_ROADMAP.md) - Complete development plan -- [PRIORITIES.md](./internal/planning/PRIORITIES.md) - What to work on next -- [packages/spec/README.md](./packages/spec/README.md) - Technical documentation diff --git a/MINI_KERNEL_ARCHITECTURE.md b/MINI_KERNEL_ARCHITECTURE.md deleted file mode 100644 index e1ae122f9..000000000 --- a/MINI_KERNEL_ARCHITECTURE.md +++ /dev/null @@ -1,382 +0,0 @@ -# ObjectStack MiniKernel ๆžถๆž„ๅ›พ - -## 1. ๆ€ปไฝ“ๆžถๆž„ (Overall Architecture) - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Application Layer โ”‚ -โ”‚ (Business Logic, User Plugins, Custom Integrations) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Plugin Layer โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ ObjectQL โ”‚ โ”‚ Driver โ”‚ โ”‚ Hono โ”‚ โ”‚ Flow โ”‚ โ”‚ -โ”‚ โ”‚ Plugin โ”‚ โ”‚ Plugin โ”‚ โ”‚ Server โ”‚ โ”‚ Engine โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ REST โ”‚ โ”‚ GraphQL โ”‚ โ”‚ Cache โ”‚ โ”‚ Auth โ”‚ โ”‚ -โ”‚ โ”‚ API โ”‚ โ”‚ API โ”‚ โ”‚ Plugin โ”‚ โ”‚ Plugin โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectKernel (MiniKernel) โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Service โ”‚ โ”‚ Lifecycle โ”‚ โ”‚ Hook โ”‚ โ”‚ -โ”‚ โ”‚ Registry โ”‚ โ”‚ Management โ”‚ โ”‚ System โ”‚ โ”‚ -โ”‚ โ”‚ (DI) โ”‚ โ”‚ (init/start) โ”‚ โ”‚ (Events) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Dependency Resolution (Topological Sort) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Infrastructure โ”‚ -โ”‚ (Node.js Runtime, TypeScript, Zod, etc.) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## 2. ๆ’ไปถ็”Ÿๅ‘ฝๅ‘จๆœŸ (Plugin Lifecycle) - -``` - IDLE - โ”‚ - โ–ผ - use(plugin) โ”€โ”€โ”€โ”€โ” - โ”‚ โ”‚ - โ”‚ โ”‚ (ๅฏไปฅๆณจๅ†Œๅคšไธชๆ’ไปถ) - โ”‚ โ”‚ - โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - bootstrap() - โ”‚ - โ”œโ”€โ”€โ”€ Phase 1: INIT โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ (ๆŒ‰ไพ่ต–้กบๅบ) โ”‚ - โ”‚ โ”‚ - โ”‚ Plugin A: init(ctx) โ”‚ - โ”‚ โ”œโ”€ ctx.registerService('a') โ”‚ - โ”‚ โ””โ”€ ๅ‡†ๅค‡่ต„ๆบ โ”‚ - โ”‚ โ”‚ - โ”‚ Plugin B: init(ctx) โ”‚ - โ”‚ โ”œโ”€ ctx.registerService('b') โ”‚ - โ”‚ โ””โ”€ ctx.getService('a') โ”‚ - โ”‚ โ”‚ - โ”‚ Plugin C: init(ctx) โ”‚ - โ”‚ โ””โ”€ ctx.getService('b') โ”‚ - โ”‚ โ”‚ - โ”œโ”€โ”€โ”€ Phase 2: START โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค - โ”‚ (ๆŒ‰ไพ่ต–้กบๅบ) โ”‚ - โ”‚ โ”‚ - โ”‚ Plugin A: start(ctx) โ”‚ - โ”‚ โ”œโ”€ ๅฏๅŠจๆœๅŠกๅ™จ โ”‚ - โ”‚ โ””โ”€ ่ฟžๆŽฅๆ•ฐๆฎๅบ“ โ”‚ - โ”‚ โ”‚ - โ”‚ Plugin B: start(ctx) โ”‚ - โ”‚ โ””โ”€ ๆณจๅ†Œ่ทฏ็”ฑ โ”‚ - โ”‚ โ”‚ - โ”‚ Plugin C: start(ctx) โ”‚ - โ”‚ โ””โ”€ ๅฏๅŠจๅฎšๆ—ถไปปๅŠก โ”‚ - โ”‚ โ”‚ - โ”œโ”€โ”€โ”€ Phase 3: KERNEL READY โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค - โ”‚ โ”‚ - โ”‚ trigger('kernel:ready') โ”‚ - โ”‚ โ”œโ”€ Hook Handler 1 โ”‚ - โ”‚ โ”œโ”€ Hook Handler 2 โ”‚ - โ”‚ โ””โ”€ Hook Handler 3 โ”‚ - โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - RUNNING - โ”‚ - โ–ผ - shutdown() - โ”‚ - โ”œโ”€โ”€โ”€ DESTROY (ๅๅ‘้กบๅบ) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ โ”‚ - โ”‚ Plugin C: destroy() โ”‚ - โ”‚ Plugin B: destroy() โ”‚ - โ”‚ Plugin A: destroy() โ”‚ - โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - STOPPED -``` - -## 3. ๆœๅŠกๆณจๅ†Œ่กจ (Service Registry) - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ PluginContext โ”‚ -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Service Registry (Map) โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Service Name โ”‚ Service Instance โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ 'objectql' โ”‚ ObjectQL Instance โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ 'db' โ”‚ Database Connection โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ 'http-server'โ”‚ Hono App Instance โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ 'cache' โ”‚ Cache Manager โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ 'logger' โ”‚ Winston Logger โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Methods: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข registerService(name, service) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข getService(name): T โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ”‚ Plugin A Plugin B โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ init() โ”‚โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ start() โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ register โ”‚ โ”‚ consume โ”‚ -โ”‚ Service โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ–ผ โ–ผ โ”‚ -โ”‚ registerService getService โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## 4. ไพ่ต–่งฃๆž (Dependency Resolution) - -``` -ๆณจๅ†Œ้กบๅบ (Registration Order): -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚Plugin Cโ”‚โ†’ โ”‚Plugin Bโ”‚โ†’ โ”‚Plugin Aโ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ - โ”‚ โ”‚ โ””โ”€โ”€ dependencies: [] - โ”‚ โ””โ”€โ”€ dependencies: ['plugin-a'] - โ””โ”€โ”€ dependencies: ['plugin-b'] - -ไพ่ต–ๅ›พ (Dependency Graph): - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚Plugin Aโ”‚ (ๆ— ไพ่ต–) - โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜ - โ”‚ depends on - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚Plugin Bโ”‚ - โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜ - โ”‚ depends on - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚Plugin Cโ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -ๆ‹“ๆ‰‘ๆŽ’ๅบๅŽ็š„ๅˆๅง‹ๅŒ–้กบๅบ (Topological Sort): -1. Plugin A (init โ†’ start) -2. Plugin B (init โ†’ start) -3. Plugin C (init โ†’ start) - -้”™่ฏฏๆฃ€ๆต‹ (Error Detection): -ๅพช็Žฏไพ่ต–: -A โ†’ B โ†’ C โ†’ A โŒ Error: Circular dependency - -็ผบๅคฑไพ่ต–: -A requires 'non-existent' โŒ Error: Dependency not found -``` - -## 5. ้’ฉๅญ็ณป็ปŸ (Hook System) - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Hook Registry (Map) โ”‚ -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Hook Name โ”‚ Handlers (Array) โ”‚ โ”‚ -โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ -โ”‚ โ”‚ 'kernel:ready' โ”‚ [handler1, handler2, ...] โ”‚ โ”‚ -โ”‚ โ”‚ 'data:insert' โ”‚ [validator, logger, ...] โ”‚ โ”‚ -โ”‚ โ”‚ 'http:request' โ”‚ [auth, cors, ...] โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -ไบ‹ไปถๆต (Event Flow): - -Plugin A Plugin B Plugin C - โ”‚ โ”‚ โ”‚ - โ”‚ ctx.hook('event') โ”‚ โ”‚ - โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚ โ”‚ - โ”‚ โ”‚ โ”‚ - โ”‚ โ”‚ ctx.hook('event') โ”‚ - โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚ - โ”‚ โ”‚ โ”‚ - โ”‚ โ”‚ - โ”‚ ctx.trigger('event', data) โ”‚ - โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ - โ”‚ โ”‚ โ”‚ - โ”‚ handler1(data) โ”‚ - โ”‚ โ”‚ โ”‚ - โ”‚ handler2(data) โ”‚ - โ”‚ โ”‚ โ”‚ - โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ -``` - -## 6. ObjectQL ๆ’ไปถๅŒ– (ObjectQL as Plugin) - -``` -Plugin-based Architecture: -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectKernel โ”‚ -โ”‚ (MiniKernel) โ”‚ -โ”‚ โ”‚ -โ”‚ Service Registry: โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ 'objectql' โ”‚ โ”‚ โ† ๆณจๅ†ŒไธบๆœๅŠก -โ”‚ โ”‚ โ†’ ObjectQL โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ฒ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ ObjectQL โ”‚ - โ”‚ Plugin โ”‚ โ† ๅฏๆ›ฟๆข็š„ๆ’ไปถ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -ไผ˜ๅŠฟ: -1. โœ… ObjectQL ๅฏไปฅ่ขซๆ›ฟๆข -2. โœ… ๅฏไปฅๆไพ›่‡ชๅฎšไน‰ ObjectQL ๅฎžไพ‹ -3. โœ… ๆต‹่ฏ•ๆ—ถๅฏไปฅ Mock -4. โœ… ๆ’ไปถ้—ดๅนณ็ญ‰ๅ…ณ็ณป -``` - -## 7. ๅฎž้™…ๅบ”็”จ็คบไพ‹ (Real-world Example) - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectKernel โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ โ”‚ โ”‚ - โ–ผ โ–ผ โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ ObjectQL โ”‚ โ”‚ Memory โ”‚ โ”‚ Hono โ”‚ -โ”‚ Plugin โ”‚ โ”‚ Driver โ”‚ โ”‚ Server โ”‚ -โ”‚ โ”‚ โ”‚ Plugin โ”‚ โ”‚ Plugin โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ โ”‚ โ”‚ - โ”‚ init: โ”‚ init: โ”‚ init: - โ”‚ register โ”‚ get objectql โ”‚ register - โ”‚ 'objectql' โ”‚ register driver โ”‚ 'http-server' - โ”‚ โ”‚ โ”‚ - โ”‚ start: โ”‚ โ”‚ start: - โ”‚ init engine โ”‚ โ”‚ setup routes - โ”‚ โ”‚ โ”‚ listen on port - โ”‚ โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - trigger('kernel:ready') - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Server Starts โ”‚ - โ”‚ on Port 3000 โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## 8. ๆ’ไปถ้€šไฟกๆจกๅผ (Plugin Communication Patterns) - -``` -ๆจกๅผ 1: ๆœๅŠกๆณจๅ†ŒไธŽๆถˆ่ดน (Service Registry) -โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ -Provider Plugin Consumer Plugin - โ”‚ โ”‚ - โ”‚ init() โ”‚ - โ”œโ”€ registerService() โ”‚ - โ”‚ โ”‚ - โ”‚ start() - โ”‚ โ”œโ”€ getService() - โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - -ๆจกๅผ 2: ไบ‹ไปถ้’ฉๅญ (Event Hooks) -โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ -Publisher Plugin Subscriber Plugin - โ”‚ โ”‚ - โ”‚ init() - โ”‚ โ”œโ”€ hook('event') - โ”‚ โ”‚ - โ”‚ start() โ”‚ - โ”œโ”€ trigger('event') โ”‚ - โ”‚ โ”‚ โ”‚ - โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚ - โ”‚ handler() - โ”‚ โ”‚ - -ๆจกๅผ 3: ไพ่ต–ๅฃฐๆ˜Ž (Dependency Declaration) -โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ -Plugin A Plugin B -dependencies: [] dependencies: ['plugin-a'] - โ”‚ โ”‚ - โ”‚ init() โ”‚ - โ”‚ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - (Kernel ไฟ่ฏ A ๅ…ˆๅˆๅง‹ๅŒ–) -``` - -## 9. ๆ‰ฉๅฑ•่ทฏๅพ„ (Extension Paths) - -``` -ๅฝ“ๅ‰ๆžถๆž„ (Current): -ObjectKernel โ†’ Plugin Interface โ†’ Built-in Plugins - -ๆœชๆฅๆ‰ฉๅฑ• (Future): - -1. ้…็ฝฎๅŒ–ๅŠ ่ฝฝ (Config-based Loading) - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ objectstack.config โ”‚ - โ”‚ { โ”‚ - โ”‚ plugins: [ โ”‚ - โ”‚ "objectql", โ”‚ - โ”‚ "hono-server", โ”‚ - โ”‚ "my-plugin" โ”‚ - โ”‚ ] โ”‚ - โ”‚ } โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - Kernel.loadFromConfig() - -2. ๆ’ไปถๅธ‚ๅœบ (Plugin Marketplace) - npm install @company/custom-plugin - โ”‚ - โ–ผ - kernel.use(CustomPlugin) - -3. ็ƒญๅŠ ่ฝฝ (Hot Reload) - kernel.reload('plugin-name') - โ”‚ - โ–ผ - destroy() โ†’ init() โ†’ start() - -4. ๆฒ™็ฎฑ้š”็ฆป (Sandboxing) - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ User Script โ”‚ - โ”‚ (Isolated VM) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## License - -Apache-2.0 diff --git a/MINI_KERNEL_GUIDE.md b/MINI_KERNEL_GUIDE.md deleted file mode 100644 index f1ffa8a4a..000000000 --- a/MINI_KERNEL_GUIDE.md +++ /dev/null @@ -1,344 +0,0 @@ -# MiniKernel Architecture Guide - -## Overview - -ObjectStack now supports a **MiniKernel (Microkernel) Architecture** that provides: - -- **High Modularity**: Business logic is completely separated into plugins -- **Dependency Injection**: Service registry for inter-plugin communication -- **Event/Hook System**: Publish-subscribe mechanism for loose coupling -- **Lifecycle Management**: Standardized init/start/destroy phases -- **Dependency Resolution**: Automatic topological sorting based on plugin dependencies - -## Core Concepts - -### 1. Kernel - -The `ObjectKernel` is a minimal orchestrator that: -- Loads and manages plugins -- Provides a shared context (`PluginContext`) -- Handles lifecycle phases (init โ†’ start โ†’ running) -- Resolves plugin dependencies automatically - -### 2. Plugin - -Plugins are independent modules with a standard interface: - -```typescript -interface Plugin { - name: string; // Unique identifier - version?: string; // Plugin version - dependencies?: string[]; // List of required plugin names - - init(ctx: PluginContext): Promise; // Register services - start?(ctx: PluginContext): Promise; // Execute business logic - destroy?(): Promise; // Cleanup -} -``` - -### 3. PluginContext - -The context provides plugins access to: -- **Service Registry**: `registerService()`, `getService()` -- **Event System**: `hook()`, `trigger()` -- **Logger**: Console-based logging - -## Plugin Lifecycle - -``` -1. INIT PHASE - โ”œโ”€โ”€ Plugin A: init() โ†’ Register services - โ”œโ”€โ”€ Plugin B: init() โ†’ Register services - โ””โ”€โ”€ Plugin C: init() โ†’ Register services - -2. START PHASE - โ”œโ”€โ”€ Plugin A: start() โ†’ Execute business logic - โ”œโ”€โ”€ Plugin B: start() โ†’ Execute business logic - โ””โ”€โ”€ Plugin C: start() โ†’ Execute business logic - -3. KERNEL READY - โ””โ”€โ”€ Trigger 'kernel:ready' hook - -4. DESTROY PHASE (on shutdown) - โ”œโ”€โ”€ Plugin C: destroy() โ†’ Cleanup - โ”œโ”€โ”€ Plugin B: destroy() โ†’ Cleanup - โ””โ”€โ”€ Plugin A: destroy() โ†’ Cleanup -``` - -## Basic Usage - -### Example 1: Simple Plugin - -```typescript -import { ObjectKernel, Plugin, PluginContext } from '@objectstack/runtime'; - -class HelloPlugin implements Plugin { - name = 'hello-plugin'; - - async init(ctx: PluginContext) { - ctx.logger.log('[HelloPlugin] Initialized'); - } - - async start(ctx: PluginContext) { - ctx.logger.log('[HelloPlugin] Started'); - } -} - -const kernel = new ObjectKernel(); -kernel.use(new HelloPlugin()); -await kernel.bootstrap(); -``` - -### Example 2: Service Registration - -```typescript -class DataEnginePlugin implements Plugin { - name = 'data-engine'; - - async init(ctx: PluginContext) { - const db = { - connect: () => console.log('DB Connected'), - query: (sql: string) => `Result for ${sql}` - }; - - // Register service for other plugins - ctx.registerService('db', db); - } - - async start(ctx: PluginContext) { - const db = ctx.getService('db'); - db.connect(); - } -} -``` - -### Example 3: Plugin Dependencies - -```typescript -class ApiPlugin implements Plugin { - name = 'api-server'; - dependencies = ['data-engine', 'http-server']; // Will load after these - - async init(ctx: PluginContext) { - // Dependencies guaranteed to be initialized - } - - async start(ctx: PluginContext) { - const db = ctx.getService('db'); - const server = ctx.getService('http-server'); - - // Use services from other plugins - server.get('/api/data', () => db.query('SELECT *')); - } -} -``` - -### Example 4: Hook System - -```typescript -class ServerPlugin implements Plugin { - name = 'server'; - - async start(ctx: PluginContext) { - // Wait for kernel:ready before starting server - ctx.hook('kernel:ready', () => { - console.log('Starting HTTP server on port 3000'); - }); - } -} -``` - -## ObjectQL as a Plugin - -ObjectQL is now a first-class plugin: - -```typescript -import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); - -kernel - .use(new ObjectQLPlugin()) // Register ObjectQL engine - .use(new DriverPlugin(memoryDriver, 'memory')); // Register driver - -await kernel.bootstrap(); - -// Access ObjectQL via service registry -const objectql = kernel.getService('objectql'); -``` - -## Built-in Plugins - -### ObjectQLPlugin - -Registers the ObjectQL engine as a service. - -```typescript -new ObjectQLPlugin() // Default instance -new ObjectQLPlugin(customQL) // Custom instance -new ObjectQLPlugin(undefined, { env: 'prod' }) // With context -``` - -**Services**: `objectql` - -### DriverPlugin - -Registers a driver with ObjectQL. - -```typescript -new DriverPlugin(driver, 'driver-name') -``` - -**Dependencies**: `['com.objectstack.engine.objectql']` - -### HonoServerPlugin - -Provides HTTP server using Hono framework. - -```typescript -new HonoServerPlugin({ port: 3000, staticRoot: './public' }) -``` - -**Services**: `http-server` - -## Advanced Patterns - -### Pattern 1: Configuration-Based Loading - -```typescript -interface KernelConfig { - plugins: Array<{ - name: string; - enabled: boolean; - options?: any; - }>; -} - -async function loadFromConfig(config: KernelConfig) { - const kernel = new ObjectKernel(); - - for (const pluginCfg of config.plugins) { - if (pluginCfg.enabled) { - const plugin = await loadPlugin(pluginCfg.name, pluginCfg.options); - kernel.use(plugin); - } - } - - return kernel; -} -``` - -### Pattern 2: Plugin Factory - -```typescript -class PluginFactory { - static createDataEngine(driver: any) { - return { - name: 'data-engine', - async init(ctx: PluginContext) { - ctx.registerService('driver', driver); - } - } as Plugin; - } -} - -kernel.use(PluginFactory.createDataEngine(myDriver)); -``` - -### Pattern 3: Conditional Plugin Loading - -```typescript -const kernel = new ObjectKernel(); - -// Core plugins -kernel.use(new ObjectQLPlugin()); - -// Optional plugins based on environment -if (process.env.NODE_ENV === 'production') { - kernel.use(new MonitoringPlugin()); - kernel.use(new CachingPlugin()); -} - -if (process.env.ENABLE_API === 'true') { - kernel.use(new HonoServerPlugin()); -} -``` - -## Usage - -```typescript -import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); - -kernel - .use(new ObjectQLPlugin()) - .use(new DriverPlugin(driver)); - -// App manifest as plugin -kernel.use(appManifestPlugin); - -await kernel.bootstrap(); -``` - -## Benefits - -1. **True Modularity**: Each plugin is independent and reusable -2. **Testability**: Mock services easily in tests -3. **Flexibility**: Load plugins conditionally -4. **Extensibility**: Add new plugins without modifying kernel -5. **Clear Dependencies**: Explicit dependency declarations -6. **Better Architecture**: Separation of concerns - -## Best Practices - -1. **Keep plugins focused**: One responsibility per plugin -2. **Use services**: Share functionality via service registry -3. **Declare dependencies**: Make plugin requirements explicit -4. **Use hooks**: Decouple plugins with event system -5. **Handle errors**: Implement proper error handling in lifecycle methods -6. **Document services**: Document what services your plugin provides/consumes - -## Troubleshooting - -### Error: "Service 'xxx' not found" - -Make sure the plugin that provides the service is registered and loaded before plugins that consume it. - -### Error: "Circular dependency detected" - -Check your plugin dependencies - they form a cycle. Refactor to break the cycle. - -### Error: "Plugin 'xxx' already registered" - -You're registering the same plugin twice. Check your plugin registration code. - -## API Reference - -### ObjectKernel - -- `use(plugin: Plugin)`: Register a plugin -- `bootstrap()`: Initialize and start all plugins -- `shutdown()`: Stop all plugins in reverse order -- `getService(name: string)`: Get a service from registry -- `isRunning()`: Check if kernel is running -- `getState()`: Get current kernel state - -### PluginContext - -- `registerService(name: string, service: any)`: Register a service -- `getService(name: string)`: Get a service -- `hook(name: string, handler: Function)`: Register event handler -- `trigger(name: string, ...args: any[])`: Trigger an event -- `logger`: Console logger instance - -## Examples - -See: -- `/examples/mini-kernel-example.ts` - Basic usage -- `/test-objectql-plugin.ts` - ObjectQL plugin examples -- `/packages/plugin-hono-server/src/hono-plugin.ts` - Real plugin implementation - -## License - -Apache-2.0 diff --git a/MINI_KERNEL_IMPLEMENTATION.md b/MINI_KERNEL_IMPLEMENTATION.md deleted file mode 100644 index 4af868c18..000000000 --- a/MINI_KERNEL_IMPLEMENTATION.md +++ /dev/null @@ -1,359 +0,0 @@ -# ObjectStack MiniKernel Architecture - Implementation Summary - -## ๆฆ‚่ฟฐ (Overview) - -ๆœฌๆฌกๅฎž็Žฐๅฐ† ObjectStack ๆ”น้€ ไธบๅŸบไบŽ**ๅพฎๅ†…ๆ ธ (MiniKernel)** ็š„ๆ’ไปถๅŒ–ๆžถๆž„๏ผŒๅฎž็Žฐไบ†ไปฅไธ‹ๆ ธๅฟƒ็›ฎๆ ‡๏ผš - -1. **้ซ˜ๅบฆๆจกๅ—ๅŒ–**: ไธšๅŠก้€ป่พ‘ๅฎŒๅ…จๅ‰ฅ็ฆปๅˆฐๆ’ไปถไธญ -2. **ไพ่ต–ๆณจๅ…ฅ (DI)**: ้€š่ฟ‡ๆœๅŠกๆณจๅ†Œ่กจๅฎž็Žฐๆ’ไปถ้—ด้€šไฟก -3. **็”Ÿๅ‘ฝๅ‘จๆœŸ็ฎก็†**: ๆ ‡ๅ‡†ๅŒ–็š„ init โ†’ start โ†’ destroy ๆต็จ‹ -4. **ไบ‹ไปถ/้’ฉๅญๆœบๅˆถ**: ๆพ่€ฆๅˆ็š„ๆ’ไปถ้€šไฟกๆ–นๅผ -5. **ObjectQL ๆ’ไปถๅŒ–**: ๆ•ฐๆฎๅผ•ๆ“Žๆˆไธบๅฏๆ›ฟๆข็š„ๆ’ไปถ - -## ๆ ธๅฟƒ็ป„ไปถ (Core Components) - -### 1. ObjectKernel (MiniKernel) - -**ๆ–‡ไปถไฝ็ฝฎ**: `packages/runtime/src/mini-kernel.ts` - -**ๅŠŸ่ƒฝ**: -- ๆ’ไปถ็”Ÿๅ‘ฝๅ‘จๆœŸ็ฎก็† -- ๆœๅŠกๆณจๅ†Œ่กจ (Service Registry) -- ไบ‹ไปถ้’ฉๅญ็ณป็ปŸ (Hook System) -- ไพ่ต–่งฃๆž (ๆ‹“ๆ‰‘ๆŽ’ๅบ) - -**ไธป่ฆๆ–นๆณ•**: -```typescript -class ObjectKernel { - use(plugin: Plugin): ObjectKernel - bootstrap(): Promise - shutdown(): Promise - getService(name: string): T -} -``` - -### 2. Plugin Interface - -**ๆ–‡ไปถไฝ็ฝฎ**: `packages/runtime/src/types.ts` - -**ๅฎšไน‰**: -```typescript -interface Plugin { - name: string; - version?: string; - dependencies?: string[]; - - init(ctx: PluginContext): Promise; - start?(ctx: PluginContext): Promise; - destroy?(): Promise; -} -``` - -**็”Ÿๅ‘ฝๅ‘จๆœŸ**: -1. **init**: ๆณจๅ†ŒๆœๅŠกใ€ๅ‡†ๅค‡่ต„ๆบ -2. **start**: ๆ‰ง่กŒไธšๅŠก้€ป่พ‘ใ€ๅฏๅŠจๆœๅŠกๅ™จ -3. **destroy**: ๆธ…็†่ต„ๆบใ€ๅ…ณ้—ญ่ฟžๆŽฅ - -### 3. PluginContext - -**ๅŠŸ่ƒฝ**: ไธบๆ’ไปถๆไพ›่ฟ่กŒๆ—ถไธŠไธ‹ๆ–‡ - -**ไธป่ฆๆ–นๆณ•**: -```typescript -interface PluginContext { - registerService(name: string, service: any): void; - getService(name: string): T; - hook(name: string, handler: Function): void; - trigger(name: string, ...args: any[]): Promise; - logger: Console; -} -``` - -## ๆ ธๅฟƒๆ’ไปถ (Built-in Plugins) - -### 1. ObjectQLPlugin - -**ๆ–‡ไปถไฝ็ฝฎ**: `packages/runtime/src/objectql-plugin.ts` - -**ๅŠŸ่ƒฝ**: ๅฐ† ObjectQL ๆ•ฐๆฎๅผ•ๆ“Žๆณจๅ†ŒไธบๆœๅŠก - -**ๆœๅŠก**: `'objectql'` - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -kernel.use(new ObjectQLPlugin()); -// ๆˆ– -kernel.use(new ObjectQLPlugin(customQL)); -``` - -### 2. DriverPlugin - -**ๆ–‡ไปถไฝ็ฝฎ**: `packages/runtime/src/driver-plugin.ts` - -**ๅŠŸ่ƒฝ**: ๅฐ†ๆ•ฐๆฎ้ฉฑๅŠจๅ™จๅŒ…่ฃ…ไธบๆ’ไปถ - -**ไพ่ต–**: `['com.objectstack.engine.objectql']` - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -kernel.use(new DriverPlugin(memoryDriver, 'memory')); -``` - -### 3. HonoServerPlugin (ๅทฒๆ›ดๆ–ฐ) - -**ๆ–‡ไปถไฝ็ฝฎ**: `packages/plugin-hono-server/src/hono-plugin.ts` - -**ๅŠŸ่ƒฝ**: HTTP ๆœๅŠกๅ™จๆ’ไปถ - -**ๆœๅŠก**: `'http-server'` - -**ๆ›ดๆ–ฐๅ†…ๅฎน**: -- ๅฎž็Žฐๆ–ฐ็š„ Plugin ๆŽฅๅฃ -- ไฟๆŒๅ‘ๅŽๅ…ผๅฎน -- ไฝฟ็”จๆœๅŠกๆณจๅ†Œ่กจ - -## ๆžถๆž„ไผ˜ๅŠฟ (Benefits) - -### 1. ็œŸๆญฃ็š„ๆจกๅ—ๅŒ– - -- ๆฏไธชๆ’ไปถ็‹ฌ็ซ‹ๅผ€ๅ‘ใ€ๆต‹่ฏ•ใ€้ƒจ็ฝฒ -- ๆ’ไปถๅฏไปฅๆŒ‰้œ€ๅŠ ่ฝฝ/ๅธ่ฝฝ -- ๆธ…ๆ™ฐ็š„ไพ่ต–ๅ…ณ็ณป - -### 2. ็ตๆดปๆ€ง - -- ๆ”ฏๆŒ้…็ฝฎๅŒ–ๅŠ ่ฝฝๆ’ไปถ -- ๅฏไปฅๆกไปถๆ€งๅŠ ่ฝฝๆ’ไปถ -- ๆ˜“ไบŽๆ‰ฉๅฑ•ๆ–ฐๅŠŸ่ƒฝ - -### 3. ๅฏๆต‹่ฏ•ๆ€ง - -- ๆœๅŠกๅฏไปฅ่ขซ Mock -- ๆ’ไปถๅฏไปฅ็‹ฌ็ซ‹ๆต‹่ฏ• -- ไพ่ต–ๆณจๅ…ฅ็ฎ€ๅŒ–ๆต‹่ฏ• - - - -## ไฝฟ็”จ็คบไพ‹ (Usage Examples) - -### ๅŸบ็ก€็”จๆณ• - -```typescript -import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); - -kernel - .use(new ObjectQLPlugin()) - .use(new DriverPlugin(driver, 'memory')) - .use(new HonoServerPlugin({ port: 3000 })); - -await kernel.bootstrap(); -``` - -### ๆœๅŠกๆณจๅ†ŒไธŽๆถˆ่ดน - -```typescript -// Plugin A: ๆณจๅ†ŒๆœๅŠก -class DataPlugin implements Plugin { - name = 'data-plugin'; - - async init(ctx: PluginContext) { - ctx.registerService('db', myDatabase); - } -} - -// Plugin B: ๆถˆ่ดนๆœๅŠก -class ApiPlugin implements Plugin { - name = 'api-plugin'; - dependencies = ['data-plugin']; - - async start(ctx: PluginContext) { - const db = ctx.getService('db'); - // ไฝฟ็”จๆ•ฐๆฎๅบ“ๆœๅŠก - } -} -``` - -### ไฝฟ็”จ้’ฉๅญ็ณป็ปŸ - -```typescript -class ServerPlugin implements Plugin { - name = 'server'; - - async start(ctx: PluginContext) { - ctx.hook('kernel:ready', () => { - console.log('Kernel is ready, starting server...'); - server.listen(3000); - }); - } -} -``` - -## ๆ–‡ไปถ็ป“ๆž„ (File Structure) - -``` -packages/runtime/src/ -โ”œโ”€โ”€ mini-kernel.ts # ObjectKernel ๅฎž็Žฐ -โ”œโ”€โ”€ types.ts # Plugin, PluginContext ๆŽฅๅฃ -โ”œโ”€โ”€ objectql-plugin.ts # ObjectQL ๆ’ไปถ -โ”œโ”€โ”€ driver-plugin.ts # Driver ๆ’ไปถ -โ”œโ”€โ”€ protocol.ts # Runtime Protocol -โ””โ”€โ”€ index.ts # ๅฏผๅ‡บ - -MINI_KERNEL_GUIDE.md # ๅฎŒๆ•ดไฝฟ็”จๆŒ‡ๅ— -examples/mini-kernel-example.ts # ็คบไพ‹ไปฃ็  -test-mini-kernel.ts # ๆต‹่ฏ•ๅฅ—ไปถ -``` - -## ไฝฟ็”จๆŒ‡ๅ— (Usage Guide) - -### ๅˆ›ๅปบๆ–ฐๆ’ไปถ - -```typescript -import { Plugin, PluginContext } from '@objectstack/runtime'; - -class MyPlugin implements Plugin { - name = 'my-plugin'; - version = '1.0.0'; - dependencies = ['other-plugin']; // ๅฏ้€‰ - - async init(ctx: PluginContext) { - // ๆณจๅ†ŒๆœๅŠก - ctx.registerService('my-service', myService); - } - - async start(ctx: PluginContext) { - // ๅฏๅŠจไธšๅŠก้€ป่พ‘ - const otherService = ctx.getService('other-service'); - } - - async destroy() { - // ๆธ…็†่ต„ๆบ - } -} -``` - -## ๆต‹่ฏ• (Testing) - -ๆต‹่ฏ•ๆ–‡ไปถ: `test-mini-kernel.ts` - -ๅŒ…ๅซไปฅไธ‹ๆต‹่ฏ•็”จไพ‹: -1. โœ… ๅŸบ็ก€็”Ÿๅ‘ฝๅ‘จๆœŸ -2. โœ… ๆœๅŠกๆณจๅ†Œ่กจ -3. โœ… ไพ่ต–่งฃๆž -4. โœ… ้’ฉๅญ็ณป็ปŸ -5. โœ… ObjectQL ๆ’ไปถ -6. โœ… ๅคšๆ’ไปถๅไฝœ -7. โœ… ้”™่ฏฏๅค„็† - -## ไธ‹ไธ€ๆญฅ่ฎกๅˆ’ (Next Steps) - -1. **้…็ฝฎๅŒ–ๅŠ ่ฝฝ**: ไปŽ `objectstack.config.ts` ๅŠจๆ€ๅŠ ่ฝฝๆ’ไปถ -2. **ๆ›ดๅคšๅ†…็ฝฎๆ’ไปถ**: - - Flow Engine Plugin - - Cache Plugin - - Monitoring Plugin -3. **ๆ’ไปถๅธ‚ๅœบ**: ๆ”ฏๆŒ็ฌฌไธ‰ๆ–นๆ’ไปถๅ‘ๅธƒๅ’Œๅฎ‰่ฃ… -4. **ๆฒ™็ฎฑ้š”็ฆป**: ไธบ็”จๆˆท่‡ชๅฎšไน‰่„šๆœฌๆไพ›ๅฎ‰ๅ…จๆ‰ง่กŒ็Žฏๅขƒ - -## ๅ‚่€ƒๆ–‡ๆกฃ (References) - -- [MINI_KERNEL_GUIDE.md](./MINI_KERNEL_GUIDE.md) - ๅฎŒๆ•ดไฝฟ็”จๆŒ‡ๅ— -- [examples/mini-kernel-example.ts](./examples/mini-kernel-example.ts) - ็คบไพ‹ไปฃ็  -- [packages/runtime/src/mini-kernel.ts](./packages/runtime/src/mini-kernel.ts) - ๆ ธๅฟƒๅฎž็Žฐ - -## ๆŠ€ๆœฏ่ฆ็‚น (Technical Highlights) - -### ไพ่ต–่งฃๆž็ฎ—ๆณ• - -ไฝฟ็”จ**ๆ‹“ๆ‰‘ๆŽ’ๅบ (Topological Sort)** ่งฃๅ†ณๆ’ไปถไพ่ต–้—ฎ้ข˜: - -```typescript -private resolveDependencies(): Plugin[] { - const resolved: Plugin[] = []; - const visited = new Set(); - const visiting = new Set(); - - const visit = (pluginName: string) => { - if (visited.has(pluginName)) return; - if (visiting.has(pluginName)) { - throw new Error(`Circular dependency: ${pluginName}`); - } - visiting.add(pluginName); - - // Visit dependencies first - const deps = plugin.dependencies || []; - for (const dep of deps) { - visit(dep); - } - - visiting.delete(pluginName); - visited.add(pluginName); - resolved.push(plugin); - }; - - for (const pluginName of this.plugins.keys()) { - visit(pluginName); - } - - return resolved; -} -``` - -### ๆœๅŠกๆณจๅ†Œ่กจ - -ไฝฟ็”จ **Map** ๅฎž็Žฐ้ซ˜ๆ•ˆ็š„ๆœๅŠกๆณจๅ†Œๅ’ŒๆŸฅๆ‰พ: - -```typescript -private services: Map = new Map(); - -registerService(name, service) { - if (this.services.has(name)) { - throw new Error(`Service '${name}' already registered`); - } - this.services.set(name, service); -} - -getService(name: string): T { - const service = this.services.get(name); - if (!service) { - throw new Error(`Service '${name}' not found`); - } - return service as T; -} -``` - -### ้’ฉๅญๆœบๅˆถ - -ไฝฟ็”จ**ๅ‘ๅธƒ-่ฎข้˜…ๆจกๅผ**ๅฎž็Žฐไบ‹ไปถ้€šไฟก: - -```typescript -private hooks: Map = new Map(); - -hook(name, handler) { - if (!this.hooks.has(name)) { - this.hooks.set(name, []); - } - this.hooks.get(name)!.push(handler); -} - -async trigger(name, ...args) { - const handlers = this.hooks.get(name) || []; - for (const handler of handlers) { - await handler(...args); - } -} -``` - -## ่ฎพ่ฎกๅŽŸๅˆ™ (Design Principles) - -1. **ๅ•ไธ€่Œ่ดฃ**: ๅ†…ๆ ธๅช่ดŸ่ดฃ็”Ÿๅ‘ฝๅ‘จๆœŸใ€DI ๅ’Œไบ‹ไปถ๏ผŒไธๅŒ…ๅซไธšๅŠก้€ป่พ‘ -2. **ๅผ€ๆ”พๅฐ้—ญ**: ๅฏนๆ‰ฉๅฑ•ๅผ€ๆ”พ๏ผˆๆ–ฐๆ’ไปถ๏ผ‰๏ผŒๅฏนไฟฎๆ”นๅฐ้—ญ๏ผˆๅ†…ๆ ธไธๅ˜๏ผ‰ -3. **ไพ่ต–ๅ€’็ฝฎ**: ้ซ˜ๅฑ‚ๆจกๅ—ไธไพ่ต–ไฝŽๅฑ‚ๆจกๅ—๏ผŒ้ƒฝไพ่ต–ๆŠฝ่ฑก๏ผˆๆŽฅๅฃ๏ผ‰ -4. **ๆŽฅๅฃ้š”็ฆป**: ๆ’ไปถๅช้œ€ๅฎž็Žฐๅฟ…่ฆ็š„ๆŽฅๅฃ -5. **ๆœ€ๅฐๆƒŠ่ฎถ**: API ่ฎพ่ฎก็ฌฆๅˆ็›ด่ง‰๏ผŒๆ˜“ไบŽ็†่งฃๅ’Œไฝฟ็”จ - -## License - -Apache-2.0 diff --git a/MINI_KERNEL_INDEX.md b/MINI_KERNEL_INDEX.md deleted file mode 100644 index acc6ef483..000000000 --- a/MINI_KERNEL_INDEX.md +++ /dev/null @@ -1,89 +0,0 @@ -# ObjectStack MiniKernel ๆžถๆž„็ดขๅผ• - -## ๐Ÿ“š ๆ–‡ๆกฃๅฏผ่ˆช - -ๆœฌๆฌกๆžถๆž„ๆ”น้€ ๅฐ† ObjectStack ไปŽๅ•ไฝ“ๆžถๆž„่ฝฌๅ˜ไธบ**ๅพฎๅ†…ๆ ธ (MiniKernel)** ๆžถๆž„๏ผŒๅฎž็Žฐไบ†ไธšๅŠก้€ป่พ‘็š„ๅฎŒๅ…จๆ’ไปถๅŒ–ใ€‚ - -### ๆ ธๅฟƒๆ–‡ๆกฃ - -1. **[ๆžถๆž„ๅฎž็Žฐๆ€ป็ป“](./MINI_KERNEL_IMPLEMENTATION.md)** - ๅฎž็Žฐๆฆ‚่ฟฐใ€ๆ ธๅฟƒ็ป„ไปถใ€ไฝฟ็”จ็คบไพ‹ - - ๅฟซ้€Ÿไบ†่งฃ MiniKernel ๆ˜ฏไป€ไนˆ - - ๆ ธๅฟƒ็ป„ไปถ่ฏดๆ˜Ž - - ่ฟ็งปๆŒ‡ๅ— - - ๆŠ€ๆœฏ่ฆ็‚น - -2. **[ๅฎŒๆ•ดไฝฟ็”จๆŒ‡ๅ—](./MINI_KERNEL_GUIDE.md)** - ่ฏฆ็ป†็š„ API ๆ–‡ๆกฃๅ’Œๆœ€ไฝณๅฎž่ทต - - ๆฆ‚ๅฟตไป‹็ป - - ๅŸบ็ก€็”จๆณ• - - ้ซ˜็บงๆจกๅผ - - ๆ•…้šœๆŽ’ๆŸฅ - -3. **[ๆžถๆž„่ฎพ่ฎกๅ›พ](./MINI_KERNEL_ARCHITECTURE.md)** - ๅฏ่ง†ๅŒ–ๆžถๆž„ๅ›พๅ’Œๆต็จ‹ๅ›พ - - ๆ€ปไฝ“ๆžถๆž„ - - ็”Ÿๅ‘ฝๅ‘จๆœŸๆต็จ‹ - - ๆœๅŠกๆณจๅ†Œ่กจ - - ไพ่ต–่งฃๆž - - ้’ฉๅญ็ณป็ปŸ - -### ไปฃ็ ็คบไพ‹ - -1. **[ๅŸบ็ก€็คบไพ‹](./examples/mini-kernel-example.ts)** - ็ฎ€ๅ•็š„ MiniKernel ไฝฟ็”จ็คบไพ‹ -2. **[ๆต‹่ฏ•ๅฅ—ไปถ](./test-mini-kernel.ts)** - ๅฎŒๆ•ด็š„ๆต‹่ฏ•็”จไพ‹ - -### ๆบไปฃ็  - -- **[ObjectKernel](./packages/runtime/src/mini-kernel.ts)** - ๅพฎๅ†…ๆ ธๅฎž็Žฐ -- **[Plugin Types](./packages/runtime/src/types.ts)** - ๆ’ไปถๆŽฅๅฃๅฎšไน‰ -- **[ObjectQLPlugin](./packages/runtime/src/objectql-plugin.ts)** - ObjectQL ๆ’ไปถ -- **[DriverPlugin](./packages/runtime/src/driver-plugin.ts)** - ้ฉฑๅŠจๅ™จๆ’ไปถ -- **[HonoServerPlugin](./packages/plugin-hono-server/src/hono-plugin.ts)** - HTTP ๆœๅŠกๅ™จๆ’ไปถ - -## ๐Ÿš€ ๅฟซ้€Ÿๅผ€ๅง‹ - -```typescript -import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); - -kernel - .use(new ObjectQLPlugin()) - .use(new DriverPlugin(memoryDriver, 'memory')); - -await kernel.bootstrap(); - -// ่ฎฟ้—ฎๆœๅŠก -const objectql = kernel.getService('objectql'); -``` - -## ๐Ÿ“‹ ๆ ธๅฟƒ็‰นๆ€ง - -- โœ… **ๆ’ไปถๅŒ–ๆžถๆž„**: ไธšๅŠก้€ป่พ‘ๅฎŒๅ…จๅ‰ฅ็ฆปๅˆฐๆ’ไปถ -- โœ… **ไพ่ต–ๆณจๅ…ฅ**: ๆœๅŠกๆณจๅ†Œ่กจๅฎž็Žฐ DI -- โœ… **็”Ÿๅ‘ฝๅ‘จๆœŸ็ฎก็†**: init โ†’ start โ†’ destroy -- โœ… **ไบ‹ไปถ็ณป็ปŸ**: Hook ๆœบๅˆถๅฎž็Žฐๆพ่€ฆๅˆ -- โœ… **ไพ่ต–่งฃๆž**: ่‡ชๅŠจๆ‹“ๆ‰‘ๆŽ’ๅบ -- โœ… **ๅ‘ๅŽๅ…ผๅฎน**: ไฟ็•™ๆ—ง API - -## ๐Ÿ”„ ไฝฟ็”จ็คบไพ‹ - -```typescript -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin()); -kernel.use(appManifestPlugin); -await kernel.bootstrap(); -``` - -## ๐Ÿ“– ๆŽจ่้˜…่ฏป้กบๅบ - -1. ๅ…ˆ่ฏป [ๅฎž็Žฐๆ€ป็ป“](./MINI_KERNEL_IMPLEMENTATION.md) ไบ†่งฃๆ•ดไฝ“ๆฆ‚ๅ†ต -2. ๆŸฅ็œ‹ [ๆžถๆž„ๅ›พ](./MINI_KERNEL_ARCHITECTURE.md) ็†่งฃ่ฎพ่ฎกๆ€่ทฏ -3. ๅ‚่€ƒ [ไฝฟ็”จๆŒ‡ๅ—](./MINI_KERNEL_GUIDE.md) ๅญฆไน ๅ…ทไฝ“็”จๆณ• -4. ่ฟ่กŒ [็คบไพ‹ไปฃ็ ](./examples/mini-kernel-example.ts) ๅฎž่ทตๆ“ไฝœ - -## ๐Ÿค ่ดก็Œฎ - -ๆฌข่ฟŽ่ดก็Œฎๆ–ฐ็š„ๆ’ไปถใ€ๆ”น่ฟ›ๆ–‡ๆกฃๆˆ–ๆๅ‡บ้—ฎ้ข˜๏ผ - -## ๐Ÿ“„ License - -Apache-2.0 diff --git a/MINI_KERNEL_SUMMARY.md b/MINI_KERNEL_SUMMARY.md deleted file mode 100644 index 020a93289..000000000 --- a/MINI_KERNEL_SUMMARY.md +++ /dev/null @@ -1,439 +0,0 @@ -# ๐ŸŽฏ ObjectStack MiniKernel ๆžถๆž„ๆ”น้€ ๆ€ป็ป“ - -## ๆฆ‚่ฟฐ - -ๆœฌๆฌกๆ”น้€ ๅฐ† ObjectStack ไปŽๅ•ไฝ“ๆžถๆž„่ฝฌๅ˜ไธบ**ๅพฎๅ†…ๆ ธ (MiniKernel)** ๆžถๆž„๏ผŒๅฎž็Žฐไบ†ไธšๅŠก้€ป่พ‘็š„ๅฎŒๅ…จๆ’ไปถๅŒ–ใ€‚ - -**ๆ ธๅฟƒๅŽŸๅˆ™**: ๅƒ Linux Kernel ไธ€ๆ ท๏ผŒๅฐ†ๆ ธๅฟƒๅŠŸ่ƒฝๅ‰ฅ็ฆปๅˆฐๆœ€ๅฐ๏ผŒๆ‰€ๆœ‰ไธšๅŠก้€ป่พ‘ไฝœไธบๆ’ไปถๅŠ ่ฝฝใ€‚ - -## ๆžถๆž„็‰น็‚น - -```typescript -// ObjectQL ๆˆไธบๅฏๆ’ๆ‹”็š„ๆœๅŠก -class ObjectKernel { - private services: Map; // โ† ๆœๅŠกๆณจๅ†Œ่กจ - - use(plugin: Plugin) { - // ๆ’ไปถๆณจๅ†Œ - } - - async bootstrap() { - // 1. Init: ๆ’ไปถๆณจๅ†ŒๆœๅŠก - // 2. Start: ๆ’ไปถๅฏๅŠจ - // 3. Ready: ่งฆๅ‘ kernel:ready ไบ‹ไปถ - } -} -``` - -**ไผ˜ๅŠฟ:** -- โœ… ObjectQL ๅฏๆ›ฟๆข (new ObjectQLPlugin(customQL)) -- โœ… ๆœๅŠกๆณจๅ†Œ่กจๅฎž็Žฐ DI -- โœ… ๆ ‡ๅ‡†็”Ÿๅ‘ฝๅ‘จๆœŸ (init/start/destroy) -- โœ… ๆ˜“ไบŽๆต‹่ฏ•ๅ’Œ Mock - -## ๆ ธๅฟƒ็ป„ไปถ - -### 1. ObjectKernel (ๅพฎๅ†…ๆ ธ) - -**ๆ–‡ไปถ**: `packages/runtime/src/mini-kernel.ts` - -**่Œ่ดฃ:** -- ๐Ÿ”„ ็ฎก็†ๆ’ไปถ็”Ÿๅ‘ฝๅ‘จๆœŸ -- ๐Ÿ“ฆ ๆไพ›ๆœๅŠกๆณจๅ†Œ่กจ (DI) -- ๐Ÿ”— ๅฎž็Žฐ้’ฉๅญ็ณป็ปŸ (Event Bus) -- ๐Ÿ“Š ่งฃๆžไพ่ต–ๅ…ณ็ณป (ๆ‹“ๆ‰‘ๆŽ’ๅบ) - -**API:** -```typescript -kernel.use(plugin) // ๆณจๅ†Œๆ’ไปถ -kernel.bootstrap() // ๅฏๅŠจๅ†…ๆ ธ -kernel.shutdown() // ๅ…ณ้—ญๅ†…ๆ ธ -kernel.getService(name) // ่Žทๅ–ๆœๅŠก -``` - -### 2. Plugin Interface - -**ๆ–‡ไปถ**: `packages/runtime/src/types.ts` - -**ๅฎšไน‰:** -```typescript -interface Plugin { - name: string; - dependencies?: string[]; - init(ctx: PluginContext): Promise; - start?(ctx: PluginContext): Promise; - destroy?(): Promise; -} -``` - -**็”Ÿๅ‘ฝๅ‘จๆœŸ:** -``` -idle โ†’ use() โ†’ init() โ†’ start() โ†’ running โ†’ destroy() โ†’ stopped -``` - -### 3. PluginContext - -**API:** -```typescript -ctx.registerService(name, service) // ๆณจๅ†ŒๆœๅŠก -ctx.getService(name) // ่Žทๅ–ๆœๅŠก -ctx.hook(event, handler) // ๆณจๅ†Œ้’ฉๅญ -ctx.trigger(event, ...args) // ่งฆๅ‘ไบ‹ไปถ -ctx.logger // ๆ—ฅๅฟ— -``` - -## ๅ†…็ฝฎๆ’ไปถ - -### 1. ObjectQLPlugin - -```typescript -kernel.use(new ObjectQLPlugin()); -// ๆณจๅ†ŒๆœๅŠก: 'objectql' -``` - -### 2. DriverPlugin - -```typescript -kernel.use(new DriverPlugin(driver, 'memory')); -// ไพ่ต–: ['com.objectstack.engine.objectql'] -``` - -### 3. HonoServerPlugin - -```typescript -kernel.use(new HonoServerPlugin({ port: 3000 })); -// ๆณจๅ†ŒๆœๅŠก: 'http-server' -``` - -## ๅฎž้™…ๅบ”็”จ็คบไพ‹ - -### ๅŸบ็ก€็”จๆณ• - -```typescript -import { ObjectKernel, ObjectQLPlugin, DriverPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); - -kernel - .use(new ObjectQLPlugin()) - .use(new DriverPlugin(memoryDriver)); - -await kernel.bootstrap(); -``` - -### ๆ’ไปถ้€šไฟก - -```typescript -// Plugin A: ๆไพ›ๆœๅŠก -class DataPlugin implements Plugin { - name = 'data'; - - async init(ctx) { - ctx.registerService('db', myDatabase); - } -} - -// Plugin B: ๆถˆ่ดนๆœๅŠก -class ApiPlugin implements Plugin { - name = 'api'; - dependencies = ['data']; - - async start(ctx) { - const db = ctx.getService('db'); - // ไฝฟ็”จๆ•ฐๆฎๅบ“ - } -} -``` - -### ไบ‹ไปถ้€šไฟก - -```typescript -class ServerPlugin implements Plugin { - name = 'server'; - - async start(ctx) { - ctx.hook('kernel:ready', () => { - server.listen(3000); - }); - } -} -``` - -## ๆŠ€ๆœฏไบฎ็‚น - -### 1. ไพ่ต–่งฃๆž (ๆ‹“ๆ‰‘ๆŽ’ๅบ) - -```typescript -// ๆณจๅ†Œ้กบๅบๆ— ๅ…ณ็ดง่ฆ -kernel.use(new PluginC()); // depends on B -kernel.use(new PluginB()); // depends on A -kernel.use(new PluginA()); // no deps - -// ่‡ชๅŠจๆŽ’ๅบไธบ: A โ†’ B โ†’ C -``` - -**็ฎ—ๆณ•**: ๆทฑๅบฆไผ˜ๅ…ˆๆœ็ดข + ๆ‹“ๆ‰‘ๆŽ’ๅบ -**ๆ—ถ้—ดๅคๆ‚ๅบฆ**: O(V + E) -**็ฉบ้—ดๅคๆ‚ๅบฆ**: O(V) - -### 2. ๆœๅŠกๆณจๅ†Œ่กจ - -```typescript -private services: Map = new Map(); - -registerService(name, service) { - if (this.services.has(name)) { - throw new Error(`Service '${name}' already exists`); - } - this.services.set(name, service); -} -``` - -**็‰น็‚น:** -- O(1) ๆŸฅๆ‰พๆ—ถ้—ด -- ็ฑปๅž‹ๅฎ‰ๅ…จ (ๆณ›ๅž‹) -- ้˜ฒๆญข้‡ๅคๆณจๅ†Œ - -### 3. ้’ฉๅญ็ณป็ปŸ - -```typescript -private hooks: Map = new Map(); - -hook(name, handler) { - if (!this.hooks.has(name)) { - this.hooks.set(name, []); - } - this.hooks.get(name).push(handler); -} - -async trigger(name, ...args) { - const handlers = this.hooks.get(name) || []; - for (const handler of handlers) { - await handler(...args); - } -} -``` - -**็‰น็‚น:** -- ๅ‘ๅธƒ-่ฎข้˜…ๆจกๅผ -- ๅผ‚ๆญฅๆ‰ง่กŒ -- ้กบๅบไฟ่ฏ - -## ๆ–‡ๆกฃไฝ“็ณป - -### ๐Ÿ“š ๅฎŒๆ•ดๆ–‡ๆกฃ (1,250+ ่กŒ) - -1. **[MINI_KERNEL_INDEX.md](./MINI_KERNEL_INDEX.md)** - - ๅฏผ่ˆช็ดขๅผ• - - ๅฟซ้€Ÿๅผ€ๅง‹ - - ๆŽจ่้˜…่ฏป้กบๅบ - -2. **[MINI_KERNEL_IMPLEMENTATION.md](./MINI_KERNEL_IMPLEMENTATION.md)** - - ๅฎž็Žฐๆ€ป็ป“ (ไธญ่‹ฑๅŒ่ฏญ) - - ๆ ธๅฟƒ็ป„ไปถ่ฏฆ่งฃ - - ่ฟ็งปๆŒ‡ๅ— - -3. **[MINI_KERNEL_GUIDE.md](./MINI_KERNEL_GUIDE.md)** - - ๅฎŒๆ•ด API ๆ–‡ๆกฃ - - ไฝฟ็”จ็คบไพ‹ - - ๆœ€ไฝณๅฎž่ทต - - ๆ•…้šœๆŽ’ๆŸฅ - -4. **[MINI_KERNEL_ARCHITECTURE.md](./MINI_KERNEL_ARCHITECTURE.md)** - - ๆžถๆž„ๅ›พ (ASCII Art) - - ๆต็จ‹ๅ›พ - - ๅบๅˆ—ๅ›พ - - ๆ‰ฉๅฑ•่ทฏๅพ„ - -## ไปฃ็ ็ปŸ่ฎก - -### ๆ ธๅฟƒๅฎž็Žฐ (~500 ่กŒ) -- `mini-kernel.ts`: 248 ่กŒ -- `types.ts`: 114 ่กŒ -- `driver-plugin.ts`: 42 ่กŒ -- `objectql-plugin.ts`: 84 ่กŒ - -### ๆ–‡ๆกฃ (~1,700 ่กŒ) -- ไธปๆ–‡ๆกฃ: 1,250 ่กŒ -- ็คบไพ‹ไปฃ็ : 200 ่กŒ -- ๆต‹่ฏ•ๅฅ—ไปถ: 260 ่กŒ - -### ๆ€ป่ฎก: **~2,200 ่กŒ** - -## ่ฎพ่ฎกๅŽŸๅˆ™ - -### SOLID ๅŽŸๅˆ™ - -1. **S** - Single Responsibility - - Kernel ๅช่ดŸ่ดฃ็”Ÿๅ‘ฝๅ‘จๆœŸ/DI/ไบ‹ไปถ - - ไธšๅŠก้€ป่พ‘ๅ…จ้ƒจๅœจๆ’ไปถไธญ - -2. **O** - Open/Closed - - ๅฏนๆ‰ฉๅฑ•ๅผ€ๆ”พ (ๆ–ฐๆ’ไปถ) - - ๅฏนไฟฎๆ”นๅฐ้—ญ (Kernel ไธๅ˜) - -3. **L** - Liskov Substitution - - ๆ‰€ๆœ‰ Plugin ๅฏไปฅไบ’ๆข - - ObjectQLPlugin ๅฏไปฅๆ›ฟๆข - -4. **I** - Interface Segregation - - Plugin ๅช้œ€ๅฎž็Žฐๅฟ…่ฆๆ–นๆณ• - - start/destroy ้ƒฝๆ˜ฏๅฏ้€‰็š„ - -5. **D** - Dependency Inversion - - ้ซ˜ๅฑ‚ไธไพ่ต–ไฝŽๅฑ‚ - - ้ƒฝไพ่ต– Plugin ๆŽฅๅฃ - -### ๅ…ถไป–ๅŽŸๅˆ™ - -- **ๆœ€ๅฐๆƒŠ่ฎถๅŽŸๅˆ™**: API ็›ด่ง‚ๆ˜“ๆ‡‚ -- **็บฆๅฎšไผ˜ไบŽ้…็ฝฎ**: ๅˆ็†็š„้ป˜่ฎคๅ€ผ -- **ๆ˜พๅผไผ˜ไบŽ้šๅผ**: ไพ่ต–ๅฃฐๆ˜Žๆธ…ๆ™ฐ - -## ๆต‹่ฏ•่ฆ†็›– - -### ๆต‹่ฏ•็”จไพ‹ (test-mini-kernel.ts) - -1. โœ… ๅŸบ็ก€็”Ÿๅ‘ฝๅ‘จๆœŸ -2. โœ… ๆœๅŠกๆณจๅ†Œ่กจ -3. โœ… ไพ่ต–่งฃๆž -4. โœ… ้’ฉๅญ็ณป็ปŸ -5. โœ… ObjectQL ๆ’ไปถ -6. โœ… ๅคšๆ’ไปถๅไฝœ -7. โœ… ้”™่ฏฏๅค„็† - -### ่ฟ่กŒๆต‹่ฏ• - -```bash -node test-mini-kernel.js -``` - -## ไฝฟ็”จๆŒ‡ๅ— - -### ๆญฅ้ชค 1: ๅฎ‰่ฃ…ไพ่ต– - -```bash -npm install @objectstack/runtime -``` - -### ๆญฅ้ชค 2: ็ผ–ๅ†™ไปฃ็  - -```typescript -import { ObjectKernel, ObjectQLPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); - -kernel - .use(new ObjectQLPlugin()) - .use(appManifestPlugin); - -await kernel.bootstrap(); -``` - -### ๆญฅ้ชค 3: ๆต‹่ฏ• - -```bash -npm test -``` - - - -## ๆ€ง่ƒฝ็‰น็‚น - -### ๅฏๅŠจๆ—ถ้—ด - -- 5ไธชๆ’ไปถ: ~220ms -- ไพ่ต–่งฃๆž: O(V+E) ๆ—ถ้—ดๅคๆ‚ๅบฆ - -### ๅ†…ๅญ˜ๅ ็”จ - -- ๅŸบ็ก€ๅ†…ๅญ˜: ~52MB -- ๆœๅŠกๆณจๅ†Œ่กจ: O(1) ๆŸฅๆ‰พๆ€ง่ƒฝ - -## ๆœชๆฅ่ง„ๅˆ’ - -### Phase 1: ้…็ฝฎๅŒ–ๅŠ ่ฝฝ โœจ - -```typescript -// objectstack.config.ts -export default { - plugins: [ - 'objectql', - 'memory-driver', - 'hono-server' - ] -}; - -// ่‡ชๅŠจๅŠ ่ฝฝ -const kernel = await loadFromConfig('./objectstack.config.ts'); -``` - -### Phase 2: ๆ’ไปถๅธ‚ๅœบ ๐Ÿช - -```bash -npm install @company/awesome-plugin - -# objectstack.config.ts -plugins: ['@company/awesome-plugin'] -``` - -### Phase 3: ็ƒญ้‡่ฝฝ ๐Ÿ”ฅ - -```typescript -kernel.reload('plugin-name'); // ๆ— ้œ€้‡ๅฏ -``` - -### Phase 4: ๆฒ™็ฎฑ้š”็ฆป ๐Ÿ”’ - -```typescript -// ็”จๆˆท่„šๆœฌๅœจ้š”็ฆป็Žฏๅขƒ่ฟ่กŒ -kernel.use(new SandboxPlugin({ - userScript: './user-plugin.js', - permissions: ['read', 'write'] -})); -``` - -## ๅธธ่ง้—ฎ้ข˜ - -### Q: ไธบไป€ไนˆ่ฆๅพฎๅ†…ๆ ธ๏ผŸ - -A: -1. **ๆจกๅ—ๅŒ–**: ไธšๅŠก้€ป่พ‘ๅฎŒๅ…จ่งฃ่€ฆ -2. **ๅฏๆต‹่ฏ•**: Mock ๅ˜ๅพ—็ฎ€ๅ• -3. **ๅฏๆ‰ฉๅฑ•**: ๆ’ไปถๅผๆ‰ฉๅฑ• -4. **็ตๆดปๆ€ง**: ๆŒ‰้œ€ๅŠ ่ฝฝๆ’ไปถ - -### Q: ๆ€ง่ƒฝไผšไธ‹้™ๅ—๏ผŸ - -A: ไธไผšใ€‚ๅผ€้”€ไป…ๅœจๅฏๅŠจๆ—ถ (+10%)๏ผŒ่ฟ่กŒๆ—ถๅ‡ ไนŽๆ— ๅทฎๅผ‚ใ€‚ - -### Q: ๅฆ‚ไฝ•่ฟ็งป็Žฐๆœ‰ไปฃ็ ๏ผŸ - -A: ๅนณๆป‘่ฟ็งป๏ผŒๆ—งไปฃ็ ็ปง็ปญๅทฅไฝœใ€‚ๅ‚่€ƒ [่ฟ็งปๆŒ‡ๅ—](#่ฟ็งปๆŒ‡ๅ—)ใ€‚ - -### Q: ๅฏไปฅ่‡ชๅฎšไน‰ ObjectQL ๅ—๏ผŸ - -A: ๅฏไปฅ๏ผ`new ObjectQLPlugin(customQL)` - -## ๅ‚่€ƒ่ต„ๆ–™ - -- [Microkernel Architecture Pattern](https://en.wikipedia.org/wiki/Microkernel) -- [Plugin Architecture](https://martinfowler.com/articles/plugins.html) -- [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) -- [Service Locator Pattern](https://martinfowler.com/articles/injection.html) - -## ่ดก็Œฎ่€… - -- [@hotlong](https://github.com/hotlong) - ๆžถๆž„่ฎพ่ฎกไธŽๅฎž็Žฐ -- GitHub Copilot - ไปฃ็ ่พ…ๅŠฉ - -## License - -Apache-2.0 - ---- - -**๐ŸŽ‰ ๆˆๅŠŸๅฎž็Žฐไบ†ไธ€ไธช็œŸๆญฃ็š„ๅพฎๅ†…ๆ ธๆžถๆž„๏ผ** - -> "The best architectures, requirements, and designs emerge from self-organizing teams." -> โ€” Agile Manifesto diff --git a/OBJECTQL_PLUGIN_QUICKSTART.md b/OBJECTQL_PLUGIN_QUICKSTART.md deleted file mode 100644 index f9b82dc29..000000000 --- a/OBJECTQL_PLUGIN_QUICKSTART.md +++ /dev/null @@ -1,215 +0,0 @@ -# ObjectQL Plugin - Quick Reference - -## Installation - -```bash -npm install @objectstack/runtime -``` - -## Basic Usage - -### Default ObjectQL (Recommended) - -```typescript -import { ObjectKernel, ObjectQLPlugin } from '@objectstack/runtime'; - -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin()); -// ... other plugins - -await kernel.bootstrap(); -``` - -### Custom ObjectQL Instance - -```typescript -import { ObjectKernel, ObjectQLPlugin, ObjectQL } from '@objectstack/runtime'; - -// Create custom instance -const customQL = new ObjectQL({ - env: 'production', - // custom options -}); - -// Configure as needed -customQL.registerHook('beforeInsert', async (ctx) => { - console.log(`Inserting into ${ctx.object}`); -}); - -// Use in kernel -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin(customQL)); -// ... other plugins - -await kernel.bootstrap(); -``` - -## API Reference - -### ObjectQLPlugin Constructor - -```typescript -new ObjectQLPlugin(ql?: ObjectQL, hostContext?: Record) -``` - -**Parameters:** -- `ql` (optional): Custom ObjectQL instance to use -- `hostContext` (optional): Configuration for new ObjectQL instance (ignored if `ql` provided) - -**Note:** If both parameters are provided, `hostContext` is ignored with a warning. - -### Examples - -```typescript -// Create with default settings -new ObjectQLPlugin() - -// Use custom instance -const custom = new ObjectQL({ env: 'prod' }); -new ObjectQLPlugin(custom) - -// Create with custom context -new ObjectQLPlugin(undefined, { env: 'prod', debug: true }) -``` - -## Migration Guide - -### From Array-Based to Chaining Pattern - -**Before:** -```typescript -const kernel = new ObjectKernel([appConfig, driver]); -``` - -**After:** -```typescript -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin()); // Add this line -kernel.use(appConfig); -kernel.use(driver); - -await kernel.bootstrap(); -``` - -## Common Patterns - -### Testing with Mock ObjectQL - -```typescript -import { ObjectKernel, ObjectQLPlugin } from '@objectstack/runtime'; -import { MockObjectQL } from './mocks'; - -const mockQL = new MockObjectQL(); -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin(mockQL)); -// ... test config - -await kernel.bootstrap(); -``` - -### Multiple Environments - -```typescript -// Production -const prodQL = new ObjectQL({ env: 'production', cache: true }); -const prodKernel = new ObjectKernel(); -prodKernel.use(new ObjectQLPlugin(prodQL)); -// ... production plugins - -await prodKernel.bootstrap(); - -// Development -const devKernel = new ObjectKernel(); -devKernel.use(new ObjectQLPlugin(undefined, { env: 'development', debug: true })); -// ... dev plugins - -await devKernel.bootstrap(); -``` - -### Custom ObjectQL from Separate Project - -```typescript -// Your custom implementation -import { ObjectKernel, ObjectQLPlugin } from '@objectstack/runtime'; -import { MyCustomObjectQL } from '@mycompany/custom-objectql'; - -const customQL = new MyCustomObjectQL({ - specialFeature: true, - // custom options -}); - -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin(customQL)); -// ... other plugins - -await kernel.bootstrap(); -``` - -## Troubleshooting - -### Error: "ObjectQL engine not initialized" - -This means the kernel tried to use ObjectQL before it was set up. Make sure you register the `ObjectQLPlugin`: - -```typescript -const kernel = new ObjectKernel(); -kernel.use(new ObjectQLPlugin()); // Add this -// ... other plugins - -await kernel.bootstrap(); -``` - -### Warning: "Both ql and hostContext provided..." - -You passed both a custom ObjectQL instance and host context: - -```typescript -// โŒ Don't do this -new ObjectQLPlugin(customQL, { env: 'prod' }) // hostContext ignored - -// โœ… Do this instead -new ObjectQLPlugin(customQL) // Use custom instance - -// โœ… Or this -new ObjectQLPlugin(undefined, { env: 'prod' }) // Create with context -``` - -## Advanced - -### Type-Based Detection - -ObjectQLPlugin uses a `type` field for reliable detection: - -```typescript -// Check if a plugin is an ObjectQL plugin -const isObjectQLPlugin = plugin && plugin.type === 'objectql'; -``` - -The plugin sets `type = 'objectql'` which aligns with the manifest schema that supports package types: 'app', 'plugin', 'driver', 'module', 'objectql', 'gateway', 'adapter'. - -### Type Safety - -The kernel's `ql` property is typed as optional: - -```typescript -export class ObjectKernel { - public ql?: ObjectQL; - - private ensureObjectQL(): ObjectQL { - if (!this.ql) { - throw new Error('ObjectQL engine not initialized'); - } - return this.ql; - } -} -``` - -## Resources - -- [Full Documentation](./packages/runtime/README.md) -- [Implementation Summary](./OBJECTQL_PLUGIN_SUMMARY.md) -- [Custom ObjectQL Example](./examples/custom-objectql-example.ts) - -## License - -Apache-2.0 diff --git a/PROTOCOL_EXTENSIONS_COMPLETED.md b/PROTOCOL_EXTENSIONS_COMPLETED.md deleted file mode 100644 index b52b0f181..000000000 --- a/PROTOCOL_EXTENSIONS_COMPLETED.md +++ /dev/null @@ -1,447 +0,0 @@ -# ObjectStack Protocol Extensions - Completion Report - -> **ๅฎŒๆˆๆ—ฅๆœŸ**: 2026-01-27 -> **็Šถๆ€**: โœ… ๆ‰€ๆœ‰ๅปบ่ฎฎ็š„ๅ่ฎฎๆ‰ฉๅฑ•ๅทฒๅฎŒๆˆๅฎž็Žฐ - ---- - -## ๐Ÿ“‹ ๆ‰ง่กŒๆ‘˜่ฆ - -ๆœฌๆ–‡ๆกฃ่ฎฐๅฝ•ไบ† ObjectStack ๅ่ฎฎๆ‰ฉๅฑ•ๆœบไผš็š„ๅฎž็Žฐ็Šถๆ€ใ€‚ๆ นๆฎ [PROTOCOL_OPTIMIZATION_PLAN.md](./PROTOCOL_OPTIMIZATION_PLAN.md) ไธญ็š„ๅปบ่ฎฎ๏ผŒไปฅไธ‹ๆ‰€ๆœ‰้ซ˜็บงๆŸฅ่ฏขๅŠŸ่ƒฝๅ’Œๅญ—ๆฎต็ฑปๅž‹ๆ‰ฉๅฑ•ๅทฒ็ปๆˆๅŠŸๅฎž็Žฐๅนถ้€š่ฟ‡ๆต‹่ฏ•ใ€‚ - ---- - -## โœ… 2.1 ้ซ˜็บงๆŸฅ่ฏขๅŠŸ่ƒฝ - ๅทฒๅฎŒๆˆๅฎž็Žฐ - -### 2.1.1 ็ช—ๅฃๅ‡ฝๆ•ฐ (Window Functions) โœ… ๅทฒๅฎŒๆˆ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/data/query.zod.ts` (่กŒ 236-381) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐ** - -**ๆ”ฏๆŒ็š„็ช—ๅฃๅ‡ฝๆ•ฐ**: -- โœ… `row_number` - Sequential number within partition -- โœ… `rank` - Rank with gaps for ties -- โœ… `dense_rank` - Rank without gaps -- โœ… `percent_rank` - Relative rank as percentage -- โœ… `lag` - Access previous row value -- โœ… `lead` - Access next row value -- โœ… `first_value` - First value in window -- โœ… `last_value` - Last value in window -- โœ… Aggregate window functions: `sum`, `avg`, `count`, `min`, `max` - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const WindowFunction = z.enum([ - 'row_number', 'rank', 'dense_rank', 'percent_rank', - 'lag', 'lead', 'first_value', 'last_value', - 'sum', 'avg', 'count', 'min', 'max' -]); - -export const WindowFunctionNodeSchema = z.object({ - function: WindowFunction.describe('Window function name'), - field: z.string().optional().describe('Field to operate on'), - alias: z.string().describe('Result column alias'), - over: WindowSpecSchema.describe('Window specification (OVER clause)'), -}); -``` - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -// SQL: SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY amount DESC) as rank -{ - object: 'order', - fields: ['id', 'customer_id', 'amount'], - windowFunctions: [ - { - function: 'row_number', - alias: 'rank', - over: { - partitionBy: ['customer_id'], - orderBy: [{ field: 'amount', order: 'desc' }] - } - } - ] -} -``` - -**ๆต‹่ฏ•่ฆ†็›–**: `packages/spec/src/data/query.test.ts` - 20+ ๆต‹่ฏ•็”จไพ‹ - ---- - -### 2.1.2 HAVING ๅญๅฅ โœ… ๅทฒๅฎŒๆˆ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/data/query.zod.ts` (่กŒ 457) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐ** - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const QuerySchema = z.object({ - // ... other fields - groupBy: z.array(z.string()).optional().describe('GROUP BY fields'), - having: FilterConditionSchema.optional().describe('HAVING clause for aggregation filtering'), - // ... -}); -``` - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -// SQL: SELECT region, SUM(amount) as total -// FROM sales -// GROUP BY region -// HAVING total > 1000 -{ - object: 'sales', - fields: ['region'], - aggregations: [ - { function: 'sum', field: 'amount', alias: 'total' } - ], - groupBy: ['region'], - having: { total: { $gt: 1000 } } -} -``` - -**ๆต‹่ฏ•่ฆ†็›–**: `packages/spec/src/data/query.test.ts` - 10+ ๆต‹่ฏ•็”จไพ‹ - ---- - -### 2.1.3 DISTINCT ๆŸฅ่ฏข โœ… ๅทฒๅฎŒๆˆ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/data/query.zod.ts` (่กŒ 463) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐ** - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const QuerySchema = z.object({ - // ... other fields - distinct: z.boolean().optional().describe('SELECT DISTINCT flag'), -}); -``` - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -// SQL: SELECT DISTINCT customer_id FROM orders -{ - object: 'order', - fields: ['customer_id'], - distinct: true -} -``` - -**ๆต‹่ฏ•่ฆ†็›–**: `packages/spec/src/data/query.test.ts` - 5+ ๆต‹่ฏ•็”จไพ‹ - ---- - -### 2.1.4 ๅญๆŸฅ่ฏขๆ”ฏๆŒ (Subqueries) โœ… ๅทฒๅฎŒๆˆ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/data/query.zod.ts` (่กŒ 231) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐ** - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const JoinNodeSchema = z.object({ - type: JoinType.describe('Join type'), - object: z.string().describe('Object/table to join'), - alias: z.string().optional().describe('Table alias'), - on: FilterConditionSchema.describe('Join condition'), - subquery: z.lazy(() => QuerySchema).optional().describe('Subquery instead of object'), -}); -``` - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -// Join with a subquery (filtered dataset) -{ - object: 'customer', - joins: [ - { - type: 'left', - object: 'order', - alias: 'high_value_orders', - on: ['customer.id', '=', 'high_value_orders.customer_id'], - subquery: { - object: 'order', - fields: ['customer_id', 'total'], - where: { total: { $gt: 1000 } } - } - } - ] -} -``` - -**ๆต‹่ฏ•่ฆ†็›–**: `packages/spec/src/data/query.test.ts` - 8+ ๆต‹่ฏ•็”จไพ‹ - ---- - -## โœ… 2.2 ่ฟ่กŒๆ—ถๆ‰ฉๅฑ•ไธŽๅ่ฎฎ่พน็•Œ - ๅทฒๅฎŒๆˆๅฎž็Žฐ - -### 2.2.1 Vector ๅญ—ๆฎต็ฑปๅž‹ โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/data/field.zod.ts` (่กŒ 43, 150-156) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐๅนถ็บณๅ…ฅๅ่ฎฎ** - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const FieldType = z.enum([ - // ... other types - 'vector', // Vector embeddings for AI/ML (semantic search, RAG) -]); - -export const VectorConfigSchema = z.object({ - dimensions: z.number().int().min(1).max(10000) - .describe('Vector dimensionality (e.g., 1536 for OpenAI embeddings)'), - distanceMetric: z.enum(['cosine', 'euclidean', 'dotProduct', 'manhattan']) - .default('cosine') - .describe('Distance/similarity metric for vector search'), - normalized: z.boolean().default(false) - .describe('Whether vectors are normalized (unit length)'), - indexed: z.boolean().default(true) - .describe('Whether to create a vector index for fast similarity search'), - indexType: z.enum(['hnsw', 'ivfflat', 'flat']).optional() - .describe('Vector index algorithm'), -}); -``` - -**ไฝฟ็”จๅœบๆ™ฏ**: -- โœ… ่ฏญไน‰ๆœ็ดข (Semantic Search) -- โœ… RAG (Retrieval-Augmented Generation) -- โœ… ๆ–‡ๆœฌๅตŒๅ…ฅ (Text Embeddings) -- โœ… ๅ›พๅƒ็‰นๅพๅ‘้‡ (Image Feature Vectors) -- โœ… ๆŽจ่็ณป็ปŸ (Recommendation Systems) - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -{ - name: 'embedding', - type: 'vector', - label: 'Content Embedding', - vectorConfig: { - dimensions: 1536, // OpenAI text-embedding-ada-002 - distanceMetric: 'cosine', - indexed: true, - indexType: 'hnsw' - } -} -``` - -**ๆต‹่ฏ•่ฆ†็›–**: `packages/spec/src/data/field.test.ts` - 15+ ๆต‹่ฏ•็”จไพ‹ - ---- - -### 2.2.2 Location ๅญ—ๆฎต็ฑปๅž‹ โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/data/field.zod.ts` (่กŒ 31, 74-82) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐๅนถ็บณๅ…ฅๅ่ฎฎ** - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const FieldType = z.enum([ - // ... other types - 'location', // GPS coordinates -]); - -export const LocationCoordinatesSchema = z.object({ - latitude: z.number().min(-90).max(90).describe('Latitude coordinate'), - longitude: z.number().min(-180).max(180).describe('Longitude coordinate'), - altitude: z.number().optional().describe('Altitude in meters'), - accuracy: z.number().optional().describe('Accuracy in meters'), -}); -``` - -**ไฝฟ็”จๅœบๆ™ฏ**: -- โœ… GPS ๅฎšไฝ (GPS Positioning) -- โœ… ๅœฐ็†ๅ›ดๆ  (Geofencing) -- โœ… ไฝ็ฝฎ่ฟฝ่ธช (Location Tracking) -- โœ… ่ท็ฆป่ฎก็ฎ— (Distance Calculation) -- โœ… ๅœฐๅ›พๅฑ•็คบ (Map Display) - -**ไฝฟ็”จ็คบไพ‹**: -```typescript -{ - name: 'store_location', - type: 'location', - label: 'Store Location', - displayMap: true, - allowGeocoding: true -} -``` - -**ๆต‹่ฏ•่ฆ†็›–**: `packages/spec/src/data/field.test.ts` - 10+ ๆต‹่ฏ•็”จไพ‹ - ---- - -### 2.2.3 ๅ…ถไป–ๅขžๅผบๅญ—ๆฎต็ฑปๅž‹ โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ - -ไปฅไธ‹ๅญ—ๆฎต็ฑปๅž‹ไนŸๅทฒๅฎŒๅ…จๅฎž็Žฐๅนถ็บณๅ…ฅๅ่ฎฎ: - -- โœ… **Address** (`address`) - ็ป“ๆž„ๅŒ–ๅœฐๅ€ (่กŒ 116-124) -- โœ… **Object** - ้€š่ฟ‡ `lookup` ๅ’Œ `master_detail` ๅฎž็Žฐๅ…ณ็ณป -- โœ… **Grid** - ้€š่ฟ‡ UI ๅฑ‚็š„ `view.zod.ts` ๅฎž็Žฐ - ---- - -## ๐Ÿ”ง 2.3 ้ฉฑๅŠจ่ƒฝๅŠ›ๅฃฐๆ˜Ž - ๅทฒๅฎŒๆˆๅฎž็Žฐ - -**ๅฎž็Žฐไฝ็ฝฎ**: `packages/spec/src/system/driver.zod.ts` (่กŒ 44-135) - -**ๅŠŸ่ƒฝ็Šถๆ€**: ๐ŸŸข **ๅทฒๅฎŒๅ…จๅฎž็Žฐ** - -**ๅ่ฎฎๅฎšไน‰**: -```typescript -export const DriverCapabilitiesSchema = z.object({ - // Query Operations - queryFilters: z.boolean().describe('Supports WHERE clause filtering'), - queryAggregations: z.boolean().describe('Supports GROUP BY and aggregation functions'), - querySorting: z.boolean().describe('Supports ORDER BY sorting'), - queryPagination: z.boolean().describe('Supports LIMIT/OFFSET pagination'), - queryWindowFunctions: z.boolean().describe('Supports window functions with OVER clause'), - querySubqueries: z.boolean().describe('Supports subqueries'), - joins: z.boolean().describe('Supports SQL joins'), - - // Advanced Features - fullTextSearch: z.boolean().describe('Supports full-text search'), - vectorSearch: z.boolean().default(false).describe('Supports vector embeddings and similarity search'), - geoSpatial: z.boolean().default(false).describe('Supports geospatial queries'), - jsonFields: z.boolean().describe('Supports JSON field types'), - arrayFields: z.boolean().describe('Supports array field types'), - - // ... other capabilities -}); -``` - -**้ฉฑๅŠจๅฎž็Žฐ็คบไพ‹** (`packages/driver-memory/src/memory-driver.ts`): -```typescript -supports = { - transactions: false, - queryFilters: false, - queryAggregations: false, - querySorting: false, - queryPagination: true, - queryWindowFunctions: false, // โœ… ็Žฐๅœจๆœ‰ๆ˜Ž็กฎๅฎšไน‰ - querySubqueries: false, // โœ… ็Žฐๅœจๆœ‰ๆ˜Ž็กฎๅฎšไน‰ - joins: false, - fullTextSearch: false, - vectorSearch: false, - geoSpatial: false, - jsonFields: true, - arrayFields: true, -}; -``` - ---- - -## ๐Ÿ“Š ๆ€ปไฝ“ๅฎŒๆˆๅบฆ่ฏ„ไผฐ - -### Query Protocol - ๅฎŒๆ•ดๅบฆ: 95% โ†’ **100%** โœ… - -| ๅŠŸ่ƒฝ | ไน‹ๅ‰็Šถๆ€ | ๅฝ“ๅ‰็Šถๆ€ | ๅ่ฎฎไฝ็ฝฎ | -|------|---------|---------|---------| -| Window Functions | ๐ŸŸก SQL ้ฉฑๅŠจๆ”ฏๆŒไฝ†ๅ่ฎฎๆœชๅฎšไน‰ | โœ… ๅทฒๅฎŒๅ…จๅฎšไน‰ | `query.zod.ts:236-381` | -| Subqueries | ๐ŸŸก ้ƒจๅˆ†ๆ”ฏๆŒไฝ†ๅ่ฎฎๆœชๅฎšไน‰ | โœ… ๅทฒๅฎŒๅ…จๅฎšไน‰ | `query.zod.ts:231` | -| HAVING Clause | ๐ŸŸก GroupBy ๅทฒๅฎž็Žฐไฝ†ๆ—  HAVING | โœ… ๅทฒๅฎŒๅ…จๅฎšไน‰ | `query.zod.ts:457` | -| DISTINCT Query | ๐ŸŸก ๅฎž็Žฐไธบ็‹ฌ็ซ‹ๆ–นๆณ• | โœ… ๅทฒ็บณๅ…ฅ QueryAST | `query.zod.ts:463` | - -### Field Types - ๅฎŒๆ•ดๅบฆ: 95% โ†’ **100%** โœ… - -| ๅญ—ๆฎต็ฑปๅž‹ | ไน‹ๅ‰็Šถๆ€ | ๅฝ“ๅ‰็Šถๆ€ | ๅ่ฎฎไฝ็ฝฎ | -|---------|---------|---------|---------| -| Vector | โš ๏ธ Runtime Extension | โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ | `field.zod.ts:43, 150-156` | -| Location | โš ๏ธ Runtime Extension | โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ | `field.zod.ts:31, 74-82` | -| Address | โœ… ๅทฒๅฎž็Žฐ | โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ | `field.zod.ts:116-124` | - -### Driver Capabilities - ๅฎŒๆ•ดๅบฆ: 85% โ†’ **100%** โœ… - -| ่ƒฝๅŠ›ๆ ‡ๅฟ— | ไน‹ๅ‰็Šถๆ€ | ๅฝ“ๅ‰็Šถๆ€ | ๅ่ฎฎไฝ็ฝฎ | -|---------|---------|---------|---------| -| queryWindowFunctions | โŒ ๆœชๅฎšไน‰ | โœ… ๅทฒๅฎšไน‰ | `driver.zod.ts:89` | -| querySubqueries | โŒ ๆœชๅฎšไน‰ | โœ… ๅทฒๅฎšไน‰ | `driver.zod.ts:95` | -| vectorSearch | โŒ ๆœชๅฎšไน‰ | โœ… ๅทฒๅฎšไน‰ | `driver.zod.ts:129` | -| geoSpatial | โŒ ๆœชๅฎšไน‰ | โœ… ๅทฒๅฎšไน‰ | `driver.zod.ts:134` | - ---- - -## ๐Ÿงช ๆต‹่ฏ•่ฆ†็›–็އ - -**ๆ€ปไฝ“ๆต‹่ฏ•็Šถๆ€**: โœ… **1695 ๆต‹่ฏ•ๅ…จ้ƒจ้€š่ฟ‡** - -### ็›ธๅ…ณๆต‹่ฏ•ๆ–‡ไปถ: -- โœ… `packages/spec/src/data/query.test.ts` - 105 tests (ๅŒ…ๅซ Window Functions, HAVING, DISTINCT ๆต‹่ฏ•) -- โœ… `packages/spec/src/data/field.test.ts` - 81 tests (ๅŒ…ๅซ Vector, Location ๅญ—ๆฎตๆต‹่ฏ•) -- โœ… `packages/spec/src/system/driver.test.ts` - 23 tests (ๅŒ…ๅซ้ฉฑๅŠจ่ƒฝๅŠ›ๆต‹่ฏ•) - -### ๆต‹่ฏ•ๆ‰ง่กŒ็ป“ๆžœ: -```bash -โœ“ src/data/query.test.ts (105 tests) 83ms -โœ“ src/data/field.test.ts (81 tests) 54ms -โœ“ src/system/driver.test.ts (23 tests) 19ms - -Test Files 50 passed (50) -Tests 1695 passed (1695) -``` - ---- - -## ๐Ÿ“š ๆ–‡ๆกฃๅ’Œ็คบไพ‹ - -### ไปฃ็ ๆ–‡ๆกฃ (JSDoc) -ๆ‰€ๆœ‰ๆ–ฐๅขž็š„ๅ่ฎฎๆ‰ฉๅฑ•้ƒฝๅŒ…ๅซๅฎŒๆ•ด็š„ JSDoc ๆ–‡ๆกฃ๏ผŒๅŒ…ๆ‹ฌ: -- โœ… ๅŠŸ่ƒฝๆ่ฟฐ -- โœ… SQL ็ญ‰ๆ•ˆ่ฏญๆณ• -- โœ… ไฝฟ็”จ็คบไพ‹ -- โœ… ๆ€ง่ƒฝ่€ƒ่™‘ -- โœ… ่กŒไธšๅฏนๆ ‡ (Salesforce, PostgreSQL, etc.) - -### ็คบไพ‹ไปฃ็  -ๆฏไธชๅ่ฎฎๆ‰ฉๅฑ•้ƒฝๅœจ JSDoc ไธญๅŒ…ๅซ่‡ณๅฐ‘ 2-3 ไธชๅฎž้™…ไฝฟ็”จ็คบไพ‹ใ€‚ - ---- - -## ๐ŸŽฏ ไธŽ่กŒไธšๆ ‡ๅ‡†ๅฏนๆ ‡ - -| ๅŠŸ่ƒฝ | ObjectStack | SQL | MongoDB | Salesforce | ็Šถๆ€ | -|------|------------|-----|---------|-----------|------| -| Window Functions | โœ… | โœ… | โŒ | โœ… (Analytics) | โญโญโญโญโญ | -| HAVING Clause | โœ… | โœ… | โœ… ($match after $group) | โœ… | โญโญโญโญโญ | -| DISTINCT | โœ… | โœ… | โœ… | โœ… | โญโญโญโญโญ | -| Subqueries | โœ… | โœ… | โœ… ($lookup) | โœ… (Relationship Queries) | โญโญโญโญโญ | -| Vector Search | โœ… | โœ… (pgvector) | โœ… (Atlas Vector Search) | โŒ | โญโญโญโญโญ | -| Geo Location | โœ… | โœ… (PostGIS) | โœ… | โœ… | โญโญโญโญโญ | - -**่กŒไธšๅฏนๆ ‡่ฏ„ๅˆ†**: โญโญโญโญโญ (5/5) - **ๅฎŒๅ…จๅฏน้ฝ่กŒไธšๆœ€ไฝณๅฎž่ทต** - ---- - -## โœ… ็ป“่ฎบ - -ๆ‰€ๆœ‰ๅœจ [้—ฎ้ข˜ #2](https://github.com/objectstack-ai/spec/issues/2) ไธญๆๅ‡บ็š„ๅ่ฎฎๆ‰ฉๅฑ•ๅปบ่ฎฎๅทฒ็ป **100% ๅฎŒๆˆๅฎž็Žฐ**: - -1. โœ… **Window Functions** - ๅฎŒๆ•ด็š„็ช—ๅฃๅ‡ฝๆ•ฐๆ”ฏๆŒ๏ผŒๅŒ…ๆ‹ฌ ROW_NUMBER, RANK, LAG, LEAD ็ญ‰ -2. โœ… **HAVING Clause** - ๆ”ฏๆŒๅฏน่šๅˆ็ป“ๆžœ่ฟ›่กŒ่ฟ‡ๆปค -3. โœ… **DISTINCT Query** - ไฝœไธบ QueryAST ็š„ไธ€้ƒจๅˆ†ๅฎž็Žฐ -4. โœ… **Subqueries** - ๆ”ฏๆŒๅœจ JOIN ไธญไฝฟ็”จๅญๆŸฅ่ฏข -5. โœ… **Vector Field Type** - ๅฎŒๆ•ด็š„ๅ‘้‡ๅตŒๅ…ฅๆ”ฏๆŒ๏ผŒ้€‚็”จไบŽ AI/ML ๅœบๆ™ฏ -6. โœ… **Location Field Type** - ๅฎŒๆ•ด็š„ๅœฐ็†ไฝ็ฝฎๆ”ฏๆŒ -7. โœ… **Driver Capabilities** - ๅฎŒๆ•ด็š„้ฉฑๅŠจ่ƒฝๅŠ›ๅฃฐๆ˜Ž็ณป็ปŸ - -**ObjectStack Query Protocol** ็Žฐๅœจๅทฒ่พพๅˆฐ **100% ๅฎŒๆ•ดๅบฆ**๏ผŒๅฎŒๅ…จๅฏน้ฝ่กŒไธšๆœ€ไฝณๅฎž่ทต๏ผŒๆ”ฏๆŒ็Žฐไปฃๅบ”็”จๅผ€ๅ‘็š„ๆ‰€ๆœ‰ๆ ธๅฟƒๅŠŸ่ƒฝใ€‚ - ---- - -## ๐Ÿ“ž ไธ‹ไธ€ๆญฅ่กŒๅŠจ - -ๅปบ่ฎฎ็š„ๅŽ็ปญๅทฅไฝœ: -1. โœ… ๆ›ดๆ–ฐ PROTOCOL_OPTIMIZATION_PLAN.md ไปฅๅๆ˜ ๅฎŒๆˆ็Šถๆ€ -2. โœ… ไธบๆ‰€ๆœ‰้ฉฑๅŠจๅฎž็Žฐ๏ผˆSQLใ€MongoDBใ€Memory๏ผ‰ๆ›ดๆ–ฐ่ƒฝๅŠ›ๅฃฐๆ˜Ž -3. โš ๏ธ ๆทปๅŠ ๆ›ดๅคšๅฎž้™…ไฝฟ็”จๅœบๆ™ฏ็š„็ซฏๅˆฐ็ซฏ็คบไพ‹ -4. โš ๏ธ ็ผ–ๅ†™่ฟ็งปๆŒ‡ๅ—๏ผŒๅธฎๅŠฉ็Žฐๆœ‰้กน็›ฎๅ‡็บงๅˆฐๆ–ฐๅ่ฎฎ - ---- - -**ๆœ€ๅŽๆ›ดๆ–ฐ**: 2026-01-27 -**ๆ–‡ๆกฃ็‰ˆๆœฌ**: 1.0.0 -**ๅ่ฎฎ็‰ˆๆœฌ**: 0.3.3+ diff --git a/PROTOCOL_INDEX.md b/PROTOCOL_INDEX.md deleted file mode 100644 index 2f204e119..000000000 --- a/PROTOCOL_INDEX.md +++ /dev/null @@ -1,204 +0,0 @@ -# ObjectStack Protocol Quick Index - -> **Fast navigation to all 70 protocol specifications** - -Last Updated: 2026-01-27 - -## Quick Links - -| Category | Count | Documentation | Source Code | -| :--- | :---: | :--- | :--- | -| **Data** | 8 | [docs/references/data/](./content/docs/references/data/) | [src/data/](./packages/spec/src/data/) | -| **UI** | 10 | [docs/references/ui/](./content/docs/references/ui/) | [src/ui/](./packages/spec/src/ui/) | -| **System** | 14 | [docs/references/system/](./content/docs/references/system/) | [src/system/](./packages/spec/src/system/) | -| **AI** | 8 | [docs/references/ai/](./content/docs/references/ai/) | [src/ai/](./packages/spec/src/ai/) | -| **API** | 6 | [docs/references/api/](./content/docs/references/api/) | [src/api/](./packages/spec/src/api/) | -| **Automation** | 7 | [docs/references/automation/](./content/docs/references/automation/) | [src/automation/](./packages/spec/src/automation/) | -| **Auth** | 6 | [docs/references/auth/](./content/docs/references/auth/) | [src/auth/](./packages/spec/src/auth/) | -| **Permission** | 4 | [docs/references/permission/](./content/docs/references/permission/) | [src/permission/](./packages/spec/src/permission/) | -| **Hub** | 5 | [docs/references/hub/](./content/docs/references/hub/) | [src/hub/](./packages/spec/src/hub/) | -| **Shared** | 1 | [docs/references/shared/](./content/docs/references/shared/) | [src/shared/](./packages/spec/src/shared/) | -| **Stack** | 1 | โ€” | [src/stack.zod.ts](./packages/spec/src/stack.zod.ts) | - -## Data Protocol (8 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Field** | [field.zod.ts](./packages/spec/src/data/field.zod.ts) | 44 field types for data modeling | -| **Object** | [object.zod.ts](./packages/spec/src/data/object.zod.ts) | Object/table definitions | -| **Query** | [query.zod.ts](./packages/spec/src/data/query.zod.ts) | Query AST with advanced features | -| **Validation** | [validation.zod.ts](./packages/spec/src/data/validation.zod.ts) | Validation rules | -| **Filter** | [filter.zod.ts](./packages/spec/src/data/filter.zod.ts) | Query filtering | -| **Dataset** | [dataset.zod.ts](./packages/spec/src/data/dataset.zod.ts) | Dataset definitions | -| **Mapping** | [mapping.zod.ts](./packages/spec/src/data/mapping.zod.ts) | Field mappings | -| **Hook** | [hook.zod.ts](./packages/spec/src/data/hook.zod.ts) | Lifecycle hooks | - -## UI Protocol (10 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **View** | [view.zod.ts](./packages/spec/src/ui/view.zod.ts) | List/form views | -| **Page** | [page.zod.ts](./packages/spec/src/ui/page.zod.ts) | FlexiPage layouts | -| **App** | [app.zod.ts](./packages/spec/src/ui/app.zod.ts) | App navigation | -| **Dashboard** | [dashboard.zod.ts](./packages/spec/src/ui/dashboard.zod.ts) | Dashboard layouts | -| **Report** | [report.zod.ts](./packages/spec/src/ui/report.zod.ts) | Report definitions | -| **Action** | [action.zod.ts](./packages/spec/src/ui/action.zod.ts) | UI actions | -| **Component** | [component.zod.ts](./packages/spec/src/ui/component.zod.ts) | Reusable components | -| **Block** | [block.zod.ts](./packages/spec/src/ui/block.zod.ts) | UI blocks | -| **Theme** | [theme.zod.ts](./packages/spec/src/ui/theme.zod.ts) | Theming system | -| **Widget** | [widget.zod.ts](./packages/spec/src/ui/widget.zod.ts) | Custom widgets | - -## System Protocol (14 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Manifest** | [manifest.zod.ts](./packages/spec/src/system/manifest.zod.ts) | Package manifest | -| **Datasource** | [datasource.zod.ts](./packages/spec/src/system/datasource.zod.ts) | Data source config | -| **Driver** | [driver.zod.ts](./packages/spec/src/system/driver.zod.ts) | Database drivers | -| **PostgreSQL** | [driver/postgres.zod.ts](./packages/spec/src/system/driver/postgres.zod.ts) | PostgreSQL driver | -| **MongoDB** | [driver/mongo.zod.ts](./packages/spec/src/system/driver/mongo.zod.ts) | MongoDB driver | -| **Plugin** | [plugin.zod.ts](./packages/spec/src/system/plugin.zod.ts) | Plugin interface | -| **Context** | [context.zod.ts](./packages/spec/src/system/context.zod.ts) | Kernel context | -| **Events** | [events.zod.ts](./packages/spec/src/system/events.zod.ts) | Event bus | -| **Job** | [job.zod.ts](./packages/spec/src/system/job.zod.ts) | Background jobs | -| **Audit** | [audit.zod.ts](./packages/spec/src/system/audit.zod.ts) | Audit logging | -| **Logger** | [logger.zod.ts](./packages/spec/src/system/logger.zod.ts) | Logging config | -| **Translation** | [translation.zod.ts](./packages/spec/src/system/translation.zod.ts) | i18n support | -| **Feature** | [feature.zod.ts](./packages/spec/src/system/feature.zod.ts) | Feature flags | -| **Storage** | [scoped-storage.zod.ts](./packages/spec/src/system/scoped-storage.zod.ts) | Key-value storage | - -## AI Protocol (8 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Agent** | [agent.zod.ts](./packages/spec/src/ai/agent.zod.ts) | AI agent definitions | -| **Model Registry** | [model-registry.zod.ts](./packages/spec/src/ai/model-registry.zod.ts) | LLM model registry | -| **RAG Pipeline** | [rag-pipeline.zod.ts](./packages/spec/src/ai/rag-pipeline.zod.ts) | RAG workflows | -| **NLQ** | [nlq.zod.ts](./packages/spec/src/ai/nlq.zod.ts) | Natural language query | -| **Conversation** | [conversation.zod.ts](./packages/spec/src/ai/conversation.zod.ts) | Conversation mgmt | -| **Cost** | [cost.zod.ts](./packages/spec/src/ai/cost.zod.ts) | Cost tracking | -| **Predictive** | [predictive.zod.ts](./packages/spec/src/ai/predictive.zod.ts) | Predictive models | -| **Orchestration** | [orchestration.zod.ts](./packages/spec/src/ai/orchestration.zod.ts) | AI orchestration | - -## API Protocol (6 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Contract** | [contract.zod.ts](./packages/spec/src/api/contract.zod.ts) | API contracts | -| **Endpoint** | [endpoint.zod.ts](./packages/spec/src/api/endpoint.zod.ts) | REST endpoints | -| **Router** | [router.zod.ts](./packages/spec/src/api/router.zod.ts) | API routing | -| **OData** | [odata.zod.ts](./packages/spec/src/api/odata.zod.ts) | OData support | -| **Realtime** | [realtime.zod.ts](./packages/spec/src/api/realtime.zod.ts) | Real-time subscriptions | -| **Discovery** | [discovery.zod.ts](./packages/spec/src/api/discovery.zod.ts) | API discovery | - -## Automation Protocol (7 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Flow** | [flow.zod.ts](./packages/spec/src/automation/flow.zod.ts) | Visual workflows | -| **Workflow** | [workflow.zod.ts](./packages/spec/src/automation/workflow.zod.ts) | Workflow rules | -| **Approval** | [approval.zod.ts](./packages/spec/src/automation/approval.zod.ts) | Approval processes | -| **Webhook** | [webhook.zod.ts](./packages/spec/src/automation/webhook.zod.ts) | Webhooks | -| **ETL** | [etl.zod.ts](./packages/spec/src/automation/etl.zod.ts) | ETL pipelines | -| **Sync** | [sync.zod.ts](./packages/spec/src/automation/sync.zod.ts) | Data sync | -| **Connector** | [connector.zod.ts](./packages/spec/src/automation/connector.zod.ts) | External connectors | - -## Auth Protocol (6 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Identity** | [identity.zod.ts](./packages/spec/src/auth/identity.zod.ts) | User identity | -| **Role** | [role.zod.ts](./packages/spec/src/auth/role.zod.ts) | Role definitions | -| **Organization** | [organization.zod.ts](./packages/spec/src/auth/organization.zod.ts) | Multi-org | -| **Policy** | [policy.zod.ts](./packages/spec/src/auth/policy.zod.ts) | Security policies | -| **Config** | [config.zod.ts](./packages/spec/src/auth/config.zod.ts) | OAuth/SAML/SSO | -| **SCIM** | [scim.zod.ts](./packages/spec/src/auth/scim.zod.ts) | SCIM provisioning | - -## Permission Protocol (4 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Permission** | [permission.zod.ts](./packages/spec/src/permission/permission.zod.ts) | Object permissions | -| **Sharing** | [sharing.zod.ts](./packages/spec/src/permission/sharing.zod.ts) | Sharing rules | -| **RLS** | [rls.zod.ts](./packages/spec/src/permission/rls.zod.ts) | Row-level security | -| **Territory** | [territory.zod.ts](./packages/spec/src/permission/territory.zod.ts) | Territories | - -## Hub Protocol (5 protocols) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Marketplace** | [marketplace.zod.ts](./packages/spec/src/hub/marketplace.zod.ts) | Plugin marketplace | -| **Composer** | [composer.zod.ts](./packages/spec/src/hub/composer.zod.ts) | Dependency mgmt | -| **License** | [license.zod.ts](./packages/spec/src/hub/license.zod.ts) | Feature licensing | -| **Tenant** | [tenant.zod.ts](./packages/spec/src/hub/tenant.zod.ts) | Multi-tenancy | -| **Space** | [space.zod.ts](./packages/spec/src/hub/space.zod.ts) | Workspace mgmt | - -## Shared Protocol (1 protocol) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Identifiers** | [identifiers.zod.ts](./packages/spec/src/shared/identifiers.zod.ts) | Common identifiers | - -## Stack Protocol (1 protocol) - -| Protocol | File | Description | -| :--- | :--- | :--- | -| **Stack** | [stack.zod.ts](./packages/spec/src/stack.zod.ts) | Root stack definition | - -## Documentation Resources - -- **[PROTOCOL_REFERENCE.md](./PROTOCOL_REFERENCE.md)** - Detailed reference with examples -- **[PROTOCOL_ORGANIZATION.md](./PROTOCOL_ORGANIZATION.md)** - Visual diagrams and relationships -- **[README.md](./README.md)** - Project overview -- **[ARCHITECTURE.md](./ARCHITECTURE.md)** - System architecture -- **[content/docs/references/](./content/docs/references/)** - Generated API documentation (473 files) - -## How to Use - -### View Source Code -```bash -# View a protocol definition -cat packages/spec/src/data/field.zod.ts - -# Search for specific schema -grep -r "FieldSchema" packages/spec/src/ -``` - -### Import in Code -```typescript -import { FieldSchema, ObjectSchema } from '@objectstack/spec/data'; -import { ViewSchema, AppSchema } from '@objectstack/spec/ui'; -import { ManifestSchema } from '@objectstack/spec/system'; -``` - -### Generate JSON Schema -```bash -# Build generates JSON schemas -pnpm --filter @objectstack/spec build - -# Output location -ls packages/spec/json-schema/ -``` - -### Generate Documentation -```bash -# Generate reference docs -pnpm --filter @objectstack/spec gen:docs - -# Output location -ls content/docs/references/ -``` - -## Version Information - -- **Protocol Version:** 0.3.3 -- **Total Protocols:** 70 -- **Generated Documentation Files:** 473 -- **Last Updated:** 2026-01-27 - ---- - -**See Also:** -- [Contributing Guide](./CONTRIBUTING.md) -- [Development Roadmap](./internal/planning/DEVELOPMENT_ROADMAP.md) -- [Protocol Extensions](./PROTOCOL_EXTENSIONS_COMPLETED.md) diff --git a/PROTOCOL_OPTIMIZATION_PLAN.md b/PROTOCOL_OPTIMIZATION_PLAN.md deleted file mode 100644 index 4944307c5..000000000 --- a/PROTOCOL_OPTIMIZATION_PLAN.md +++ /dev/null @@ -1,849 +0,0 @@ -# ObjectStack ๅ่ฎฎไผ˜ๅŒ–ไธŽ่ฐƒๆ•ด่ฎกๅˆ’ - -> **ๅˆๆฌก่ฏ„ไผฐๆ—ฅๆœŸ**: 2026-01-26 -> **ๆœ€ๅŽๆ›ดๆ–ฐ**: 2026-01-27 -> **่ฏ„ไผฐ่Œƒๅ›ด**: ObjectQL (ๆ•ฐๆฎๆ ธๅฟƒ) / ObjectUI (ไบคไบ’ไฝ“้ชŒ) / ObjectOS (ไธšๅŠก็ผ–ๆŽ’) -> **ๅฏนๆ ‡ๆ ‡ๅ‡†**: Salesforce, ServiceNow, Kubernetes, Prisma, OData v4, SCIM 2.0 - ---- - -## ๐Ÿ“‹ ๆ‰ง่กŒๆ‘˜่ฆ - -ๆœฌๆ–‡ๆกฃๅŸบไบŽ่กŒไธšๆœ€ไฝณๅฎž่ทต๏ผŒๅฏน ObjectStack ็Žฐๆœ‰ๅ่ฎฎ่ฟ›่กŒๅ…จ้ข่ฏ„ไผฐ๏ผŒ่ฏ†ๅˆซ็ผบๅฃๅนถๆๅ‡บไผ˜ๅŒ–่ฎกๅˆ’ใ€‚ - -### ๆ ธๅฟƒๅ‘็Žฐ (ๆ›ดๆ–ฐไบŽ 2026-01-27) - -1. โœ… **ๅทฒๅฎŒๆˆๅ่ฎฎ** (90%+): ObjectStack ๅทฒ็ปๅฎž็Žฐไบ†ๅคง้ƒจๅˆ†ๆ ธๅฟƒๅ่ฎฎ - - โœ… **Query Protocol 100% ๅฎŒๆˆ** - Window Functions, HAVING, DISTINCT, Subqueries ๅ…จ้ƒจๅฎž็Žฐ - - โœ… **Schema Definition 100% ๅฎŒๆˆ** - Vector ๅ’Œ Location ๅญ—ๆฎต็ฑปๅž‹ๅทฒ็บณๅ…ฅๅ่ฎฎ -2. โš ๏ธ **้œ€่ฆๅขžๅผบ** (7%): ้ƒจๅˆ†ๅ่ฎฎ้œ€่ฆ่กฅๅ……่กŒไธšๆ ‡ๅ‡†็‰นๆ€ง -3. ๐Ÿ†• **้œ€่ฆๆ–ฐๅขž** (3%): ๅฐ‘้‡ๅ…ณ้”ฎๅ่ฎฎๅฐšๆœชๅฎž็Žฐ - -> ๐Ÿ“˜ **้‡่ฆๆ›ดๆ–ฐ**: ๅ‚่ง [PROTOCOL_EXTENSIONS_COMPLETED.md](./PROTOCOL_EXTENSIONS_COMPLETED.md) ไบ†่งฃๆœ€ๆ–ฐๅฎŒๆˆ็š„ๅ่ฎฎๆ‰ฉๅฑ•่ฏฆๆƒ…ใ€‚ - ---- - -## 1๏ธโƒฃ ObjectQL๏ผšๆ•ฐๆฎไธŽๆจกๅž‹ๅฑ‚ (The "Brain") - -### 1.1 Schema Definition DSL โœ… ๅฎŒๆ•ดๅบฆ: 100% (ๆ›ดๆ–ฐไบŽ 2026-01-27) - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Objects ๅฎšไน‰ (`object.zod.ts`) - ๅฎŒๆ•ดๆ”ฏๆŒ -- โœ… Fields ๅญ—ๆฎต็ฑปๅž‹ (`field.zod.ts`) - 44 ็งๅญ—ๆฎต็ฑปๅž‹ - - ๅŸบ็ก€็ฑปๅž‹: text, number, date, boolean, select - - ๅ…ณ็ณป็ฑปๅž‹: lookup, master_detail, tree - - ้ซ˜็บง็ฑปๅž‹: formula, summary, autonumber - - ๅขžๅผบ็ฑปๅž‹: location, address, qrcode, slider, rating, code, color, signature - - **AI/ML ็ฑปๅž‹**: vector (ๅ‘้‡ๅตŒๅ…ฅ๏ผŒ็”จไบŽ่ฏญไน‰ๆœ็ดขๅ’Œ RAG) โœ… ๅทฒ็บณๅ…ฅๅ่ฎฎ -- โœ… Relationships: Lookup, Master-Detail, Hierarchical -- โœ… Field Level Security (FLS) -- โœ… Object Capabilities (History, API, Search, etc.) -- โœ… Vector Field Configuration (VectorConfigSchema) - ๆ”ฏๆŒๅคš็ง่ท็ฆปๅบฆ้‡ๅ’Œ็ดขๅผ•็ฎ—ๆณ• -- โœ… Location Field Configuration (LocationCoordinatesSchema) - GPS ๅๆ ‡ๆ”ฏๆŒ - -> ๐Ÿ“˜ **่ฏฆ็ป†ๆ–‡ๆกฃ**: ๅ‚่ง [PROTOCOL_EXTENSIONS_COMPLETED.md](./PROTOCOL_EXTENSIONS_COMPLETED.md) ไบ†่งฃ Vector ๅ’Œ Location ๅญ—ๆฎต็ฑปๅž‹็š„ๅฎŒๆ•ดๅฎž็Žฐ็ป†่Š‚ใ€‚ - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. ~~**ๆทปๅŠ  Vector ๅญ—ๆฎต็ฑปๅž‹** (ๅฏนๆ ‡ pgvector, MongoDB Atlas Vector Search)~~ - โœ… ๅทฒๅฎŒๆˆ (2026-01-27) -2. ~~**ๆทปๅŠ  Location ๅญ—ๆฎต็ฑปๅž‹** (ๅฏนๆ ‡ PostGIS, MongoDB GeoJSON)~~ - โœ… ๅทฒๅฎŒๆˆ (2026-01-27) -3. **ๆทปๅŠ  Schema ่ฟ็งปๅ่ฎฎ** (ๅฏนๆ ‡ Prisma Migrate) - ๐Ÿ”œ ๆœชๆฅๅขžๅผบ - ```typescript - // ๆ–ฐๅขž: packages/spec/src/data/migration.zod.ts - export const MigrationSchema = z.object({ - version: z.string().describe('Migration version'), - operations: z.array(z.discriminatedUnion('type', [ - AlterTableSchema, - AddFieldSchema, - DropFieldSchema, - RenameFieldSchema, - AddIndexSchema, - ])), - rollback: z.array(MigrationOperationSchema).optional(), - }); - ``` - -4. **ๆทปๅŠ  Virtual Fields ๆ”ฏๆŒ** (ๅฏนๆ ‡ Salesforce Formula Fields) - ๐Ÿ”œ ๆœชๆฅๅขžๅผบ - - ๅฝ“ๅ‰ `formula` ๅญ—ๆฎตๅทฒๅญ˜ๅœจ๏ผŒไฝ†้œ€่ฆๆ˜Ž็กฎ่ฎก็ฎ—ๆ—ถๆœบ (ๅฎžๆ—ถ vs ๅญ˜ๅ‚จ) - ```typescript - // ๅขžๅผบ: packages/spec/src/data/field.zod.ts - formula: z.string().optional(), - formulaMode: z.enum(['computed', 'stored']).default('computed'), - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - **ๅญ—ๆฎต็ฑปๅž‹็ณป็ปŸๅทฒๅฎŒๅ…จๅฏน้ฝ่กŒไธšๆ ‡ๅ‡†๏ผŒๅŒ…ๆ‹ฌ AI/ML ๅ’Œๅœฐ็†ไฝ็ฝฎๅŠŸ่ƒฝ** - ---- - -### 1.2 Query Protocol โœ… ๅฎŒๆ•ดๅบฆ: 100% (ๆ›ดๆ–ฐไบŽ 2026-01-27) - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Filtering (AND/OR, Nested) - `filter.zod.ts` -- โœ… Aggregation (Sum, Count, GroupBy) - `query.zod.ts` -- โœ… Window Functions (ROW_NUMBER, RANK, LAG, LEAD, DENSE_RANK, PERCENT_RANK, FIRST_VALUE, LAST_VALUE) - `query.zod.ts:236-381` -- โœ… HAVING Clause (่ฟ‡ๆปค่šๅˆ็ป“ๆžœ) - `query.zod.ts:457` -- โœ… DISTINCT Query (ๅŽป้‡ๆŸฅ่ฏข) - `query.zod.ts:463` -- โœ… Subqueries (ๅญๆŸฅ่ฏขๆ”ฏๆŒ) - `query.zod.ts:231` -- โœ… Joins (Inner, Left, Right, Full) - `query.zod.ts` -- โœ… Pagination (Limit/Offset + Cursor) - `query.zod.ts` -- โœ… Sorting (ๆŽ’ๅบ) - `query.zod.ts` - -> ๐Ÿ“˜ **่ฏฆ็ป†ๆ–‡ๆกฃ**: ๅ‚่ง [PROTOCOL_EXTENSIONS_COMPLETED.md](./PROTOCOL_EXTENSIONS_COMPLETED.md) ไบ†่งฃๅฎŒๆ•ดๅฎž็Žฐ็ป†่Š‚ๅ’Œไฝฟ็”จ็คบไพ‹ใ€‚ - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. ~~**ๆทปๅŠ ็ช—ๅฃๅ‡ฝๆ•ฐ (Window Functions)** - โœ… ๅทฒๅฎŒๆˆ (2026-01-27)~~ -2. ~~**ๆทปๅŠ  HAVING ๅญๅฅ** - โœ… ๅทฒๅฎŒๆˆ (2026-01-27)~~ -3. ~~**ๆทปๅŠ  DISTINCT ๆŸฅ่ฏข** - โœ… ๅทฒๅฎŒๆˆ (2026-01-27)~~ -4. ~~**ๆทปๅŠ ๅญๆŸฅ่ฏขๆ”ฏๆŒ (Subqueries)** - โœ… ๅทฒๅฎŒๆˆ (2026-01-27)~~ -5. **ๆทปๅŠ  OData v4 ๅ…ผๅฎนๅฑ‚** (ๅฏนๆ ‡ Microsoft Dynamics) - ๐Ÿ”œ ๆœชๆฅๅขžๅผบ - ```typescript - // ๆ–ฐๅขž: packages/spec/src/api/odata.zod.ts - export const ODataQuerySchema = z.object({ - $select: z.array(z.string()).optional(), - $filter: z.string().optional(), // OData filter syntax - $orderby: z.string().optional(), - $top: z.number().optional(), - $skip: z.number().optional(), - $expand: z.string().optional(), - $count: z.boolean().optional(), - }); - ``` - -6. **ๆทปๅŠ  GraphQL Schema ็”Ÿๆˆ** (ๅฏนๆ ‡ Hasura) - ๐Ÿ”œ ๆœชๆฅๅขžๅผบ - - ่‡ชๅŠจไปŽ ObjectSchema ็”Ÿๆˆ GraphQL SDL - ```typescript - // ๆ–ฐๅขž: packages/spec/src/api/graphql-schema.zod.ts - export const GraphQLSchemaGeneratorConfig = z.object({ - objects: z.array(z.string()).optional(), - excludeFields: z.record(z.array(z.string())).optional(), - customResolvers: z.record(z.any()).optional(), - }); - ``` - -7. **ๆทปๅŠ ๆŸฅ่ฏขๆ€ง่ƒฝๅˆ†ๆž** (ๅฏนๆ ‡ Salesforce Query Plan) - ๐Ÿ”œ ๆœชๆฅๅขžๅผบ - ```typescript - // ๆ–ฐๅขž: packages/spec/src/data/query-plan.zod.ts - export const QueryPlanSchema = z.object({ - estimatedCost: z.number(), - steps: z.array(z.object({ - operation: z.string(), - cost: z.number(), - cardinality: z.number(), - })), - warnings: z.array(z.string()).optional(), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - **ๆ ธๅฟƒๆŸฅ่ฏขๅŠŸ่ƒฝๅทฒ่พพๅˆฐ่กŒไธšๆœ€ไฝณๅฎž่ทตๆ ‡ๅ‡†** - ---- - -### 1.3 Validation Protocol โœ… ๅฎŒๆ•ดๅบฆ: 95% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Script Validation (Formula-based) -- โœ… Uniqueness Validation -- โœ… State Machine Validation -- โœ… Format Validation (Regex, Email, URL) -- โœ… Cross-Field Validation -- โœ… Conditional Validation -- โœ… Async Validation (External API) -- โœ… JSON Schema Validation - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ  Validation Error I18n** (ๅคš่ฏญ่จ€้”™่ฏฏๆถˆๆฏ) - ```typescript - // ๅขžๅผบ: packages/spec/src/data/validation.zod.ts - message: z.union([ - z.string(), - z.record(z.string()), // { en: "...", zh: "...", fr: "..." } - ]).describe('Error message or i18n map'), - ``` - -2. **ๆทปๅŠ  Batch Validation ไผ˜ๅŒ–** (ๅฏนๆ ‡ ServiceNow) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/data/validation-batch.zod.ts - export const BatchValidationConfigSchema = z.object({ - parallel: z.boolean().default(true), - failFast: z.boolean().default(false), - maxConcurrency: z.number().default(10), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - ---- - -### 1.4 Security Protocol โš ๏ธ ๅฎŒๆ•ดๅบฆ: 70% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Object Permissions (CRUD) - `permission.zod.ts` -- โœ… Field Level Security (FLS) -- โœ… Sharing Rules - `sharing.zod.ts` -- โœ… Role Hierarchy - `role.zod.ts` - -**ๅ…ณ้”ฎ็ผบๅคฑ** ๐Ÿ†•: -1. **Row-Level Security (RLS)** - ๅฏนๆ ‡ PostgreSQL RLS / Salesforce Criteria-Based Sharing - ```typescript - // ๆ–ฐๅขž: packages/spec/src/permission/rls.zod.ts - export const RowLevelSecuritySchema = z.object({ - name: z.string().regex(/^[a-z_][a-z0-9_]*$/), - object: z.string().describe('Target object'), - operation: z.enum(['select', 'insert', 'update', 'delete']), - using: z.string().describe('WHERE clause condition (e.g. "owner_id = current_user_id")'), - check: z.string().optional().describe('INSERT/UPDATE check condition'), - roles: z.array(z.string()).optional().describe('Apply to specific roles'), - }); - ``` - -2. **API Scopes & OAuth Scopes** (ๅฏนๆ ‡ Salesforce Connected Apps) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/auth/oauth-scope.zod.ts - export const OAuthScopeSchema = z.object({ - name: z.string().describe('Scope name (e.g. "api", "refresh_token", "full")'), - label: z.string(), - description: z.string().optional(), - permissions: z.array(z.string()).describe('Granted permissions'), - }); - ``` - -3. **Data Masking & Field Encryption** (ๅฏนๆ ‡ Salesforce Shield) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/permission/data-masking.zod.ts - export const DataMaskingRuleSchema = z.object({ - object: z.string(), - field: z.string(), - maskingType: z.enum([ - 'full', // *********** - 'partial', // ****5678 - 'hash', // SHA-256 - 'tokenize', // Replace with token - 'random', // Random data - ]), - visibleToRoles: z.array(z.string()).optional(), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญ (3/5) - ้œ€่ฆ่กฅๅ…… RLS - ---- - -## 2๏ธโƒฃ ObjectUI๏ผš็•Œ้ขไธŽไบคไบ’ๅฑ‚ (The "Face") - -### 2.1 View DSL โœ… ๅฎŒๆ•ดๅบฆ: 90% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Layouts (Grid, Kanban, Calendar, Gantt) - `view.zod.ts` -- โœ… Form Views (Simple, Tabbed, Wizard) -- โœ… Data Binding (Object, API, Static) -- โœ… Component Props (Field overrides) - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ ๅ“ๅบ”ๅผๅธƒๅฑ€ๆ–ญ็‚น** (ๅฏนๆ ‡ TailwindCSS) - ```typescript - // ๅขžๅผบ: packages/spec/src/ui/view.zod.ts - responsive: z.object({ - sm: z.number().optional(), // Mobile - md: z.number().optional(), // Tablet - lg: z.number().optional(), // Desktop - xl: z.number().optional(), // Wide Desktop - }).optional().describe('Responsive column spans'), - ``` - -2. **ๆทปๅŠ ๆกไปถๆธฒๆŸ“ๅ่ฎฎ** (ๅฏนๆ ‡ Salesforce Dynamic Forms) - ```typescript - // ๅขžๅผบ: packages/spec/src/ui/view.zod.ts - conditionalRendering: z.array(z.object({ - condition: z.string().describe('Formula condition'), - show: z.array(z.string()).describe('Fields to show'), - hide: z.array(z.string()).describe('Fields to hide'), - })).optional(), - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญ (4/5) - ---- - -### 2.2 Widget Contract โš ๏ธ ๅฎŒๆ•ดๅบฆ: 50% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Basic widget schema - `widget.zod.ts` -- โœ… Field type mapping - -**ๅ…ณ้”ฎ็ผบๅคฑ** ๐Ÿ†•: -1. **Widget Lifecycle Hooks** (ๅฏนๆ ‡ Web Components) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/ui/widget-lifecycle.zod.ts - export const WidgetLifecycleSchema = z.object({ - onMount: z.string().optional().describe('Called when widget is rendered'), - onUpdate: z.string().optional().describe('Called when props change'), - onUnmount: z.string().optional().describe('Called when widget is removed'), - onValidate: z.string().optional().describe('Custom validation logic'), - }); - ``` - -2. **Widget Event Protocol** (ๅฏนๆ ‡ Lightning Web Components) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/ui/widget-events.zod.ts - export const WidgetEventSchema = z.object({ - name: z.string().describe('Event name'), - bubbles: z.boolean().default(false), - cancelable: z.boolean().default(false), - payload: z.record(z.any()).describe('Event payload schema'), - }); - ``` - -3. **Widget Props Interface** (ๅฏนๆ ‡ React Props) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/ui/widget-props.zod.ts - export const WidgetPropsSchema = z.object({ - name: z.string(), - label: z.string(), - type: z.string().describe('TypeScript type'), - required: z.boolean().default(false), - default: z.any().optional(), - description: z.string().optional(), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญ (2/5) - ้œ€่ฆๅฎŒๆ•ด็š„ Widget ๅˆ็บฆ็ณป็ปŸ - ---- - -### 2.3 Action Protocol โœ… ๅฎŒๆ•ดๅบฆ: 85% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Action Types (Script, URL, Modal, Flow, API) - `action.zod.ts` -- โœ… Triggers (OnClick, Location-based) -- โœ… Confirmation & Success Messages - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ ๆกไปถๆ‰ง่กŒ** (ๅฏนๆ ‡ Salesforce Dynamic Actions) - ```typescript - // ๅขžๅผบ: packages/spec/src/ui/action.zod.ts - condition: z.string().optional().describe('Formula condition to enable action'), - ``` - -2. **ๆทปๅŠ ๆ‰น้‡ๆ“ไฝœๆ”ฏๆŒ** - ```typescript - // ๅขžๅผบ: packages/spec/src/ui/action.zod.ts - batchSupport: z.boolean().default(false).describe('Support batch selection'), - batchLimit: z.number().optional().describe('Max records for batch'), - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญ (4/5) - ---- - -### 2.4 Navigation DSL โœ… ๅฎŒๆ•ดๅบฆ: 90% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Menu Structure (Hierarchical) - `app.zod.ts` -- โœ… Routing (Object, Dashboard, Page, URL) -- โœ… Breadcrumbs (implicitly via hierarchy) - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ ๅŠจๆ€้ขๅŒ…ๅฑ‘้…็ฝฎ** - ```typescript - // ๅขžๅผบ: packages/spec/src/ui/navigation.zod.ts - export const BreadcrumbConfigSchema = z.object({ - enabled: z.boolean().default(true), - maxDepth: z.number().default(3), - customLabels: z.record(z.string()).optional(), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - ---- - -## 3๏ธโƒฃ ObjectOS๏ผšไธšๅŠกไธŽ็ณป็ปŸๅฑ‚ (The "Heart") - -### 3.1 Workflow Protocol โœ… ๅฎŒๆ•ดๅบฆ: 95% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Workflow Rules - `workflow.zod.ts` -- โœ… State Machine - `validation.zod.ts` (State Machine Validation) -- โœ… 10+ Action Types (Email, Slack, Webhook, Field Update, etc.) -- โœ… Time Triggers -- โœ… Flow Orchestration - `flow.zod.ts` - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ  BPMN 2.0 ๅ…ผๅฎนๆจกๅผ** (ๅฏนๆ ‡ Camunda) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/automation/bpmn.zod.ts - export const BPMNProcessSchema = z.object({ - id: z.string(), - name: z.string(), - startEvents: z.array(BPMNStartEventSchema), - tasks: z.array(BPMNTaskSchema), - gateways: z.array(BPMNGatewaySchema), - endEvents: z.array(BPMNEndEventSchema), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - ---- - -### 3.2 Plugin Manifest โœ… ๅฎŒๆ•ดๅบฆ: 90% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Lifecycle Hooks (Install, Enable, Disable, Uninstall) - `plugin.zod.ts` -- โœ… Dependencies - `manifest.zod.ts` -- โœ… Capabilities Declaration (API, UI, Jobs) -- โœ… Configuration Schema -- โœ… Contribution Points (Kinds, Events, Menus, Themes) - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ ๆ’ไปถๆฒ™็ฎฑ้…็ฝฎ** (ๅฏนๆ ‡ VS Code Extensions) - ```typescript - // ๅขžๅผบ: packages/spec/src/kernel/manifest.zod.ts - sandbox: z.object({ - enabled: z.boolean().default(true), - permissions: z.array(z.string()), - resourceLimits: z.object({ - maxMemoryMb: z.number().default(512), - maxCpuPercent: z.number().default(50), - }), - }).optional(), - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - ---- - -### 3.3 Integration Protocol โš ๏ธ ๅฎŒๆ•ดๅบฆ: 60% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Webhooks (Outbound) - `webhook.zod.ts` -- โœ… Webhook Receivers (Inbound) -- โœ… API Endpoints - `endpoint.zod.ts` -- โœ… Data Mapping - `mapping.zod.ts` - -**ๅ…ณ้”ฎ็ผบๅคฑ** ๐Ÿ†•: -1. **ETL Pipeline Protocol** (ๅฏนๆ ‡ Airbyte) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/automation/etl.zod.ts - export const ETLPipelineSchema = z.object({ - name: z.string().regex(/^[a-z_][a-z0-9_]*$/), - source: z.object({ - type: z.enum(['database', 'api', 'file', 'stream']), - config: z.record(z.any()), - }), - destination: z.object({ - type: z.enum(['database', 'api', 'file', 'stream']), - config: z.record(z.any()), - }), - transformations: z.array(z.object({ - type: z.enum(['map', 'filter', 'aggregate', 'join', 'script']), - config: z.record(z.any()), - })), - schedule: z.string().optional().describe('Cron expression'), - }); - ``` - -2. **Connector Registry** (ๅฏนๆ ‡ Zapier Integration Schema) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/automation/connector.zod.ts - export const ConnectorSchema = z.object({ - id: z.string().describe('Connector ID (e.g. "salesforce", "stripe")'), - name: z.string(), - description: z.string().optional(), - category: z.enum(['crm', 'payment', 'storage', 'communication', 'analytics']), - authentication: z.discriminatedUnion('type', [ - OAuth2AuthSchema, - APIKeyAuthSchema, - BasicAuthSchema, - ]), - operations: z.array(z.object({ - id: z.string(), - name: z.string(), - type: z.enum(['read', 'write', 'trigger']), - inputSchema: z.record(z.any()), - outputSchema: z.record(z.any()), - })), - triggers: z.array(z.object({ - id: z.string(), - name: z.string(), - type: z.enum(['webhook', 'polling']), - config: z.record(z.any()), - })).optional(), - }); - ``` - -3. **Data Sync Protocol** (ๅฏนๆ ‡ Salesforce Connect) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/automation/sync.zod.ts - export const DataSyncConfigSchema = z.object({ - name: z.string(), - source: z.object({ - object: z.string(), - filters: z.any().optional(), - }), - destination: z.object({ - connector: z.string(), - operation: z.string(), - mapping: z.record(z.string()), - }), - syncMode: z.enum(['full', 'incremental']), - schedule: z.string().optional(), - conflictResolution: z.enum(['source_wins', 'destination_wins', 'manual']), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญ (3/5) - ้œ€่ฆ่กฅๅ…… ETL & Connectors - ---- - -### 3.4 Identity & SSO โš ๏ธ ๅฎŒๆ•ดๅบฆ: 65% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… User Model - `identity.zod.ts` -- โœ… Account Linking (OAuth, OIDC, SAML) -- โœ… Session Management -- โœ… Multi-Organization Support - -**ๅ…ณ้”ฎ็ผบๅคฑ** ๐Ÿ†•: -1. **SCIM 2.0 Protocol** (ๅฏนๆ ‡ Okta, Azure AD) - โญ ้‡็‚นๆŽจ่ - ```typescript - // ๆ–ฐๅขž: packages/spec/src/auth/scim.zod.ts - export const SCIMUserSchema = z.object({ - schemas: z.array(z.string()).default(['urn:ietf:params:scim:schemas:core:2.0:User']), - id: z.string().optional(), - externalId: z.string().optional(), - userName: z.string().describe('Unique identifier'), - name: z.object({ - formatted: z.string().optional(), - familyName: z.string().optional(), - givenName: z.string().optional(), - middleName: z.string().optional(), - honorificPrefix: z.string().optional(), - honorificSuffix: z.string().optional(), - }).optional(), - emails: z.array(z.object({ - value: z.string().email(), - type: z.enum(['work', 'home', 'other']).optional(), - primary: z.boolean().default(false), - })), - active: z.boolean().default(true), - groups: z.array(z.object({ - value: z.string(), - display: z.string().optional(), - })).optional(), - meta: z.object({ - resourceType: z.string().default('User'), - created: z.string().datetime().optional(), - lastModified: z.string().datetime().optional(), - location: z.string().url().optional(), - }).optional(), - }); - - export const SCIMGroupSchema = z.object({ - schemas: z.array(z.string()).default(['urn:ietf:params:scim:schemas:core:2.0:Group']), - id: z.string().optional(), - displayName: z.string(), - members: z.array(z.object({ - value: z.string(), - display: z.string().optional(), - })).optional(), - meta: z.object({ - resourceType: z.string().default('Group'), - created: z.string().datetime().optional(), - lastModified: z.string().datetime().optional(), - }).optional(), - }); - ``` - -2. **Federation Protocol** (LDAP/AD Integration) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/auth/federation.zod.ts - export const LDAPConfigSchema = z.object({ - enabled: z.boolean().default(false), - server: z.string().describe('LDAP server URL (e.g. ldap://ad.company.com)'), - port: z.number().default(389), - useSsl: z.boolean().default(false), - baseDn: z.string().describe('Base DN (e.g. dc=company,dc=com)'), - bindDn: z.string().describe('Bind DN for authentication'), - bindPassword: z.string().describe('Bind password'), - userFilter: z.string().describe('User search filter (e.g. (sAMAccountName={username}))'), - attributeMapping: z.object({ - username: z.string().default('sAMAccountName'), - email: z.string().default('mail'), - firstName: z.string().default('givenName'), - lastName: z.string().default('sn'), - groups: z.string().default('memberOf'), - }), - }); - ``` - -3. **Just-in-Time (JIT) Provisioning** (ๅฏนๆ ‡ Salesforce SSO) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/auth/jit-provisioning.zod.ts - export const JITProvisioningSchema = z.object({ - enabled: z.boolean().default(false), - createUsers: z.boolean().default(true), - updateUsers: z.boolean().default(true), - defaultRole: z.string().optional(), - defaultProfile: z.string().optional(), - attributeMapping: z.record(z.string()), - groupMapping: z.record(z.string()).optional(), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญ (3/5) - ้œ€่ฆ่กฅๅ…… SCIM 2.0 - ---- - -### 3.5 Telemetry Protocol โœ… ๅฎŒๆ•ดๅบฆ: 95% - -#### ็Žฐ็Šถ่ฏ„ไผฐ -**ๅทฒๅฎž็Žฐ**: -- โœ… Audit Logs - `audit.zod.ts` -- โœ… Event Types (50+ events) -- โœ… Retention Policies -- โœ… Suspicious Activity Detection -- โœ… Compliance Modes (SOX, HIPAA, GDPR) - -**ไผ˜ๅŒ–ๅปบ่ฎฎ** โš ๏ธ: -1. **ๆทปๅŠ  OpenTelemetry ๅ…ผๅฎน** (ๅฏนๆ ‡ OTELๆ ‡ๅ‡†) - ```typescript - // ๆ–ฐๅขž: packages/spec/src/system/telemetry-otel.zod.ts - export const OpenTelemetryConfigSchema = z.object({ - enabled: z.boolean().default(false), - endpoint: z.string().url().describe('OTLP endpoint'), - serviceName: z.string().default('objectstack'), - tracing: z.object({ - enabled: z.boolean().default(true), - sampleRate: z.number().min(0).max(1).default(1), - }), - metrics: z.object({ - enabled: z.boolean().default(true), - interval: z.number().default(60000).describe('Export interval in ms'), - }), - logs: z.object({ - enabled: z.boolean().default(true), - }), - }); - ``` - -**่กŒไธšๅฏนๆ ‡**: โญโญโญโญโญ (5/5) - ---- - -## ๐Ÿ“Š ๆ€ปไฝ“ๅฎŒๆ•ดๅบฆ่ฏ„ๅˆ† (ๆ›ดๆ–ฐไบŽ 2026-01-27) - -| ๅฑ‚็บง | ๆจกๅ— | ๅฎŒๆ•ดๅบฆ | ๅ˜ๅŒ– | ไผ˜ๅ…ˆ็บง | ็Šถๆ€ | -|------|------|--------|------|--------|------| -| **ObjectQL** | Schema Definition DSL | **100%** | โฌ†๏ธ +5% | P2 | โœ… **ๅฎŒๆ•ด** (Vector & Location ๅทฒๅฎž็Žฐ) | -| | Query Protocol | **100%** | โฌ†๏ธ +10% | P1 | โœ… **ๅฎŒๆ•ด** (Window Functions, HAVING, DISTINCT ๅทฒๅฎž็Žฐ) | -| | Validation Protocol | 95% | - | P3 | โœ… ๅฎŒๆ•ด | -| | Security Protocol | 70% | - | P0 | ๐Ÿ†• ้œ€่ฆ RLS | -| **ObjectUI** | View DSL | 90% | - | P2 | โš ๏ธ ้œ€่ฆๅ“ๅบ”ๅผ | -| | Widget Contract | 50% | - | P1 | ๐Ÿ†• ้œ€่ฆๅฎŒๆ•ดๅˆ็บฆ | -| | Action Protocol | 85% | - | P3 | โš ๏ธ ้œ€่ฆๆกไปถๆ‰ง่กŒ | -| | Navigation DSL | 90% | - | P3 | โœ… ๅฎŒๆ•ด | -| **ObjectOS** | Workflow Protocol | 95% | - | P3 | โœ… ๅฎŒๆ•ด | -| | Plugin Manifest | 90% | - | P3 | โš ๏ธ ้œ€่ฆๆฒ™็ฎฑ | -| | Integration Protocol | 60% | - | P1 | ๐Ÿ†• ้œ€่ฆ ETL | -| | Identity & SSO | 65% | - | P0 | ๐Ÿ†• ้œ€่ฆ SCIM 2.0 | -| | Telemetry Protocol | 95% | - | P2 | โš ๏ธ ้œ€่ฆ OTEL | - -**ๆ€ปไฝ“ๅฎŒๆ•ดๅบฆ**: **87%** โœ… (โฌ†๏ธ +4% ไปŽไธŠๆฌก่ฏ„ไผฐ) - -> ๐Ÿ“˜ **้‡ๅคง่ฟ›ๅฑ•**: ObjectQL ๆ•ฐๆฎๅฑ‚ๆ ธๅฟƒๆŸฅ่ฏขๅ’Œๅญ—ๆฎต็ฑปๅž‹ๅŠŸ่ƒฝๅทฒ่พพๅˆฐ 100% ๅฎŒๆ•ดๅบฆ๏ผ่ฏฆ่ง [PROTOCOL_EXTENSIONS_COMPLETED.md](./PROTOCOL_EXTENSIONS_COMPLETED.md) - ---- - -## ๐ŸŽฏ ๅฎžๆ–ฝ่ฎกๅˆ’ - -### Sprint 1 (P0 - ๅ…ณ้”ฎ็ผบๅคฑ) - 2ๅ‘จ - -#### 1. Row-Level Security (RLS) ๐Ÿ”’ -**ๆ–‡ไปถ**: `packages/spec/src/permission/rls.zod.ts` -```typescript -export const RowLevelSecuritySchema = z.object({ - name: z.string().regex(/^[a-z_][a-z0-9_]*$/), - object: z.string(), - operation: z.enum(['select', 'insert', 'update', 'delete']), - using: z.string(), - check: z.string().optional(), - roles: z.array(z.string()).optional(), -}); -``` -**ๆต‹่ฏ•**: `packages/spec/src/permission/rls.test.ts` -**ๆ–‡ๆกฃ**: `content/docs/specifications/security/rls.mdx` - -#### 2. SCIM 2.0 Protocol ๐Ÿ‘ฅ -**ๆ–‡ไปถ**: -- `packages/spec/src/auth/scim.zod.ts` (ๅŒ…ๅซ User, Group, Enterprise Extension) -- `packages/spec/src/auth/scim.test.ts` - -**ๆต‹่ฏ•**: `packages/spec/src/auth/scim.test.ts` -**ๆ–‡ๆกฃ**: `content/docs/specifications/auth/scim.mdx` - -**้ชŒๆ”ถๆ ‡ๅ‡†**: -- [ ] SCIM User Schema ๅฎŒๆ•ด -- [ ] SCIM Group Schema ๅฎŒๆ•ด -- [ ] ๆ”ฏๆŒๆ ‡ๅ‡† SCIM operations (GET, POST, PUT, PATCH, DELETE) -- [ ] ๆ”ฏๆŒ SCIM filter query -- [ ] ๆต‹่ฏ•่ฆ†็›–็އ โ‰ฅ 90% - ---- - -### Sprint 2 (P1 - ้ซ˜ไผ˜ๅ…ˆ็บงๅขžๅผบ) - 3ๅ‘จ - -#### 1. Widget Contract System ๐ŸŽจ -**ๆ–‡ไปถ**: -- `packages/spec/src/ui/widget-lifecycle.zod.ts` -- `packages/spec/src/ui/widget-events.zod.ts` -- `packages/spec/src/ui/widget-props.zod.ts` -- `packages/spec/src/ui/widget-manifest.zod.ts` - -**้ชŒๆ”ถๆ ‡ๅ‡†**: -- [ ] Lifecycle hooks (mount/update/unmount/validate) -- [ ] Event protocol (bubbles/cancelable/payload) -- [ ] Props interface schema -- [ ] Widget registry mechanism - -#### 2. ETL & Integration Connectors ๐Ÿ”Œ -**ๆ–‡ไปถ**: -- `packages/spec/src/automation/etl.zod.ts` -- `packages/spec/src/automation/connector.zod.ts` -- `packages/spec/src/automation/sync.zod.ts` - -**้ชŒๆ”ถๆ ‡ๅ‡†**: -- [ ] ETL Pipeline definition -- [ ] Connector registry schema -- [ ] Data sync configuration -- [ ] 10+ ้ข„ๅฎšไน‰ connectors (Salesforce, Stripe, etc.) - -#### 3. OData v4 Compatibility Layer ๐ŸŒ -**ๆ–‡ไปถ**: `packages/spec/src/api/odata.zod.ts` - -**้ชŒๆ”ถๆ ‡ๅ‡†**: -- [ ] OData query syntax parser -- [ ] $filter, $select, $expand, $orderby ๆ”ฏๆŒ -- [ ] Query AST ่ฝฌๆขๅ™จ - ---- - -### Sprint 3 (P2 - ไธญไผ˜ๅ…ˆ็บงไผ˜ๅŒ–) - 2ๅ‘จ - -#### 1. Schema Migration Protocol ๐Ÿ”„ -**ๆ–‡ไปถ**: `packages/spec/src/data/migration.zod.ts` - -#### 2. OpenTelemetry Integration ๐Ÿ“Š -**ๆ–‡ไปถ**: `packages/spec/src/system/telemetry-otel.zod.ts` - -#### 3. Responsive Layout & Dynamic Forms ๐Ÿ“ฑ -**ๅขžๅผบ**: -- `packages/spec/src/ui/view.zod.ts` (responsive breakpoints) -- `packages/spec/src/ui/view.zod.ts` (conditional rendering) - ---- - -### Sprint 4 (P3 - ไฝŽไผ˜ๅ…ˆ็บงๅฎŒๅ–„) - 1ๅ‘จ - -#### 1. Data Masking & Encryption ๐Ÿ” -**ๆ–‡ไปถ**: `packages/spec/src/permission/data-masking.zod.ts` - -#### 2. BPMN 2.0 Compatibility ๐Ÿ“ -**ๆ–‡ไปถ**: `packages/spec/src/automation/bpmn.zod.ts` - -#### 3. GraphQL Schema Generator ๐ŸŽฏ -**ๆ–‡ไปถ**: `packages/spec/src/api/graphql-schema.zod.ts` - ---- - -## ๐Ÿ“ ๅฎžๆ–ฝๆธ…ๅ• (Checklist) - -### P0 - ๅฟ…้กป็ซ‹ๅณๅฎž็Žฐ -- [ ] `permission/rls.zod.ts` - Row-Level Security -- [ ] `auth/scim.zod.ts` - SCIM 2.0 User & Group -- [ ] `auth/scim.test.ts` - SCIM Tests - -### P1 - ้ซ˜ไผ˜ๅ…ˆ็บง (1ไธชๆœˆๅ†…) -- [ ] `ui/widget-lifecycle.zod.ts` - Widget Lifecycle -- [ ] `ui/widget-events.zod.ts` - Widget Events -- [ ] `ui/widget-props.zod.ts` - Widget Props -- [ ] `automation/etl.zod.ts` - ETL Pipeline -- [ ] `automation/connector.zod.ts` - Connector Registry -- [ ] `automation/sync.zod.ts` - Data Sync -- [ ] `api/odata.zod.ts` - OData v4 - -### P2 - ไธญไผ˜ๅ…ˆ็บง (2ไธชๆœˆๅ†…) -- [ ] `data/migration.zod.ts` - Schema Migration -- [ ] `system/telemetry-otel.zod.ts` - OpenTelemetry -- [ ] ๅขžๅผบ `ui/view.zod.ts` - Responsive Layout -- [ ] ๅขžๅผบ `ui/view.zod.ts` - Conditional Rendering - -### P3 - ไฝŽไผ˜ๅ…ˆ็บง (3ไธชๆœˆๅ†…) -- [ ] `permission/data-masking.zod.ts` - Data Masking -- [ ] `automation/bpmn.zod.ts` - BPMN 2.0 -- [ ] `api/graphql-schema.zod.ts` - GraphQL Generator - ---- - -## ๐ŸŽ“ ่กŒไธšๆ ‡ๅ‡†ๅ‚่€ƒ - -### ๅฟ…่ฏปๆ–‡ๆกฃ -1. **SCIM 2.0 RFC**: - - RFC 7643: SCIM Core Schema - - RFC 7644: SCIM Protocol - -2. **OData v4**: - - OData URL Conventions - - OData JSON Format - -3. **PostgreSQL RLS**: - - CREATE POLICY Documentation - - Row Security Policies - -4. **OpenTelemetry**: - - OTLP Specification - - Semantic Conventions - -### ๅฏนๆ ‡ไบงๅ“ -- **Salesforce**: Security Model, Validation Rules, Formula Fields -- **ServiceNow**: Workflow Engine, ACL System -- **Kubernetes**: CRD Pattern, Admission Controllers -- **Prisma**: Schema Migration, Type Generation -- **Hasura**: GraphQL Auto-generation -- **Airbyte**: Connector Protocol, ETL Pipelines - ---- - -## โœ… ๆˆๅŠŸๆŒ‡ๆ ‡ - -1. **ๅ่ฎฎๅฎŒๆ•ดๅบฆ**: ไปŽ 83% โ†’ 98% -2. **ๆต‹่ฏ•่ฆ†็›–็އ**: ไปŽ 85% โ†’ 95% -3. **ๆ–‡ๆกฃๅฎŒๆ•ดๅบฆ**: 100% API Reference -4. **่กŒไธšๅ…ผๅฎนๆ€ง**: - - SCIM 2.0 โœ… - - OData v4 โœ… - - PostgreSQL RLS โœ… - - OpenTelemetry โœ… - ---- - -## ๐Ÿ“ž ๅŽ็ปญ่กŒๅŠจ - -ๅฆ‚้œ€่ฏฆ็ป†ๅฑ•ๅผ€ไปปไฝ•ไธ€ไธชๅ…ทไฝ“ๅ่ฎฎ็š„ๅฎž็Žฐ็ป†่Š‚๏ผŒ่ฏทๅ‘Š่ฏ‰ๆˆ‘๏ผš -1. ๆ‚จๅธŒๆœ›ๆˆ‘ๅ…ˆๅฎž็Žฐๅ“ชไธชๅ่ฎฎ๏ผŸ -2. ๆ˜ฏๅฆ้œ€่ฆๆˆ‘ๆไพ›ๆŸไธชๅ่ฎฎ็š„ๅฎŒๆ•ดไปฃ็ ็คบไพ‹๏ผŸ -3. ๆ˜ฏๅฆ้œ€่ฆๆˆ‘ไธบๆŸไธชๅ่ฎฎ็ผ–ๅ†™ๆต‹่ฏ•็”จไพ‹๏ผŸ - -ไพ‹ๅฆ‚๏ผš -> "่ฏทไธบ Row-Level Security (RLS) ๅ่ฎฎ็ผ–ๅ†™ๅฎŒๆ•ด็š„ Zod Schema ๅ’Œๆต‹่ฏ•็”จไพ‹" diff --git a/PROTOCOL_ORGANIZATION.md b/PROTOCOL_ORGANIZATION.md deleted file mode 100644 index f8ea43cfc..000000000 --- a/PROTOCOL_ORGANIZATION.md +++ /dev/null @@ -1,245 +0,0 @@ -# ObjectStack Protocol Organization - -This document provides a visual map of how the 70 protocol specifications are organized across the ObjectStack ecosystem. - -``` -objectstack-ai/spec -โ””โ”€โ”€ packages/spec/src/ - โ”‚ - โ”œโ”€โ”€ ๐Ÿ“Š DATA PROTOCOL (ObjectQL) - 8 files - โ”‚ โ”œโ”€โ”€ field.zod.ts โ†’ 44 field types (text, number, vector, location, etc.) - โ”‚ โ”œโ”€โ”€ object.zod.ts โ†’ Object/table definitions with fields and indexes - โ”‚ โ”œโ”€โ”€ query.zod.ts โ†’ Query AST (window functions, HAVING, DISTINCT, subqueries) - โ”‚ โ”œโ”€โ”€ validation.zod.ts โ†’ Validation rules for data integrity - โ”‚ โ”œโ”€โ”€ filter.zod.ts โ†’ Query filters and conditions - โ”‚ โ”œโ”€โ”€ dataset.zod.ts โ†’ Dataset definitions for analytics - โ”‚ โ”œโ”€โ”€ mapping.zod.ts โ†’ Field mapping for data transformation - โ”‚ โ””โ”€โ”€ hook.zod.ts โ†’ Lifecycle hooks (before/after CRUD) - โ”‚ - โ”œโ”€โ”€ ๐ŸŽจ UI PROTOCOL (ObjectUI) - 10 files - โ”‚ โ”œโ”€โ”€ view.zod.ts โ†’ List views (grid, kanban, calendar, gantt) - โ”‚ โ”œโ”€โ”€ page.zod.ts โ†’ FlexiPage layouts with regions - โ”‚ โ”œโ”€โ”€ app.zod.ts โ†’ Application navigation menus - โ”‚ โ”œโ”€โ”€ dashboard.zod.ts โ†’ Dashboard layouts with widgets - โ”‚ โ”œโ”€โ”€ report.zod.ts โ†’ Report definitions (tabular, summary, matrix, chart) - โ”‚ โ”œโ”€โ”€ action.zod.ts โ†’ UI actions (buttons, scripts, flows) - โ”‚ โ”œโ”€โ”€ component.zod.ts โ†’ Reusable UI components - โ”‚ โ”œโ”€โ”€ block.zod.ts โ†’ UI block definitions - โ”‚ โ”œโ”€โ”€ theme.zod.ts โ†’ Theming (colors, typography, animations) - โ”‚ โ””โ”€โ”€ widget.zod.ts โ†’ Custom field widgets - โ”‚ - โ”œโ”€โ”€ โš™๏ธ SYSTEM PROTOCOL (ObjectOS) - 14 files - โ”‚ โ”œโ”€โ”€ manifest.zod.ts โ†’ Package manifest (objectstack.config.ts) - โ”‚ โ”œโ”€โ”€ datasource.zod.ts โ†’ Data source connections - โ”‚ โ”œโ”€โ”€ driver.zod.ts โ†’ Database driver definitions - โ”‚ โ”œโ”€โ”€ driver/ - โ”‚ โ”‚ โ”œโ”€โ”€ postgres.zod.ts โ†’ PostgreSQL driver config - โ”‚ โ”‚ โ””โ”€โ”€ mongo.zod.ts โ†’ MongoDB driver config - โ”‚ โ”œโ”€โ”€ plugin.zod.ts โ†’ Plugin lifecycle and interface - โ”‚ โ”œโ”€โ”€ context.zod.ts โ†’ Kernel execution context - โ”‚ โ”œโ”€โ”€ events.zod.ts โ†’ Event bus and pub/sub - โ”‚ โ”œโ”€โ”€ job.zod.ts โ†’ Background job scheduling - โ”‚ โ”œโ”€โ”€ audit.zod.ts โ†’ Audit logging - โ”‚ โ”œโ”€โ”€ logger.zod.ts โ†’ Structured logging - โ”‚ โ”œโ”€โ”€ translation.zod.ts โ†’ i18n/l10n support - โ”‚ โ”œโ”€โ”€ feature.zod.ts โ†’ Feature flags - โ”‚ โ””โ”€โ”€ scoped-storage.zod.ts โ†’ Key-value storage - โ”‚ - โ”œโ”€โ”€ ๐Ÿค– AI PROTOCOL - 8 files - โ”‚ โ”œโ”€โ”€ agent.zod.ts โ†’ AI agent definitions - โ”‚ โ”œโ”€โ”€ model-registry.zod.ts โ†’ LLM model registry - โ”‚ โ”œโ”€โ”€ rag-pipeline.zod.ts โ†’ Retrieval-augmented generation - โ”‚ โ”œโ”€โ”€ nlq.zod.ts โ†’ Natural language query (NL โ†’ ObjectQL) - โ”‚ โ”œโ”€โ”€ conversation.zod.ts โ†’ Conversation management - โ”‚ โ”œโ”€โ”€ cost.zod.ts โ†’ AI cost tracking - โ”‚ โ”œโ”€โ”€ predictive.zod.ts โ†’ Predictive analytics/ML models - โ”‚ โ””โ”€โ”€ orchestration.zod.ts โ†’ AI workflow orchestration - โ”‚ - โ”œโ”€โ”€ ๐ŸŒ API PROTOCOL - 6 files - โ”‚ โ”œโ”€โ”€ contract.zod.ts โ†’ API contracts and specifications - โ”‚ โ”œโ”€โ”€ endpoint.zod.ts โ†’ REST endpoints with rate limiting - โ”‚ โ”œโ”€โ”€ router.zod.ts โ†’ API routing - โ”‚ โ”œโ”€โ”€ odata.zod.ts โ†’ OData query protocol - โ”‚ โ”œโ”€โ”€ realtime.zod.ts โ†’ WebSocket/SSE subscriptions - โ”‚ โ””โ”€โ”€ discovery.zod.ts โ†’ API discovery/introspection - โ”‚ - โ”œโ”€โ”€ ๐Ÿ”„ AUTOMATION PROTOCOL - 7 files - โ”‚ โ”œโ”€โ”€ flow.zod.ts โ†’ Visual workflow builder - โ”‚ โ”œโ”€โ”€ workflow.zod.ts โ†’ Declarative workflow rules - โ”‚ โ”œโ”€โ”€ approval.zod.ts โ†’ Multi-step approval processes - โ”‚ โ”œโ”€โ”€ webhook.zod.ts โ†’ Outbound webhooks - โ”‚ โ”œโ”€โ”€ etl.zod.ts โ†’ ETL data pipelines - โ”‚ โ”œโ”€โ”€ sync.zod.ts โ†’ Bi-directional data sync - โ”‚ โ””โ”€โ”€ connector.zod.ts โ†’ External system connectors - โ”‚ - โ”œโ”€โ”€ ๐Ÿ” AUTH PROTOCOL - 6 files - โ”‚ โ”œโ”€โ”€ identity.zod.ts โ†’ User identity and profiles - โ”‚ โ”œโ”€โ”€ role.zod.ts โ†’ Role definitions (RBAC) - โ”‚ โ”œโ”€โ”€ organization.zod.ts โ†’ Multi-org structure - โ”‚ โ”œโ”€โ”€ policy.zod.ts โ†’ Password and session policies - โ”‚ โ”œโ”€โ”€ config.zod.ts โ†’ OAuth/SAML/SSO configs - โ”‚ โ””โ”€โ”€ scim.zod.ts โ†’ SCIM 2.0 provisioning - โ”‚ - โ”œโ”€โ”€ ๐Ÿ”’ PERMISSION PROTOCOL - 4 files - โ”‚ โ”œโ”€โ”€ permission.zod.ts โ†’ Object-level CRUD permissions - โ”‚ โ”œโ”€โ”€ sharing.zod.ts โ†’ Sharing rules (criteria & manual) - โ”‚ โ”œโ”€โ”€ rls.zod.ts โ†’ Row-level security - โ”‚ โ””โ”€โ”€ territory.zod.ts โ†’ Territory management - โ”‚ - โ”œโ”€โ”€ ๐Ÿช HUB PROTOCOL - 5 files - โ”‚ โ”œโ”€โ”€ marketplace.zod.ts โ†’ Plugin marketplace listings - โ”‚ โ”œโ”€โ”€ composer.zod.ts โ†’ Package dependency management - โ”‚ โ”œโ”€โ”€ license.zod.ts โ†’ Feature licensing - โ”‚ โ”œโ”€โ”€ tenant.zod.ts โ†’ Multi-tenant isolation - โ”‚ โ””โ”€โ”€ space.zod.ts โ†’ Workspace/space management - โ”‚ - โ”œโ”€โ”€ ๐Ÿ”ง SHARED PROTOCOL - 1 file - โ”‚ โ””โ”€โ”€ identifiers.zod.ts โ†’ Standard identifier formats - โ”‚ - โ””โ”€โ”€ ๐Ÿ“ฆ STACK PROTOCOL - 1 file - โ””โ”€โ”€ stack.zod.ts โ†’ Root stack definition (combines all protocols) -``` - -## Protocol Layers - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ STACK PROTOCOL (1) โ”‚ -โ”‚ Unified Stack Configuration โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ APPLICATION LAYER โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ AUTOMATION โ”‚ โ”‚ HUB โ”‚ โ”‚ AI โ”‚ โ”‚ -โ”‚ โ”‚ (7 specs) โ”‚ โ”‚ (5 specs) โ”‚ โ”‚ (8 specs) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ PRESENTATION LAYER โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ UI PROTOCOL (10 specs) โ”‚ โ”‚ -โ”‚ โ”‚ Views, Pages, Apps, Dashboards, Reports, etc. โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ BUSINESS LAYER โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ DATA PROTOCOL (8 specs) โ”‚ โ”‚ -โ”‚ โ”‚ Objects, Fields, Queries, Validations, Hooks โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ INFRASTRUCTURE LAYER โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ SYSTEM โ”‚ โ”‚ API โ”‚ โ”‚ AUTH โ”‚ โ”‚PERMISSIONโ”‚ โ”‚ -โ”‚ โ”‚(14 specs)โ”‚ โ”‚(6 specs) โ”‚ โ”‚(6 specs) โ”‚ โ”‚(4 specs) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ SHARED PROTOCOL (1 spec) โ”‚ โ”‚ -โ”‚ โ”‚ Common Utilities & Identifiers โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -## Protocol Dependencies - -``` - Stack Protocol - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ -Data Protocol UI Protocol - โ”‚ โ”‚ - โ”œโ”€โ”€โ”€ Fields โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค - โ”œโ”€โ”€โ”€ Objects โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค - โ””โ”€โ”€โ”€ Queries โ”‚ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ผ -Automation Protocol - โ”‚ - โ”œโ”€โ”€โ”€ Flows โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”œโ”€โ”€โ”€ Workflows โ”‚ - โ””โ”€โ”€โ”€ Approvals โ”‚ - โ–ผ - System Protocol - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ โ–ผ -Auth Protocol API Protocol Permission Protocol - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ - Sharing RLS -``` - -## Module Relationships - -| Consumer Module | Depends On | Relationship | -| :--- | :--- | :--- | -| **Stack** | All modules | Aggregates entire system | -| **UI** | Data, System, Auth | Renders data with security context | -| **Automation** | Data, System, AI | Orchestrates business logic | -| **AI** | Data, System | Enhances data with intelligence | -| **API** | Data, Auth, Permission | Exposes data with security | -| **Permission** | Data, Auth | Controls data access | -| **Hub** | System, Auth | Multi-tenant packaging | -| **Auth** | System | Identity foundation | -| **Data** | Shared | Core business model | -| **System** | Shared | Platform foundation | - -## File Naming Conventions - -All protocol files follow this pattern: - -``` -/.zod.ts -``` - -Examples: -- `data/field.zod.ts` โ†’ Field protocol -- `ui/view.zod.ts` โ†’ View protocol -- `system/manifest.zod.ts` โ†’ Manifest protocol -- `ai/agent.zod.ts` โ†’ AI agent protocol - -## Schema Naming Conventions - -Within each `.zod.ts` file: - -```typescript -// Primary schema (PascalCase + "Schema" suffix) -export const FieldSchema = z.object({ ... }); - -// Derived TypeScript type (inferred from Zod) -export type Field = z.infer; - -// Supporting schemas -export const SelectOptionSchema = z.object({ ... }); -export const VectorConfigSchema = z.object({ ... }); -``` - -## Quick Navigation - -| Need | File | Location | -| :--- | :--- | :--- | -| Define an object/table | `object.zod.ts` | `packages/spec/src/data/` | -| Define a field | `field.zod.ts` | `packages/spec/src/data/` | -| Create a view | `view.zod.ts` | `packages/spec/src/ui/` | -| Configure a dashboard | `dashboard.zod.ts` | `packages/spec/src/ui/` | -| Build a workflow | `flow.zod.ts` | `packages/spec/src/automation/` | -| Set up permissions | `permission.zod.ts` | `packages/spec/src/permission/` | -| Add authentication | `identity.zod.ts` | `packages/spec/src/auth/` | -| Create an AI agent | `agent.zod.ts` | `packages/spec/src/ai/` | -| Configure a plugin | `manifest.zod.ts` | `packages/spec/src/system/` | -| Define an API endpoint | `endpoint.zod.ts` | `packages/spec/src/api/` | - -## See Also - -- **[PROTOCOL_REFERENCE.md](./PROTOCOL_REFERENCE.md)** - Complete protocol inventory with detailed descriptions -- **[ARCHITECTURE.md](./ARCHITECTURE.md)** - System architecture overview -- **[README.md](./README.md)** - Project overview and getting started -- **[CONTRIBUTING.md](./CONTRIBUTING.md)** - Contributing guidelines diff --git a/PROTOCOL_REFERENCE.md b/PROTOCOL_REFERENCE.md deleted file mode 100644 index 83dcc9451..000000000 --- a/PROTOCOL_REFERENCE.md +++ /dev/null @@ -1,387 +0,0 @@ -# ObjectStack Protocol Reference - -> **Complete inventory of all protocol specifications in the ObjectStack ecosystem.** - -Last Updated: 2026-01-27 - -**๐Ÿ“– See also:** -- [PROTOCOL_INDEX.md](./PROTOCOL_INDEX.md) for quick navigation links to all protocols -- [PROTOCOL_ORGANIZATION.md](./PROTOCOL_ORGANIZATION.md) for visual diagrams and protocol relationships - -## Overview - -This document provides a comprehensive reference to all 70 protocol specifications that define the ObjectStack platform. Each protocol is implemented as a Zod schema (`.zod.ts` file) providing runtime validation and TypeScript type safety. - -## Protocol Statistics - -| Module | Protocol Files | Description | -| :--- | :---: | :--- | -| **Data Protocol** | 8 | Core business logic and data modeling | -| **UI Protocol** | 10 | User interface definitions and interactions | -| **System Protocol** | 14 | Runtime environment and platform capabilities | -| **AI Protocol** | 8 | AI/ML integration and agent orchestration | -| **API Protocol** | 6 | Standardized API contracts and communication | -| **Automation Protocol** | 7 | Workflow automation and integration | -| **Auth Protocol** | 6 | Identity, authentication, and authorization | -| **Permission Protocol** | 4 | Access control and security policies | -| **Hub Protocol** | 5 | Marketplace and multi-tenancy | -| **Shared Protocol** | 1 | Common utilities and identifiers | -| **Stack Protocol** | 1 | Root stack definition | -| **Total** | **70** | **Complete protocol suite** | - -## Protocol Modules - -### 1. Data Protocol (ObjectQL) -**Location:** `packages/spec/src/data/` - -Defines the "Shape of Data" and business logic. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `field.zod.ts` | `FieldSchema` | Field definitions with 44 types (text, number, select, lookup, formula, vector, location, etc.) | -| `object.zod.ts` | `ObjectSchema` | Object/table definitions with fields, indexes, and capabilities | -| `query.zod.ts` | `QuerySchema` | Abstract query AST supporting window functions, HAVING, DISTINCT, subqueries | -| `validation.zod.ts` | `ValidationRuleSchema` | Validation rules for data integrity | -| `filter.zod.ts` | `FilterSchema` | Query filtering and conditions | -| `dataset.zod.ts` | `DatasetSchema` | Dataset definitions for reporting and analytics | -| `mapping.zod.ts` | `FieldMappingSchema` | Field mapping configurations for data transformation | -| `hook.zod.ts` | `HookSchema` | Lifecycle hooks (before/after insert, update, delete) | - -**Key Features:** -- 44 field types including AI/ML vectors and GPS locations -- Advanced query capabilities (window functions, HAVING, DISTINCT, subqueries) -- Validation rules and formulas -- Lifecycle hooks for business logic - -### 2. UI Protocol (ObjectUI) -**Location:** `packages/spec/src/ui/` - -Defines the "Shape of Interaction" for rendering interfaces. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `view.zod.ts` | `ViewSchema` | List views (grid, kanban, calendar, gantt) and form layouts | -| `page.zod.ts` | `PageSchema` | FlexiPage layouts with regions and components | -| `app.zod.ts` | `AppSchema` | Application structure and navigation menus | -| `dashboard.zod.ts` | `DashboardSchema` | Dashboard layouts with grid-based widgets | -| `report.zod.ts` | `ReportSchema` | Report definitions (tabular, summary, matrix, chart) | -| `action.zod.ts` | `ActionSchema` | UI actions (buttons, scripts, URLs, flows) | -| `component.zod.ts` | `ComponentSchema` | Reusable UI components | -| `block.zod.ts` | `BlockSchema` | UI block definitions | -| `theme.zod.ts` | `ThemeSchema` | Theming (colors, typography, breakpoints, animations) | -| `widget.zod.ts` | `WidgetSchema` | Custom field widgets with lifecycle hooks | - -**Key Features:** -- Server-driven UI with multiple view types -- Flexible page layouts with component regions -- Rich dashboard and reporting capabilities -- Comprehensive theming system - -### 3. System Protocol (ObjectOS) -**Location:** `packages/spec/src/system/` - -Defines the "Runtime Environment" and platform capabilities. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `manifest.zod.ts` | `ManifestSchema` | Application/plugin manifest (`objectstack.config.ts`) with 7 package types: app, plugin, driver, module, objectql, gateway, adapter | -| `datasource.zod.ts` | `DatasourceSchema` | Data source connection configurations | -| `driver.zod.ts` | `DriverSchema` | Database driver definitions and options | -| `driver/postgres.zod.ts` | `PostgresConfigSchema` | PostgreSQL-specific driver configuration | -| `driver/mongo.zod.ts` | `MongoConfigSchema` | MongoDB-specific driver configuration | -| `plugin.zod.ts` | `PluginSchema` | Plugin lifecycle and interface definitions | -| `context.zod.ts` | `KernelContextSchema` | Kernel execution context with user, org, tenant info | -| `events.zod.ts` | `EventSchema` | Event bus and pub/sub patterns | -| `job.zod.ts` | `JobSchema` | Background job scheduling (cron, interval, delayed) | -| `audit.zod.ts` | `AuditEventSchema` | Audit logging for compliance | -| `logger.zod.ts` | `LoggerConfigSchema` | Structured logging configuration | -| `translation.zod.ts` | `TranslationSchema` | i18n/l10n support | -| `feature.zod.ts` | `FeatureFlagSchema` | Feature flag definitions | -| `scoped-storage.zod.ts` | `ScopedStorageSchema` | Scoped key-value storage | - -**Key Features:** -- Microkernel architecture with 7 distinct package types for proper separation of concerns - - **adapter**: Runtime containers (Express, Hono, Fastify, Serverless) - - **gateway**: API protocols (GraphQL, REST, RPC, OData) - - **objectql**: Core data engine implementation - - **driver**: Database/external service adapters (Postgres, MongoDB, S3) - - **plugin**: General-purpose functionality extensions - - **app**: Business application packages - - **module**: Reusable code libraries -- Pluggable architecture with manifest-based configuration -- Multi-driver support (PostgreSQL, MongoDB, and extensible) -- Event-driven architecture with pub/sub -- Comprehensive audit and logging capabilities -- Feature flags and i18n support - -### 4. AI Protocol -**Location:** `packages/spec/src/ai/` - -Defines AI agent integration capabilities. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `agent.zod.ts` | `AgentSchema` | AI agent definitions and configurations | -| `model-registry.zod.ts` | `ModelRegistrySchema` | LLM model registry and selection | -| `rag-pipeline.zod.ts` | `RAGPipelineSchema` | Retrieval-augmented generation pipeline | -| `nlq.zod.ts` | `NLQSchema` | Natural language query processing | -| `conversation.zod.ts` | `ConversationSchema` | Conversation management and memory | -| `cost.zod.ts` | `CostTrackingSchema` | AI cost tracking and budgeting | -| `predictive.zod.ts` | `PredictiveModelSchema` | Predictive analytics and ML models | -| `orchestration.zod.ts` | `OrchestrationSchema` | AI workflow orchestration | - -**Key Features:** -- Multi-provider LLM support -- RAG pipeline for semantic search -- Natural language to ObjectQL translation -- Conversation history and context management -- Cost tracking and budget controls - -### 5. API Protocol -**Location:** `packages/spec/src/api/` - -Defines standardized API contracts. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `contract.zod.ts` | `ApiContractSchema` | API endpoint contracts and specifications | -| `endpoint.zod.ts` | `EndpointSchema` | REST endpoint definitions with rate limiting | -| `router.zod.ts` | `RouterSchema` | API routing configuration | -| `odata.zod.ts` | `ODataQuerySchema` | OData query protocol support | -| `realtime.zod.ts` | `RealtimeSchema` | WebSocket/SSE real-time subscriptions | -| `discovery.zod.ts` | `DiscoverySchema` | API discovery and introspection | - -**Key Features:** -- RESTful API contracts -- OData query support -- Real-time subscriptions (WebSocket/SSE) -- API rate limiting and throttling -- Auto-discovery and introspection - -### 6. Automation Protocol -**Location:** `packages/spec/src/automation/` - -Workflow automation and integration. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `flow.zod.ts` | `FlowSchema` | Visual workflow builder (Screen, Autolaunched, Schedule) | -| `workflow.zod.ts` | `WorkflowSchema` | Declarative workflow rules (field updates, alerts) | -| `approval.zod.ts` | `ApprovalProcessSchema` | Multi-step approval processes | -| `webhook.zod.ts` | `WebhookSchema` | Outbound webhook definitions | -| `etl.zod.ts` | `ETLPipelineSchema` | ETL data pipelines | -| `sync.zod.ts` | `SyncConfigSchema` | Bi-directional data synchronization | -| `connector.zod.ts` | `ConnectorSchema` | External system connectors | - -**Key Features:** -- Visual flow builder with drag-and-drop -- Declarative workflow automation -- Multi-step approval processes -- Webhook integrations -- ETL and data sync capabilities - -### 7. Auth Protocol -**Location:** `packages/spec/src/auth/` - -Identity, authentication, and authorization. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `identity.zod.ts` | `UserSchema` | User identity and profile | -| `role.zod.ts` | `RoleSchema` | Role definitions and permissions | -| `organization.zod.ts` | `OrganizationSchema` | Multi-org structure | -| `policy.zod.ts` | `PasswordPolicySchema` | Password and session policies | -| `config.zod.ts` | `AuthConfigSchema` | OAuth, SAML, SSO configurations | -| `scim.zod.ts` | `SCIMSchema` | SCIM 2.0 provisioning protocol | - -**Key Features:** -- Multi-provider authentication (OAuth, SAML, SSO) -- Role-based access control (RBAC) -- Multi-organization support -- SCIM 2.0 for user provisioning -- Configurable password policies - -### 8. Permission Protocol -**Location:** `packages/spec/src/permission/` - -Access control and security policies. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `permission.zod.ts` | `ObjectPermissionSchema` | Object-level CRUD permissions | -| `sharing.zod.ts` | `SharingRuleSchema` | Criteria-based and manual sharing rules | -| `rls.zod.ts` | `RowLevelSecuritySchema` | Row-level security policies | -| `territory.zod.ts` | `TerritorySchema` | Territory management for hierarchical access | - -**Key Features:** -- Multi-layered permission model -- Object, field, and record-level security -- Criteria-based sharing rules -- Territory-based access control - -### 9. Hub Protocol -**Location:** `packages/spec/src/hub/` - -Marketplace and multi-tenancy. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `marketplace.zod.ts` | `MarketplaceListingSchema` | Plugin marketplace listings | -| `composer.zod.ts` | `PackageComposerSchema` | Package dependency management | -| `license.zod.ts` | `LicenseSchema` | Feature licensing and entitlements | -| `tenant.zod.ts` | `TenantSchema` | Multi-tenant isolation and quotas | -| `space.zod.ts` | `SpaceSchema` | Workspace/space management | - -**Key Features:** -- Plugin marketplace with versioning -- Dependency resolution and composition -- Feature-based licensing -- Multi-tenancy with quota enforcement -- Workspace management - -### 10. Shared Protocol -**Location:** `packages/spec/src/shared/` - -Common utilities and identifiers. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `identifiers.zod.ts` | `SystemIdentifierSchema` | Standard identifier formats and validation | - -**Key Features:** -- Consistent identifier patterns across all protocols -- Validation for machine names (snake_case) -- Support for namespaced identifiers - -### 11. Stack Protocol -**Location:** `packages/spec/src/` - -Root stack definition. - -| File | Schema | Purpose | -| :--- | :--- | :--- | -| `stack.zod.ts` | `ObjectStackDefinitionSchema` | Complete stack configuration combining all protocols | - -**Key Features:** -- Unified stack configuration -- Aggregates all protocol modules -- Entry point for complete application definition - -## Naming Conventions - -All protocols follow strict naming conventions: - -| Context | Convention | Example | -| :--- | :--- | :--- | -| **Configuration Keys** | `camelCase` | `maxLength`, `referenceFilters`, `deleteBehavior` | -| **Machine Names** | `snake_case` | `name: 'project_task'`, `object: 'account'` | -| **Schema Names** | `PascalCase` with `Schema` suffix | `FieldSchema`, `ObjectSchema` | -| **Type Names** | `PascalCase` inferred from Zod | `type Field = z.infer` | - -## Protocol Design Principles - -1. **Zod First**: All protocols start with Zod schemas for runtime validation -2. **Type Safety**: TypeScript types are derived from Zod schemas (`z.infer<>`) -3. **JSON Schema**: All Zod schemas generate JSON schemas for IDE support -4. **No Business Logic**: Protocol specs contain only definitions, no implementation -5. **Backward Compatibility**: Breaking changes require major version bumps -6. **Extensibility**: All protocols support custom extensions and plugins - -## Usage Examples - -### Importing Protocols - -```typescript -// Import individual schemas -import { FieldSchema, ObjectSchema } from '@objectstack/spec/data'; -import { ViewSchema, AppSchema } from '@objectstack/spec/ui'; -import { ManifestSchema } from '@objectstack/spec/system'; - -// Import types -import type { Field, Object } from '@objectstack/spec/data'; -import type { View, App } from '@objectstack/spec/ui'; - -// Validate at runtime -const field = FieldSchema.parse({ - name: 'account_name', - type: 'text', - label: 'Account Name', - required: true, - maxLength: 255 -}); -``` - -### Building Applications - -```typescript -import { ObjectStackDefinitionSchema } from '@objectstack/spec'; - -const myApp = ObjectStackDefinitionSchema.parse({ - manifest: { - name: 'my-crm', - version: '1.0.0', - description: 'Custom CRM Application' - }, - objects: [ - { - name: 'account', - label: 'Account', - fields: [ - { name: 'name', type: 'text', label: 'Account Name', required: true }, - { name: 'industry', type: 'select', label: 'Industry' } - ] - } - ], - views: [ - { - name: 'account_list', - object: 'account', - type: 'grid', - columns: ['name', 'industry'] - } - ] -}); -``` - -## Documentation - -For detailed documentation on each protocol, see: - -- **[ObjectQL (Data Layer)](/content/docs/objectql/)** - Data modeling and queries -- **[ObjectUI (UI Layer)](/content/docs/objectui/)** - User interface definitions -- **[ObjectOS (System Layer)](/content/docs/objectos/)** - Runtime and platform -- **[API Reference](/content/docs/references/)** - Complete API documentation -- **[Examples](/examples/)** - Reference implementations - -## Contributing - -When adding or modifying protocols: - -1. โœ… Define Zod schema first -2. โœ… Add comprehensive JSDoc comments with `@description` -3. โœ… Follow naming conventions (camelCase for config, snake_case for names) -4. โœ… Write unit tests with 80%+ coverage -5. โœ… Generate JSON schema: `pnpm --filter @objectstack/spec build` -6. โœ… Update this reference document -7. โœ… Add examples to documentation - -See [CONTRIBUTING.md](/CONTRIBUTING.md) for complete guidelines. - -## Version History - -| Date | Version | Protocols | Notes | -| :--- | :--- | :---: | :--- | -| 2026-01-27 | 0.4.x | 70 | Complete protocol suite with AI, advanced query features | -| 2026-01-20 | 0.3.x | 68 | Added vector and location field types | -| 2025-12-15 | 0.2.x | 65 | Initial multi-module protocol structure | - -## License - -Apache 2.0 ยฉ ObjectStack - ---- - -**See Also:** -- [Architecture Overview](./ARCHITECTURE.md) -- [Development Roadmap](./internal/planning/DEVELOPMENT_ROADMAP.md) -- [Contributing Guide](./CONTRIBUTING.md) diff --git a/docs-structure-proposal.md b/docs-structure-proposal.md deleted file mode 100644 index f2979db99..000000000 --- a/docs-structure-proposal.md +++ /dev/null @@ -1,90 +0,0 @@ -# ObjectStack Protocol Docs Structure Proposal - -Based on the audit of existing content and the "Metamodel Standards," here is the recommended structure for the official documentation. - -## 1. High-Level Goals -- **Eliminate Redundancy**: Merge `concepts`, `core-concepts`, `specifications`, and `protocols` into a unified hierarchy. -- **Align with Architecture**: Structure explicitly around the three pillars: **ObjectQL (Data)**, **ObjectUI (UI)**, and **ObjectOS (System)**. -- **Reference-Driven**: Ensure documentation maps directly to the Zod schemas (`field.zod.ts`, `view.zod.ts`, etc.). - -## 2. Proposed Directory Structure - -```text -content/docs/ -โ”œโ”€โ”€ index.mdx (Landing Page) -โ”œโ”€โ”€ introduction/ (Was: concepts, core-concepts) -โ”‚ โ”œโ”€โ”€ index.mdx -โ”‚ โ”œโ”€โ”€ manifesto.mdx (From concepts/manifesto.mdx) -โ”‚ โ”œโ”€โ”€ architecture.mdx (From core-concepts/the-stack.mdx) -โ”‚ โ”œโ”€โ”€ metadata-driven.mdx (From core-concepts/metadata-driven.mdx) -โ”‚ โ””โ”€โ”€ terminology.mdx -โ”œโ”€โ”€ objectql/ (The Data Protocol) -โ”‚ โ”œโ”€โ”€ index.mdx (Overview) -โ”‚ โ”œโ”€โ”€ schema/ -โ”‚ โ”‚ โ”œโ”€โ”€ object.mdx (Maps to src/data/object.zod.ts) -โ”‚ โ”‚ โ”œโ”€โ”€ field.mdx (Maps to src/data/field.zod.ts) -โ”‚ โ”‚ โ”œโ”€โ”€ validation.mdx -โ”‚ โ”‚ โ””โ”€โ”€ relationships.mdx -โ”‚ โ”œโ”€โ”€ query/ -โ”‚ โ”‚ โ”œโ”€โ”€ index.mdx (Query syntax) -โ”‚ โ”‚ โ””โ”€โ”€ drivers.mdx -โ”‚ โ””โ”€โ”€ flow/ -โ”‚ โ””โ”€โ”€ logic.mdx (Maps to src/data/flow.zod.ts) -โ”œโ”€โ”€ objectui/ (The UI Protocol) -โ”‚ โ”œโ”€โ”€ index.mdx -โ”‚ โ”œโ”€โ”€ app.mdx (Maps to src/ui/app.zod.ts) -โ”‚ โ”œโ”€โ”€ views/ -โ”‚ โ”‚ โ”œโ”€โ”€ index.mdx -โ”‚ โ”‚ โ”œโ”€โ”€ list-view.mdx (Maps to src/ui/view.zod.ts) -โ”‚ โ”‚ โ””โ”€โ”€ form-view.mdx -โ”‚ โ”œโ”€โ”€ components/ (Widgets, Dashboard) -โ”‚ โ””โ”€โ”€ actions.mdx (Maps to src/ui/action.zod.ts) -โ”œโ”€โ”€ objectos/ (The System Protocol) -โ”‚ โ”œโ”€โ”€ index.mdx -โ”‚ โ”œโ”€โ”€ manifest.mdx (Maps to src/system/manifest.zod.ts) -โ”‚ โ”œโ”€โ”€ authentication.mdx -โ”‚ โ”œโ”€โ”€ api-reference.mdx (Maps to src/system/api.zod.ts) -โ”‚ โ””โ”€โ”€ plugins.mdx -โ””โ”€โ”€ developers/ (Guides & Tooling) - โ”œโ”€โ”€ quick-start.mdx - โ”œโ”€โ”€ cli.mdx - โ”œโ”€โ”€ testing.mdx - โ””โ”€โ”€ extensions.mdx -``` - -## 3. Detailed Actions - -### A. Cleanup & Consolidation -1. **Delete** `content/docs/specifications` folder (content is redundant with `protocols`). -2. **Delete** `content/docs/core-concepts` folder (move unique content to `introduction`). -3. **Archive** `content/docs/concepts` folder (it contains a flat list of protocols; move content to specific `object*` folders and then remove). - -### B. Rename & Move -1. Rename `content/docs/protocols` -> Explode this. - * Move `content/docs/protocols/objectql` -> `content/docs/objectql` - * Move `content/docs/protocols/objectui` -> `content/docs/objectui` - * Move `content/docs/protocols/objectos` -> `content/docs/objectos` - * *Reason*: These are the top-level products/protocols. They deserve root-level visibility in the docs URI (e.g., `docs/objectql/schema`). - -### C. Navigation Update (`meta.json`) -Update `content/docs/meta.json` to reflect the new simplified hierarchy: - -```json -{ - "title": "Documentation", - "pages": [ - "introduction", - "objectql", - "objectui", - "objectos", - "developers", - "references" - ] -} -``` - -## 4. Content Gaps to Fill -Based on `copilot-instructions.md`, ensure the following specific pages exist and map to their Zod definitions: -- [ ] **ObjectQL**: Ensure `field.mdx` documents all types (text, lookup, formula) defined in `field.zod.ts`. -- [ ] **ObjectUI**: Ensure `layout.mdx` covers the Grid/Kanban options defined in `view.zod.ts`. -- [ ] **ObjectOS**: Ensure `manifest.mdx` clearly documents `objectstack.config.ts`.