Leaves-Guardian
Modular Baileys v7 wrapper enforcing deterministic reconnects, L1/L2 memory safety, rate queues, and 12 interactive message builders.
Entry point main/recovery/SessionRecovery.js -> Session Auto-Purge & 8-Char Pairing verified active in pipeline topology.
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
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.
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.
TrafficController & Privacy Terminal
Dispatches HIGH/NORMAL/LOW priority queues with hysteresis backpressure while masking sensitive phone digits in console logs.
FakeSocket Automated Verification
Verifies reconnect backoff, payload unwrapping, and PII scrubbing via built-in node --test suites without requiring a live phone connection.
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.