Architecture
Understanding WAKit's internal design and Socket vs Client layers.
Socket vs Client
WAKit is built on a two-layer architecture to provide both low-level control and high-level developer experience.
1. The Socket Layer (makeWASocket)
This is the lowest level of the library. It directly parses the WhatsApp protobufs, handles the Signal protocol encryption, and manages the WebSocket connection. If you need absolute control over raw nodes, binary encoding, or you are building an ultra-optimized custom implementation, you interact directly with the Socket.
2. The Client Layer (WAKitClient)
This is the developer-friendly abstraction layer that sits on top of the Socket. It wraps the complex event logic of the socket into a clean, predictable API.
What WAKitClient handles automatically:
- Connection retries and backoff.
- QR code generation in the terminal.
- Auth credential persistence via
JsonFileStore. - Normalizing complex
messages.upsertevents into simplemessageevents. - Providing the
PipelineandPluginRegistrysystems.
Event Flow
- WhatsApp sends a binary Node over the WebSocket.
- The Socket layer decrypts it and emits a raw event (e.g.,
messages.upsert). WAKitClientintercepts this event and normalizes it.- The normalized message is pushed into the Pipeline.
- Middleware functions process the message in order.
- If the message survives the pipeline,
WAKitClientemits the finalmessageevent for your bot logic.