A modular application framework with dynamic module loading and inter-module communication built on the tuple-store state management library.
- Dynamic module loading and lifecycle management
- Module dependency resolution
- Inter-module communication through shared services
- Isolated state management for each module
- Observable state changes through tuple-store
- File system or in-memory module repositories
bun add github:Foundation42/module-system
import { createModuleSystem } from 'module-system';
// Create a module system
const moduleSystem = createModuleSystem({
type: "file-system", // Load modules from the file system
modulesDir: "./modules", // Directory containing modules
enableJournaling: true // Enable state change journaling
});
// Initialize the module system
await moduleSystem.repository.refresh();
// List available modules
const modules = moduleSystem.repository.listModules();
console.log(`Found ${modules.length} modules`);
// Load modules (handles dependencies automatically)
await moduleSystem.manager.loadModules(['core-module', 'ui-module']);
Each module should export a createModule
function that returns a Module
instance:
import { Module, ModuleContext, ModuleManifest, ModuleState } from 'module-system';
export function createModule(manifest: ModuleManifest): Module {
return {
// Store the module state
state: ModuleState.REGISTERED,
// Initialize the module
async initialize(context: ModuleContext): Promise<boolean> {
// Access module-specific store
await context.store.set('initialized', true);
// Register a service
context.services.registerService({
id: 'myService',
implementation: {
doSomething: () => 'result'
},
version: '1.0.0'
});
return true;
},
// Stop the module
async stop(): Promise<boolean> {
// Cleanup
return true;
},
// Get module state
getState(): ModuleState {
return this.state;
},
// Get module manifest
getManifest(): ModuleManifest {
return manifest;
},
// Expose public API
getAPI(): Record<string, any> {
return {
getSomething: () => 'something'
};
}
};
}
Each module should have a manifest.json
file:
{
"id": "my-module",
"name": "My Module",
"description": "A sample module",
"version": "1.0.0",
"entryPoint": "index.js",
"capabilities": ["feature1", "feature2"],
"slots": ["main-panel"],
"dependencies": {
"core-module": "^1.0.0"
}
}
MIT