reflex-sync
v1.0.3
Published
Reactive state synchronization for Node.js.
Maintainers
Readme
Table of contents
Installation
Package managers
npm install reflex-syncyarn add reflex-syncpnpm add reflex-syncBasic usage
Application node (Client)
A client node binds to a master node and participates in state synchronization using a recursive proxy model.
import { Reflex } from 'reflex-sync';
const reflex = new Reflex({
mode: 'client',
host: '127.0.0.1',
port: 8080,
key: 'handshake-key'
});
await reflex.boot();
// Updates locally and broadcasts efficiently
reflex.state.settings = { theme: 'dark' };Authoritative node (Master)
The master node handles request rate limiting, initial state hydration, and broadcasting delta changes using Last Write Wins (LWW).
import { Reflex } from 'reflex-sync';
const reflex = new Reflex({
mode: 'master',
port: 8080,
key: 'handshake-key'
}, { system: { uptime: 0 } });
await reflex.boot();Configuration
The core Reflex constructor accepts a strict typing schema:
type ReflexOptions = {
mode: 'master' | 'client';
host?: string;
port: number;
key: string;
secure?: boolean;
tls?: {
cert?: string;
key?: string;
};
limits?: {
maxPayloadSize?: number;
opsPerSecond?: number;
};
}Security
Reflex leverages native Node structures for production deployments:
- Transport: Supports raw TCP or TLS 1.3 encryption (via
secure: true). - Handshake validation: Rejects unknown clients using SHA-256 HMAC pre-shared key validation immediately at the socket layer.
- DDoS mitigation: Per-IP sliding-window rate limiting.
