MANDALA मण्डल

Mesh Architecture for Network Distribution & Layered Aggregation

Sacred geometry of interconnected nodes.

v2.5.0

The Sacred Geometry of Connection

In Buddhist and Hindu traditions, a mandala represents the cosmos— a sacred geometric pattern symbolizing the universe's structure. Concentric circles radiate from a central point, with each layer representing different realms of existence.

The MANDALA protocol embodies this sacred geometry: nodes form a self-organizing mesh with hub nodes at the center, peer connections radiating outward, and message flows traversing the cosmic web of interconnection.

Overview

MANDALA (Mesh Architecture for Network Distribution & Layered Aggregation) provides peer-to-peer mesh networking for the Yakmesh network. It handles node discovery, connection management, message routing, and topology maintenance— creating the underlying fabric that connects all network participants.

Protocol Family

Protocol Himalayan Name Purpose
Gossip MANTRA Epidemic message propagation
Broadcast STUPA Priority-based broadcasting
Consensus LAMA Distributed agreement
Time MANI Temporal synchronization
Trust KARMA Reputation management
Mesh MANDALA Network topology

Message Types

MANDALA defines a set of message types that flow through the sacred geometry, each serving a specific purpose in maintaining the cosmic web:

HELLO

Initial greeting when nodes first connect. Introduces the node to its peer.

{ type: 'HELLO', nodeId, capabilities, version }

WELCOME

Response to HELLO, confirming the connection and sharing peer information.

{ type: 'WELCOME', nodeId, peerList, networkState }

GOSSIP

Epidemic message propagation via MANTRA protocol. Spreads information to peers.

{ type: 'GOSSIP', mantraId, payload, ttl }

SYNC

State synchronization request. Reconciles data between nodes.

{ type: 'SYNC', vectorClock, dataRange }

PING/PONG

Heartbeat messages to maintain connection liveness and measure latency.

{ type: 'PING', timestamp, nonce }

BYE

Graceful disconnection notification. Allows clean peer list updates.

{ type: 'BYE', reason, reconnectHint }

Core Components

MandalaNetwork

The main mesh networking engine—the cosmic web of interconnection:

import { MandalaNetwork, MandalaMessageTypes } from 'yakmesh/mesh/network';

// Initialize the mandala mesh
const mandala = new MandalaNetwork({
  nodeId: 'my-node-id',
  maxPeers: 50,                    // Maximum concurrent connections
  heartbeatInterval: 30000,        // PING every 30 seconds
  peerExchangeEnabled: true,       // Share peer lists
  autoReconnect: true,             // Reconnect on disconnect
});

// Listen for events
mandala.on('peer:connected', (peerId) => {
  console.log(`🌐 New connection in the mandala: ${peerId}`);
});

mandala.on('message', (type, payload, from) => {
  console.log(`📨 Message received: ${type} from ${from}`);
});

// Connect to a peer
await mandala.connect('ws://peer.example.com:8080');

// Broadcast to all peers
mandala.broadcast(MandalaMessageTypes.GOSSIP, {
  mantraId: 'msg-123',
  payload: { content: 'Hello Mandala!' }
});

Connection Lifecycle

Each connection follows a sacred journey through the mandala:

1 CONNECT WebSocket established
2 HELLO Introduce ourselves
3 WELCOME Acknowledge & share peers
4 ACTIVE Full message exchange
5 BYE Graceful disconnect

Network Topology

The MANDALA forms a self-organizing mesh topology, with nodes naturally clustering into a sacred geometry pattern:

                    ┌───────┐
                    │ Edge  │
                    │ Node  │
                    └───┬───┘
                        │
          ┌─────────────┼─────────────┐
          │             │             │
      ┌───┴───┐    ┌────┴────┐    ┌───┴───┐
      │ Outer │    │   Hub   │    │ Outer │
      │ Ring  │────│  Node   │────│ Ring  │
      └───┬───┘    └────┬────┘    └───┬───┘
          │             │             │
          └─────────────┼─────────────┘
                        │
                    ┌───┴───┐
                    │ Peer  │
                    └───────┘

        Legend:
        ─── Primary connection (low latency)
        ··· Secondary connection (backup)
        

Connection States

CONNECTING WebSocket handshake in progress
HANDSHAKING HELLO/WELCOME exchange
ACTIVE Full duplex communication
DRAINING Graceful shutdown in progress
CLOSED Connection terminated

Configuration

const mandala = new MandalaNetwork({
  // Node identity
  nodeId: string,                // Unique node identifier
  
  // Connection limits
  maxPeers: 50,                  // Maximum concurrent peers
  minPeers: 3,                   // Minimum peers to maintain
  
  // Heartbeat settings
  heartbeatInterval: 30000,      // PING interval (ms)
  heartbeatTimeout: 10000,       // PONG timeout (ms)
  
  // Peer discovery
  peerExchangeEnabled: true,     // Share peer lists
  peerExchangeInterval: 60000,   // Exchange frequency (ms)
  
  // Reconnection
  autoReconnect: true,           // Auto-reconnect on disconnect
  reconnectDelay: 5000,          // Initial delay (ms)
  reconnectMaxDelay: 60000,      // Maximum backoff (ms)
  
  // Message handling
  messageQueueSize: 1000,        // Max queued messages
  deduplicationWindow: 60000,    // Dedup window (ms)
});

Integration with Other Protocols

MANDALA serves as the foundation layer, integrating with all other Himalayan protocols:

Protocol Integration
MANTRA GOSSIP messages propagate through MANDALA connections
STUPA Broadcasts use MANDALA for peer selection and delivery
LAMA Consensus votes travel via MANDALA message routing
MANI Time synchronization beacons flow through MANDALA
KARMA Trust scores influence MANDALA peer prioritization
SHERPA Discovery adds new peers to the MANDALA topology

Metrics

// Get network statistics
const stats = mandala.getStats();

console.log(`Connected peers: ${stats.connectedPeers}`);
console.log(`Messages sent: ${stats.messagesSent}`);
console.log(`Messages received: ${stats.messagesReceived}`);
console.log(`Average latency: ${stats.averageLatency}ms`);
console.log(`Uptime: ${stats.uptime}s`);

Related Protocols