@hkgdevx/xplug
v0.1.1
Published
XPlug – A lifecycle-driven plugin engine for Express & Node.js, enabling modular, extensible, and plugin-based architectures.
Downloads
24
Readme
XPlug
The deterministic, zero-dependency lifecycle-driven framework for mapping sprawling Express backend ecosystems safely natively via Plugins.
XPlug solves the problem of "Framework Rot" where massive Express applications slowly drift into tightly coupled balls of mud. Rather than explicitly writing global routing configurations, Database initialization logic, and Auth layers into one sequential index.ts file — XPlug forces your developers to bundle logic into self-containing Plugins.
XPlug natively verifies their dependency structures (e.g., throwing a Hard Crash if Auth tries to load before Database), merges configuration schemas dynamically, and triggers isolated lifecycles synchronously across all extensions securely.
Core Features
- Topological Sorting: Explicitly declare string arrays inside
dependenciesandoptionalDependenciesand XPlug builds a flawless structural Directed Acyclic Graph (DAG) beforeonBootruns to ensure features load strictly deterministically. - Duck-Typed Configuration Assertions: Merge default parameters securely via Native Runtime checks (using Zod or Joi schemas locally) to enforce that host applications pass strictly configured properties down to plugins.
- Custom App Lifecycles: Emit domain events seamlessly like
.emit('onOrderCreated', orderPayload)and allow downstream third-party plugins to execute arbitrary Hooks precisely responding to application traffic. - Express Route/Middleware Adapters: Hook directly into Express
mountRoutesmapping API endpoints uniformly with fallback defaultrouteBasePaths resolving overlaps dynamically.
Documentation Index
The /docs directory is explicitly crafted outlining the API parameters exhaustively to learn the core modules:
- Architecture Overview (Start here!)
- Plugin Manager
- Lifecycle Registry
- Filesystem Discovery & Diagnostics
- CLI Scaffolding
- Express Integrations
Example Host Application
import express from 'express';
import { createPluginSystem } from 'xplug';
import { authPlugin } from './plugins/auth';
import { databasePlugin } from './plugins/db';
const app = express();
/** Bind XPlug Engine strictly allocating Allowed lifecycles */
const system = createPluginSystem({
app,
lifecycles: ['onDatabaseBoot', 'onAuthBoot', 'beforeListen']
});
system.register(authPlugin);
system.register(databasePlugin);
async function start() {
// 1. Dependency resolver confirms Auth loads after DB.
await system.init();
// 2. Safely triggers respective Lifecycle phases
await system.runLifecycle('onDatabaseBoot');
await system.runLifecycle('onAuthBoot');
// 3. Mounts the combined isolated Router endpoints dynamically!
await system.mountRoutes();
app.listen(3000, () => {
console.log("Modular Host Framework booted seamlessly!");
});
}
start();Roadmap
- Phase 1 [Complete]: Core Execution Engine
- Phase 2 [Complete]: Express Framework Integration
- Phase 3 [Complete]: Strict Typings / Errors
- Phase 4 [Complete]: Filesystem Discovery
- Phase 5 [Complete]: Schema Configurations
- Phase 6 [Complete]: Dashboards, Sandboxes, & Toggles
- Production Roadmap:
fastifyframework adapter layers, Browser-based dynamic GUI debugging plugins, and remote CDN plugin registry polling.
