meta-bridge-graph
v1.0.5
Published
A comprehensive Meta Bridge Graph solution for seamless data connectivity across Frontend and Backend.
Maintainers
Readme
🕸️ Meta Bridge Graph
Meta Bridge Graph (MBG) is a high-performance, developer-first graph management library. It is designed to bridge the gap between complex metadata structures and practical implementation across Frontend and Backend environments.
📖 Table of Contents
- Core Concepts
- Advanced Features
- Installation
- API Reference
- Advanced Usage Patterns
- Multi-Language Support
🧠 Core Concepts
MBG is built on a "Hybrid Architecture" consisting of three layers:
- Core: Pure logic for graph manipulation, cycle detection, and events. Environment agnostic.
- Backend: Specialized for Node.js. Includes File System (FS) persistence and DB sync tools.
- Frontend: Optimized for Browsers. Includes Canvas rendering and reactive search.
🌟 Advanced Features
1. Type-Safe Generics
Define your own metadata structures for nodes and edges to get 100% IntelliSense support.
2. Async Middleware System
Transform or validate data before it hits the graph state. Perfect for automated timestamping or schema validation.
3. Pub/Sub Event System
React to any changes in your graph. Integrate with UI frameworks or logging systems effortlessly.
4. Cycle Detection (DAG Check)
Prevent infinite loops by detecting circular dependencies using an optimized DFS algorithm.
🚀 Installation
npm install meta-bridge-graph🛠 API Reference
Core Engine
The heart of MBG. Works everywhere.
import { MetaBridgeGraph } from 'meta-bridge-graph';
interface MyNode { name: string }
interface MyEdge { weight: number }
const mbg = new MetaBridgeGraph<MyNode, MyEdge>();
// Middleware
mbg.useNodeMiddleware(async (node) => {
return { ...node, tags: ['verified'] };
});
// Event Listener
mbg.on(event => {
if (event.type === 'NODE_ADDED') console.log('New Node:', event.payload.id);
});
await mbg.addNode({ id: '1', metadata: { name: 'Root' } });Backend Module (Node.js)
import { MBGBackend } from 'meta-bridge-graph/backend';
const serverMbg = new MBGBackend();
await serverMbg.loadFromFile('./data.json');
const stats = serverMbg.getStats();
console.log(`Nodes: ${stats.nodeCount}`);Frontend Module (Browser)
import { MBGFrontend } from 'meta-bridge-graph/frontend';
const clientMbg = new MBGFrontend();
clientMbg.initCanvas('my-viewport');
clientMbg.render({ animate: true });💡 Advanced Usage Patterns
Detecting Cycles
mbg.addEdge({ from: '1', to: '2', relation: 'child' });
mbg.addEdge({ from: '2', to: '1', relation: 'loop' });
if (mbg.hasCycle()) {
throw new Error("Recursive loops are not allowed in this graph!");
}Deep Cloning for "What-if" Analysis
const experimentalGraph = mbg.clone();
experimentalGraph.removeNode('critical-node');
// Original graph remains untouched!🌍 Multi-Language Support
👤 Author
ZertCihuy
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
