# ahmii-kun/d-mail-whatsapp-bot architecture

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

- Interactive diagram: https://gitdiagram.com/ahmii-kun/d-mail-whatsapp-bot
- Repository: https://github.com/ahmii-kun/d-mail-whatsapp-bot

## Overview

D-Mail is a Baileys-based WhatsApp utility and group-management bot. A WhatsApp event enters through the connection layer, is emitted to the application, and messages are handled, checked, and dispatched to commands; group events trigger welcome/farewell and moderation behavior. The graph also preserves documented capabilities such as media utilities, group controls, bot modes, and anti-delete. Some wiring is dynamic and several modules were only partially excerpted, so uncertain relationships are omitted rather than inferred.

Main entry points: [`src/handler/message.js`](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/handler/message.js) (Message dispatch), [`src/frameWork/Command/base.js`](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/Command/base.js) (Command contract), [`src/config.js`](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/config.js) (Runtime configuration), [`src/frameWork/database.js`](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/database.js) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_app["Application wiring<br/>[app.js]"]
  node_connection["WhatsApp connection<br/>[connection.js]"]
  node_socket_helpers["Socket lifecycle<br/>[helper.js]"]
end

subgraph group_messaging["Message handling"]
  node_interface["Message interface<br/>[interface.js]"]
  node_sanitize["Message model<br/>[sanitize.js]"]
  node_message_handler["Message dispatch<br/>[message.js]"]
  node_event_handler["Group and message events<br/>[events.js]"]
end

subgraph group_features["Bot capabilities"]
  node_commands["Command registration<br/>[commands.js]"]
  node_command_base["Command contract<br/>[base.js]"]
  node_core_commands["Utility commands"]
  node_group_commands["Group controls"]
  node_media_commands["Media commands"]
  node_moderator_commands["Moderator commands"]
end

subgraph group_state["State and setup"]
  node_auth["Session authentication<br/>[auth.js]"]
  node_host["Web host and auth UI<br/>[host.js]"]
  node_config["Runtime configuration<br/>[config.js]"]
  node_database["Database access<br/>[database.js]"]
  node_utils["Shared utilities<br/>[utils.js]"]
end

node_whatsapp(("WhatsApp users"))
node_baileys["Baileys transport"]
node_mongo[("MongoDB")]
node_youtube["YouTube search service"]

node_whatsapp -->|"sends events"| node_baileys
node_baileys -->|"delivers events"| node_connection
node_app -->|"starts"| node_connection
node_app -->|"routes messages"| node_message_handler
node_app -->|"routes events"| node_event_handler
node_connection -->|"delegates lifecycle"| node_socket_helpers
node_socket_helpers -->|"loads auth"| node_auth
node_socket_helpers -->|"initializes"| node_config
node_config -->|"creates"| node_database
node_config -->|"creates"| node_interface
node_config -->|"creates"| node_commands
node_config -->|"imports"| node_host
node_auth -->|"stores session"| node_database
node_database -->|"connects and stores"| node_mongo
node_message_handler -.->|"reads user and group state"| node_database
node_message_handler -.->|"selects commands"| node_commands
node_message_handler -->|"runs command"| node_command_base
node_command_base -->|"implemented by"| node_core_commands
node_command_base -->|"implemented by"| node_group_commands
node_command_base -->|"implemented by"| node_media_commands
node_command_base -->|"implemented by"| node_moderator_commands
node_media_commands -->|"searches videos"| node_youtube
node_media_commands -->|"formats and fetches"| node_utils
node_event_handler -->|"reads group settings"| node_database
node_event_handler -->|"sends group messages"| node_baileys
node_message_handler -.->|"replies and moderates"| node_baileys
node_host -.->|"supports web authentication"| node_whatsapp

