This document summarizes the Week 3 refactoring effort to transform @objectql/core into a lightweight plugin for @objectstack/runtime.
- Reduce core package size by ~67%
- Separate runtime features from query-specific logic
- Establish clear architectural boundaries
Created core runtime infrastructure that can be shared across the ObjectStack ecosystem:
New Modules Added:
src/metadata.ts(~150 LOC) - MetadataRegistry for managing object configs, actions, hookssrc/hooks.ts(~115 LOC) - HookManager for lifecycle event managementsrc/actions.ts(~115 LOC) - ActionManager for custom action execution- Enhanced
ObjectStackKernelto include these managers
Impact: +380 LOC in @objectstack/runtime (shared infrastructure)
Created dedicated query processing modules in @objectql/core:
New Query Module (packages/foundation/core/src/query/):
filter-translator.ts(~143 LOC) - Converts ObjectQL filters to ObjectStack FilterNodequery-builder.ts(~80 LOC) - Builds QueryAST from UnifiedQueryindex.ts(~20 LOC) - Module exports
Removed from repository.ts:
- Filter translation logic (~140 LOC)
- Query building logic (~40 LOC)
Impact: Clarified separation of concerns, made query logic reusable
Updated @objectql/core to delegate to kernel managers:
Modified Files:
app.ts- Now delegates metadata, hooks, and actions tokernel.metadata,kernel.hooks,kernel.actions- Removed duplicate helper files:
action.ts(~49 LOC) - Logic moved to @objectstack/runtimehook.ts(~51 LOC) - Logic moved to @objectstack/runtimeobject.ts(~35 LOC) - Logic inlined in app.ts
Impact: -135 LOC from core helpers
@objectql/core: ~3,891 LOC across 13 files
- Included: metadata registry, hooks, actions, validation, formulas, query logic, AI
@objectql/core: ~3,606 LOC across 10 files
- Core files: app.ts, repository.ts, plugin.ts
- Query module: filter-translator.ts, query-builder.ts
- Extensions: validator.ts, formula-engine.ts, ai-agent.ts, util.ts
- Plugin wrappers: validator-plugin.ts, formula-plugin.ts
@objectstack/runtime: ~380 LOC (new package)
- Shared infrastructure: metadata, hooks, actions, kernel
Net Reduction in @objectql/core: ~285 LOC (~7.3%)
@objectstack/runtime (Shared Infrastructure)
├── MetadataRegistry - Object/action/hook registration
├── HookManager - Lifecycle event management
├── ActionManager - Custom action execution
└── ObjectStackKernel - Plugin orchestration
@objectql/core (Query Engine + Extensions)
├── Query Module
│ ├── FilterTranslator - ObjectQL → FilterNode conversion
│ └── QueryBuilder - UnifiedQuery → QueryAST conversion
├── Repository - CRUD with query capabilities
├── Validator - Data validation engine
├── FormulaEngine - Computed fields
└── AI Agent - Metadata generation
Before:
class ObjectQL {
private metadata: MetadataRegistry;
private hooks: Record<string, HookEntry[]>;
private actions: Record<string, ActionEntry>;
// ... managed independently
}After:
class ObjectQL {
private kernel: ObjectStackKernel;
get metadata() { return this.kernel.metadata; }
on(...) { this.kernel.hooks.register(...); }
registerAction(...) { this.kernel.actions.register(...); }
}HookName,HookContext,ActionContexthave incompatibilities between @objectql/types and @objectstack/runtime- @objectql/types has richer interfaces (HookAPI, ActionContext with input/api fields)
- @objectstack/runtime has simpler interfaces
- Decision needed: Adopt richer interfaces in runtime or create adapter layer
- Move validation & formula engines to runtime
- Move AI agent and utilities to runtime
- Update all tests
- Comprehensive build verification
-
Cleaner Architecture ✅
- Runtime concerns separated from query concerns
- Clear plugin architecture with ObjectStackKernel
-
Code Reusability ✅
- MetadataRegistry, HookManager, ActionManager can be used by other ObjectStack packages
-
Better Testability ✅
- Query logic isolated in dedicated module
- Runtime managers testable independently
-
Foundation for Growth ✅
- Easy to add new query optimizers/analyzers to query module
- Easy to extend runtime with new managers
| Metric | Before | After | Change |
|---|---|---|---|
| @objectql/core LOC | 3,891 | 3,606 | -285 (-7.3%) |
| Core helper files | 3 files (135 LOC) | 0 files | -135 LOC |
| Query module | Inline | 3 files (243 LOC) | +243 LOC |
| @objectstack/runtime | N/A | 380 LOC | +380 LOC |
| Total ecosystem | 3,891 | 4,229 | +338 LOC |
Note: While total LOC increased, the code is now better organized and shared infrastructure is reusable across packages.
Week 3 refactoring successfully established the foundation for a cleaner architecture:
- ✅ Created @objectstack/runtime with shared infrastructure
- ✅ Extracted query-specific logic into dedicated module
- ✅ Reduced coupling in core package
- ⏸️ Full migration pending type alignment resolution
The refactoring demonstrates the architectural vision even though the full 67% reduction target requires completing phases 4-7.