Getting Started
Getting Started
This guide will help you get started with the Matrix Framework.
Installation
Install the framework using npm:
npm install matrix-middleware-frameworkOr using yarn:
yarn add matrix-middleware-frameworkQuick Start
Here’s a simple example that sets up a middleware tree with authentication and logging:
import { MiddlewareTree, MessageRouter } from 'matrix-middleware-framework';
// Create middleware nodes
const tree = new MiddlewareTree();
const auth = new AuthMiddleware();
const logging = new LoggingMiddleware();
const handler = new MessageHandler();
// Build the middleware tree
tree.addNode('auth', auth);
tree.addNode('logging', logging, 'auth'); // Add logging as child of auth
tree.addNode('handler', handler, 'logging'); // Add handler as child of logging
// Create and start the router
const router = new MessageRouter(tree);
router.start();
// Send a message through the middleware tree
await router.route({
type: 'greeting',
payload: { message: 'Hello, World!' }
});Core Components
The framework consists of three main components:
- MiddlewareTree: Organizes middleware nodes in a hierarchical structure
- MessageRouter: Routes messages through the middleware tree
- Context: Carries message and metadata through the routing process
Next Steps
- Learn about the Core Architecture
- Explore Tree-based Routing
- See Examples of common patterns
- Read the API Reference for detailed documentation