MANDALA मण्डल
Mesh Architecture for Network Distribution & Layered Aggregation
Sacred geometry of interconnected nodes.
v2.5.0The 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:
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:
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
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`);