Leaves-Guardian

Modular Baileys v7 wrapper enforcing deterministic reconnects, L1/L2 memory safety, rate queues, and 12 interactive message builders.

Discipline
WhatsApp Bot Runtime & ESM Infrastructure
Release
v0.4.0
Year
2026
Stack
Node.js ESMBaileys v7SQLitenode --test@napi-rs/canvas
INTERACTIVE SYSTEM TOPOLOGY · v0.4.0Node.js ESMBaileys v7SQLitenode --test
Architectural topology diagram illustrating Leaves-Guardian connection, traffic queue, memory store, and sanitizer subsystems
main/recovery/SessionRecovery.jsSession Auto-Purge & 8-Char Pairing

Entry point main/recovery/SessionRecovery.js -> Session Auto-Purge & 8-Char Pairing verified active in pipeline topology.

SessionRecovery → MessageStore → TrafficController → absorbed-features.test

Context

Long-running WhatsApp bots built directly on raw sockets suffer from three recurring failures: blind reconnect loops after 401/403 unlinks, unbounded in-memory message stores causing OOM crashes, and bursty outbound sends triggering platform rate limits.

Architecture Decision

Leaves-Guardian separates socket open from operational readiness (OPEN vs READY) and isolates reliability concerns into explicit subsystems: deterministic exponential backoff with jitter, tiered RAM-to-disk caching, and prioritized egress queuing.

Subsystem Craft

01

Session Auto-Purge & 8-Char Pairing

Detects 401/403 disconnects across Boom payloads, purges stale credentials safely on Windows/Linux lock states, and supports custom 8-character pairing codes.

main/recovery/SessionRecovery.js
02

Tiered L1/L2 Store & MemoryGuard

Combines an LRU RAM hot cache (default 100 entries) with async cold storage and SQLite auth state so E2EE retries succeed without heap bloat.

main/store/MessageStore.js + main/sqlite/useSQLiteAuthState.js
03

TrafficController & Privacy Terminal

Dispatches HIGH/NORMAL/LOW priority queues with hysteresis backpressure while masking sensitive phone digits in console logs.

main/traffic/TrafficController.js + main/terminal/PresentationSanitizer.js
04

FakeSocket Automated Verification

Verifies reconnect backoff, payload unwrapping, and PII scrubbing via built-in node --test suites without requiring a live phone connection.

tests/absorbed-features.test.js

Outcome

Published as open-source ESM package (v0.4.0) on GitHub with 12+ fluent builders (List, Carousel, Canvas HTML5 mini-app, Poll, StickerPack) and an accompanying bilingual documentation portal.

Interactive Architecture Lab

Test the state machines behind Leaves-Guardian.

Leaves-Guardian separates socket open from operational readiness, backs off with jitter on drops, and bounds RAM with tiered L1/L2 storage. Trigger each real scenario below.

READY · OPEN == READY
Mascot operator status indicator
Mascot OperatorOPERATOR: NOMINAL
Jitter: 0 ms · L1: 42 / 100
Connection
STATE: READY
TrafficQueue
PACED: 0 Q
MessageStore
L1 42 / L2 180
Sanitizer
PII: MASKED

Socket handshake verified. Privacy scrubber active on 62812******89.

[00:00.12]ConnectionManager -> transition OPEN -> READY (8-char pairing verified)
[00:00.38]PresentationSanitizer -> masked 62812******89 before stdout sink
[00:00.64]MessageStore -> hybrid LRU active (42 hot RAM / 180 cold disk)