click node_app "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/app.js"
click node_connection "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/connection.js"
click node_socket_helpers "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/helper.js"
click node_auth "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/auth.js"
click node_host "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/host.js"
click node_config "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/config.js"
click node_database "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/database.js"
click node_interface "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/interface.js"
click node_sanitize "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/sanitize.js"
click node_message_handler "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/handler/message.js"
click node_event_handler "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/handler/events.js"
click node_commands "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/commands.js"
click node_command_base "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/Command/base.js"
click node_core_commands "https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/core"
click node_group_commands "https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/group"
click node_media_commands "https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/media"
click node_moderator_commands "https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/mod"
click node_utils "https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/lib/utils.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_connection,node_socket_helpers,node_whatsapp toneBlue
class node_interface,node_sanitize,node_message_handler,node_event_handler,node_mongo toneAmber
class node_commands,node_command_base,node_core_commands,node_group_commands,node_media_commands,node_moderator_commands toneMint
class node_auth,node_host,node_config,node_database,node_utils toneRose
class node_baileys,node_youtube toneIndigo
```

## Components

### Bot runtime

- [Application wiring](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/app.js): `app.js`
- [WhatsApp connection](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/connection.js): `src/hub/connection.js`
- [Socket lifecycle](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/helper.js): `src/hub/helper.js`

### Message handling

- [Message interface](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/interface.js): `src/frameWork/interface.js`
- [Message model](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/sanitize.js): `src/frameWork/sanitize.js`
- [Message dispatch](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/handler/message.js): `src/handler/message.js`
- [Group and message events](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/handler/events.js): `src/handler/events.js`

### Bot capabilities

- [Command registration](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/commands.js): `src/frameWork/commands.js`
- [Command contract](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/Command/base.js): `src/frameWork/Command/base.js`
- [Utility commands](https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/core): `src/Commands/core`
- [Group controls](https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/group): `src/Commands/group`
- [Media commands](https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/media): `src/Commands/media`
- [Moderator commands](https://github.com/ahmii-kun/d-mail-whatsapp-bot/tree/main/src/Commands/mod): `src/Commands/mod`

### State and setup

- [Session authentication](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/auth.js): `src/hub/auth.js`
- [Web host and auth UI](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/hub/host.js): `src/hub/host.js`
- [Runtime configuration](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/config.js): `src/config.js`
- [Database access](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/frameWork/database.js): `src/frameWork/database.js`
- [Shared utilities](https://github.com/ahmii-kun/d-mail-whatsapp-bot/blob/main/src/lib/utils.js): `src/lib/utils.js`

### Other components

- **WhatsApp users**
- **Baileys transport**
- **MongoDB**
- **YouTube search service**

## Connections

- WhatsApp users → Baileys transport: sends events
- Baileys transport → WhatsApp connection: delivers events
- Application wiring → WhatsApp connection: starts (evidence: `app.js`)
- Application wiring → Message dispatch: routes messages (evidence: `app.js`)
- Application wiring → Group and message events: routes events (evidence: `app.js`)
- WhatsApp connection → Socket lifecycle: delegates lifecycle (evidence: `src/hub/connection.js`)
- Socket lifecycle → Session authentication: loads auth (evidence: `src/hub/helper.js`)
- Socket lifecycle → Runtime configuration: initializes (evidence: `src/hub/helper.js`)
- Runtime configuration → Database access: creates (evidence: `src/config.js`)
- Runtime configuration → Message interface: creates (evidence: `src/config.js`)
- Runtime configuration → Command registration: creates (evidence: `src/config.js`)
- Runtime configuration → Web host and auth UI: imports (evidence: `src/config.js`)
- Session authentication → Database access: stores session (evidence: `src/hub/auth.js`)
- Database access → MongoDB: connects and stores (evidence: `src/frameWork/database.js`)
- Message dispatch → Database access: reads user and group state
- Message dispatch → Command registration: selects commands
- Message dispatch → Command contract: runs command (evidence: `src/handler/message.js`)
- Command contract → Utility commands: implemented by (evidence: `src/Commands/core/retrieve.js`)
- Command contract → Group controls: implemented by (evidence: `src/Commands/group/enable.js`)
- Command contract → Media commands: implemented by (evidence: `src/Commands/media/ytsearch.js`)
- Command contract → Moderator commands: implemented by (evidence: `src/Commands/mod/mode.js`)
- Media commands → YouTube search service: searches videos (evidence: `src/Commands/media/ytsearch.js`)
- Media commands → Shared utilities: formats and fetches (evidence: `src/Commands/media/ytsearch.js`)
- Group and message events → Database access: reads group settings (evidence: `src/handler/events.js`)
- Group and message events → Baileys transport: sends group messages (evidence: `src/handler/events.js`)
- Message dispatch → Baileys transport: replies and moderates
- Web host and auth UI → WhatsApp users: supports web authentication
