# jpereira/zapbot architecture

> Architecture diagram of the GitHub repository jpereira/zapbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jpereira/zapbot
- Repository: https://github.com/jpereira/zapbot

## Overview

ZapBot is a WhatsApp Web bot that receives chat messages, records them, checks access and command syntax, and dispatches commands whose results are sent back through its WhatsApp client. The README also documents recovery of deleted or edited content, scheduling, watches, media/sticker tools, market and DeFi monitoring, AI, and operational controls. Those documented capabilities are retained as command subsystems; their internal links are limited where implementation was not sampled. The graph uses README claims and indexed imports as evidence, not assumptions about unsampled call paths.

Main entry points: [`src/comandos`](https://github.com/jpereira/zapbot/tree/main/src/comandos) (Command handlers), [`app.js`](https://github.com/jpereira/zapbot/blob/main/app.js) (Application bootstrap), [`src/eventos/mensagens.js`](https://github.com/jpereira/zapbot/blob/main/src/eventos/mensagens.js) (Message events), [`src/cliente.js`](https://github.com/jpereira/zapbot/blob/main/src/cliente.js) (WhatsApp client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["WhatsApp runtime"]
  node_app["Application bootstrap<br/>[app.js]"]
  node_client["WhatsApp client<br/>[cliente.js]"]
  node_messages["Message events<br/>[mensagens.js]"]
  node_deleted["Deleted-message events<br/>[apagadas.js]"]
  node_edited["Edited-message events<br/>[editadas.js]"]
  node_reactions["Reaction events<br/>[reacoes.js]"]
end

subgraph group_commands["Command handling"]
  node_registry["Command registry<br/>[index.js]"]
  node_command_core["Command parsing and help<br/>[base.js]"]
  node_command_handlers["Command handlers"]
end

subgraph group_features["Bot capabilities"]
  node_scheduling["Scheduled messages<br/>[agenda.js]"]
  node_watch["Message watches"]
  node_recovery["Message recovery<br/>[apagadas.js]"]
  node_market["Price alerts<br/>[alertasPreco.js]"]
  node_defi["DeFi tracking<br/>[defi.js]"]
  node_media["Media and stickers"]
  node_ai["ChatGPT features"]
end

subgraph group_state["State and services"]
  node_persistence[("SQLite database<br/>[db.js]")]
  node_settings["Runtime settings<br/>[settings.js]"]
  node_destinations["Recipient resolution<br/>[destinos.js]"]
  node_email["SMTP notifications<br/>[email.js]"]
end

node_operator(("Chat users"))
node_whatsapp(("WhatsApp Web"))

node_operator -->|"sends commands"| node_whatsapp
node_whatsapp -->|"connects session"| node_client
node_client -->|"delivers messages"| node_messages
node_app -->|"initializes"| node_client
node_app -->|"registers"| node_messages
node_app -->|"registers"| node_deleted
node_app -->|"registers"| node_edited
node_app -->|"registers"| node_reactions
node_messages -->|"stores messages"| node_persistence
node_messages -->|"dispatches commands"| node_registry
node_messages -->|"parses arguments"| node_command_core
node_registry -->|"maps handlers"| node_command_handlers
node_command_handlers -->|"reads configuration"| node_settings
node_deleted -->|"reads stored messages"| node_persistence
node_operator -->|"requests recovery"| node_recovery
node_operator -->|"requests recovery"| node_edited
node_operator -->|"schedules messages"| node_scheduling
node_operator -->|"sets message watches"| node_watch
node_operator -->|"sets price alerts"| node_market
node_operator -->|"checks positions"| node_defi
node_operator -->|"requests media tools"| node_media
node_operator -->|"requests AI"| node_ai
node_command_handlers -->|"provides cron command"| node_scheduling
node_command_handlers -->|"provides watch command"| node_watch
node_command_handlers -->|"provides price commands"| node_market
node_command_handlers -->|"provides DeFi command"| node_defi
node_command_handlers -->|"provides media commands"| node_media
node_command_handlers -->|"provides AI commands"| node_ai
node_destinations -->|"resolves WhatsApp targets"| node_client
node_operator -->|"receives QR and alerts"| node_email
node_app -->|"initializes database"| node_persistence

click node_app "https://github.com/jpereira/zapbot/blob/main/app.js"
click node_client "https://github.com/jpereira/zapbot/blob/main/src/cliente.js"
click node_messages "https://github.com/jpereira/zapbot/blob/main/src/eventos/mensagens.js"
click node_deleted "https://github.com/jpereira/zapbot/blob/main/src/eventos/apagadas.js"
click node_edited "https://github.com/jpereira/zapbot/blob/main/src/eventos/editadas.js"
click node_reactions "https://github.com/jpereira/zapbot/blob/main/src/eventos/reacoes.js"
click node_registry "https://github.com/jpereira/zapbot/blob/main/src/comandos/index.js"
click node_command_core "https://github.com/jpereira/zapbot/blob/main/src/comandos/base.js"
click node_command_handlers "https://github.com/jpereira/zapbot/tree/main/src/comandos"
click node_persistence "https://github.com/jpereira/zapbot/blob/main/src/db.js"
click node_settings "https://github.com/jpereira/zapbot/blob/main/src/settings.js"
click node_destinations "https://github.com/jpereira/zapbot/blob/main/src/destinos.js"
click node_scheduling "https://github.com/jpereira/zapbot/blob/main/src/agenda.js"
click node_watch "https://github.com/jpereira/zapbot/tree/main/src/watch"
click node_recovery "https://github.com/jpereira/zapbot/blob/main/src/eventos/apagadas.js"
click node_market "https://github.com/jpereira/zapbot/blob/main/src/alertasPreco.js"
click node_defi "https://github.com/jpereira/zapbot/blob/main/src/comandos/defi.js"
click node_media "https://github.com/jpereira/zapbot/tree/main/src/comandos"
click node_ai "https://github.com/jpereira/zapbot/tree/main/src/comandos"
click node_email "https://github.com/jpereira/zapbot/blob/main/src/email.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_client,node_messages,node_deleted,node_edited,node_reactions,node_operator toneBlue
class node_registry,node_command_core,node_command_handlers toneAmber
class node_scheduling,node_watch,node_recovery,node_market,node_defi,node_media,node_ai toneMint
class node_persistence,node_settings,node_destinations,node_email toneRose
class node_whatsapp toneIndigo
```

## Components

### WhatsApp runtime

- [Application bootstrap](https://github.com/jpereira/zapbot/blob/main/app.js): `app.js`
- [WhatsApp client](https://github.com/jpereira/zapbot/blob/main/src/cliente.js): `src/cliente.js`
- [Message events](https://github.com/jpereira/zapbot/blob/main/src/eventos/mensagens.js): `src/eventos/mensagens.js`
- [Deleted-message events](https://github.com/jpereira/zapbot/blob/main/src/eventos/apagadas.js): `src/eventos/apagadas.js`
- [Edited-message events](https://github.com/jpereira/zapbot/blob/main/src/eventos/editadas.js): `src/eventos/editadas.js`
- [Reaction events](https://github.com/jpereira/zapbot/blob/main/src/eventos/reacoes.js): `src/eventos/reacoes.js`

### Command handling

- [Command registry](https://github.com/jpereira/zapbot/blob/main/src/comandos/index.js): `src/comandos/index.js`
- [Command parsing and help](https://github.com/jpereira/zapbot/blob/main/src/comandos/base.js): `src/comandos/base.js`
- [Command handlers](https://github.com/jpereira/zapbot/tree/main/src/comandos): `src/comandos`

### Bot capabilities

- [Scheduled messages](https://github.com/jpereira/zapbot/blob/main/src/agenda.js): `src/agenda.js`
- [Message watches](https://github.com/jpereira/zapbot/tree/main/src/watch): `src/watch`
- [Message recovery](https://github.com/jpereira/zapbot/blob/main/src/eventos/apagadas.js): `src/eventos/apagadas.js`
- [Price alerts](https://github.com/jpereira/zapbot/blob/main/src/alertasPreco.js): `src/alertasPreco.js`
- [DeFi tracking](https://github.com/jpereira/zapbot/blob/main/src/comandos/defi.js): `src/comandos/defi.js`
- [Media and stickers](https://github.com/jpereira/zapbot/tree/main/src/comandos): `src/comandos`
- [ChatGPT features](https://github.com/jpereira/zapbot/tree/main/src/comandos): `src/comandos`

### State and services

- [SQLite database](https://github.com/jpereira/zapbot/blob/main/src/db.js): `src/db.js`
- [Runtime settings](https://github.com/jpereira/zapbot/blob/main/src/settings.js): `src/settings.js`
- [Recipient resolution](https://github.com/jpereira/zapbot/blob/main/src/destinos.js): `src/destinos.js`
- [SMTP notifications](https://github.com/jpereira/zapbot/blob/main/src/email.js): `src/email.js`

### Other components

- **Chat users**
- **WhatsApp Web**

## Connections

- Chat users → WhatsApp Web: sends commands
- WhatsApp Web → WhatsApp client: connects session
- WhatsApp client → Message events: delivers messages (evidence: `app.js`)
- Application bootstrap → WhatsApp client: initializes (evidence: `app.js`)
- Application bootstrap → Message events: registers (evidence: `app.js`)
- Application bootstrap → Deleted-message events: registers (evidence: `app.js`)
- Application bootstrap → Edited-message events: registers (evidence: `app.js`)
- Application bootstrap → Reaction events: registers (evidence: `app.js`)
- Message events → SQLite database: stores messages (evidence: `src/eventos/mensagens.js`)
- Message events → Command registry: dispatches commands (evidence: `src/eventos/mensagens.js`)
- Message events → Command parsing and help: parses arguments (evidence: `src/eventos/mensagens.js`)
- Command registry → Command handlers: maps handlers (evidence: `src/comandos/index.js`)
- Command handlers → Runtime settings: reads configuration (evidence: `src/comandos/base.js`)
- Deleted-message events → SQLite database: reads stored messages (evidence: `src/eventos/apagadas.js`)
- Chat users → Message recovery: requests recovery
- Chat users → Edited-message events: requests recovery
- Chat users → Scheduled messages: schedules messages
- Chat users → Message watches: sets message watches
- Chat users → Price alerts: sets price alerts
- Chat users → DeFi tracking: checks positions
- Chat users → Media and stickers: requests media tools
- Chat users → ChatGPT features: requests AI
- Command handlers → Scheduled messages: provides cron command
- Command handlers → Message watches: provides watch command (evidence: `src/watch/verificar.js`)
- Command handlers → Price alerts: provides price commands (evidence: `src/alertasPreco.js`)
- Command handlers → DeFi tracking: provides DeFi command (evidence: `src/comandos/index.js`)
- Command handlers → Media and stickers: provides media commands (evidence: `src/comandos/index.js`)
- Command handlers → ChatGPT features: provides AI commands (evidence: `src/comandos/index.js`)
- Recipient resolution → WhatsApp client: resolves WhatsApp targets (evidence: `src/destinos.js`)
- Chat users → SMTP notifications: receives QR and alerts
- Application bootstrap → SQLite database: initializes database (evidence: `app.js`)
