@@ -6,9 +6,12 @@ ObjectStack Core Runtime & Query Engine
66
77The runtime package provides the ` ObjectKernel ` (MiniKernel) - a highly modular, plugin-based microkernel that orchestrates ObjectStack applications. It manages the application lifecycle through a standardized plugin system with dependency injection and event hooks.
88
9+ The package also defines ** capability contract interfaces** (` IHttpServer ` , ` IDataEngine ` ) that enable plugins to interact with common services without depending on concrete implementations, following the ** Dependency Inversion Principle** .
10+
911### Architecture Highlights
1012
1113- ** MiniKernel Design** : Business logic is completely separated into plugins
14+ - ** Capability Contracts** : Abstract interfaces for HTTP server and data persistence
1215- ** Dependency Injection** : Service registry for inter-plugin communication
1316- ** Event/Hook System** : Publish-subscribe mechanism for loose coupling
1417- ** Lifecycle Management** : Standardized init/start/destroy phases
@@ -119,6 +122,91 @@ new AppManifestPlugin(appConfig)
119122
120123## API Reference
121124
125+ ### Capability Contract Interfaces
126+
127+ #### IHttpServer
128+
129+ Abstract interface for HTTP server capabilities. Allows plugins to work with any HTTP framework (Express, Fastify, Hono, etc.) without tight coupling.
130+
131+ ``` typescript
132+ import { IHttpServer , IHttpRequest , IHttpResponse } from ' @objectstack/runtime' ;
133+
134+ // In your HTTP server plugin
135+ class MyHttpServerPlugin implements Plugin {
136+ name = ' http-server' ;
137+
138+ async init(ctx : PluginContext ) {
139+ const server: IHttpServer = createMyServer (); // Express, Hono, etc.
140+ ctx .registerService (' http-server' , server );
141+ }
142+ }
143+
144+ // In your API plugin
145+ class MyApiPlugin implements Plugin {
146+ name = ' api' ;
147+ dependencies = [' http-server' ];
148+
149+ async start(ctx : PluginContext ) {
150+ const server = ctx .getService <IHttpServer >(' http-server' );
151+
152+ // Register routes - works with any HTTP framework
153+ server .get (' /api/users' , async (req , res ) => {
154+ res .json ({ users: [] });
155+ });
156+ }
157+ }
158+ ```
159+
160+ ** Interface Methods:**
161+ - ` get(path, handler) ` - Register GET route
162+ - ` post(path, handler) ` - Register POST route
163+ - ` put(path, handler) ` - Register PUT route
164+ - ` delete(path, handler) ` - Register DELETE route
165+ - ` patch(path, handler) ` - Register PATCH route
166+ - ` use(path, handler?) ` - Register middleware
167+ - ` listen(port) ` - Start server
168+ - ` close() ` - Stop server (optional)
169+
170+ #### IDataEngine
171+
172+ Abstract interface for data persistence. Allows plugins to work with any data layer (ObjectQL, Prisma, TypeORM, etc.) without tight coupling.
173+
174+ ``` typescript
175+ import { IDataEngine } from ' @objectstack/runtime' ;
176+
177+ // In your data plugin
178+ class MyDataPlugin implements Plugin {
179+ name = ' data' ;
180+
181+ async init(ctx : PluginContext ) {
182+ const engine: IDataEngine = createMyDataEngine (); // ObjectQL, Prisma, etc.
183+ ctx .registerService (' data-engine' , engine );
184+ }
185+ }
186+
187+ // In your business logic plugin
188+ class MyBusinessPlugin implements Plugin {
189+ name = ' business' ;
190+ dependencies = [' data' ];
191+
192+ async start(ctx : PluginContext ) {
193+ const engine = ctx .getService <IDataEngine >(' data-engine' );
194+
195+ // CRUD operations - works with any data layer
196+ const user = await engine .insert (' user' , { name: ' John' });
197+ const users = await engine .find (' user' , { filter: { active: true } });
198+ await engine .update (' user' , user .id , { name: ' Jane' });
199+ await engine .delete (' user' , user .id );
200+ }
201+ }
202+ ```
203+
204+ ** Interface Methods:**
205+ - ` insert(objectName, data) ` - Create a record
206+ - ` find(objectName, query?) ` - Query records
207+ - ` update(objectName, id, data) ` - Update a record
208+ - ` delete(objectName, id) ` - Delete a record
209+
122210### ObjectKernel
123211
124212#### Methods
@@ -161,17 +249,18 @@ interface PluginContext {
161249See the ` examples/ ` directory for complete examples:
162250- ` examples/host/ ` - Full server setup with Hono
163251- ` examples/msw-react-crud/ ` - Browser-based setup with MSW
164- - ` examples/custom-objectql-example .ts` - Custom ObjectQL instance
165- - ` test-mini-kernel .ts ` - Comprehensive test suite
252+ - ` test-mini-kernel .ts` - Comprehensive kernel test suite
253+ - ` packages/runtime/src/ test-interfaces .ts` - Capability contract interface examples
166254
167255## Benefits of MiniKernel
168256
1692571 . ** True Modularity** : Each plugin is independent and reusable
170- 2 . ** Testability** : Mock services easily in tests
171- 3 . ** Flexibility** : Load plugins conditionally
172- 4 . ** Extensibility** : Add new plugins without modifying kernel
173- 5 . ** Clear Dependencies** : Explicit dependency declarations
174- 6 . ** Better Architecture** : Separation of concerns
258+ 2 . ** Capability Contracts** : Plugins depend on interfaces, not implementations
259+ 3 . ** Testability** : Mock services easily in tests
260+ 4 . ** Flexibility** : Load plugins conditionally, swap implementations
261+ 5 . ** Extensibility** : Add new plugins without modifying kernel
262+ 6 . ** Clear Dependencies** : Explicit dependency declarations
263+ 7 . ** Better Architecture** : Separation of concerns with Dependency Inversion
175264
176265## Best Practices
177266
0 commit comments