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-framework

Or using yarn:

yarn add matrix-middleware-framework

Quick 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:

  1. MiddlewareTree: Organizes middleware nodes in a hierarchical structure
  2. MessageRouter: Routes messages through the middleware tree
  3. Context: Carries message and metadata through the routing process

Next Steps