# nelson4111/wabot architecture

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

- Interactive diagram: https://gitdiagram.com/nelson4111/wabot
- Repository: https://github.com/nelson4111/wabot

## Overview

Avelia MD is a multi-device WhatsApp bot whose main workflow is receiving a chat message, dispatching it through auto-loaded ESM plugins, and replying with a command result. Its documented capabilities include AI, media downloading, sticker creation, and customizable menus; the tree also contains a separate Discord music bot. AI internals and Discord startup are represented where sampled source supports their wiring. The WhatsApp entry excerpt is partial, so detailed plugin dispatch and feature-specific dependencies are not inferred.

Main entry points: [`lib/ai/core/AIService.js`](https://github.com/nelson4111/wabot/blob/main/lib/ai/core/AIService.js) (AI coordinator), [`plugins`](https://github.com/nelson4111/wabot/tree/main/plugins) (Plugin handlers), [`main.js`](https://github.com/nelson4111/wabot/blob/main/main.js) (Bot runtime), [`bot-discord/index.js`](https://github.com/nelson4111/wabot/blob/main/bot-discord/index.js) (Discord bot)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_wa["WhatsApp runtime"]
  node_waentry["Bot runtime<br/>[main.js]"]
  node_wa_plugins["Plugin handlers"]
  node_wa_store[("JSON database<br/>[database.js]")]
end

subgraph group_features["Bot capabilities"]
  node_ai_plugin["AI commands"]
  node_downloaders["Media downloaders"]
  node_stickers["Sticker tools<br/>[sticker.js]"]
  node_menus["Menus"]
end

subgraph group_ai["AI subsystem"]
  node_ai_service["AI coordinator<br/>[AIService.js]"]
  node_context["Context builder<br/>[ContextBuilder.js]"]
  node_prompt["Prompt builder<br/>[PromptBuilder.js]"]
  node_intent["Intent detector<br/>[IntentDetector.js]"]
  node_knowledge["Knowledge retrieval"]
  node_memory[("Conversation memory")]
  node_executor["Command executor<br/>[CommandExecutor.js]"]
  node_models["Model selection<br/>[ModelManager.js]"]
end

subgraph group_discord["Discord music"]
  node_discord_app["Discord bot<br/>[index.js]"]
  node_music_commands["Music commands"]
  node_player_manager["Audio player manager"]
  node_discord_db[("Discord database<br/>[Database.js]")]
end

node_user(("WhatsApp user"))
node_llm{{"AI providers"}}
node_discord_user(("Discord user"))
node_audio_nodes{{"Lavalink nodes"}}

node_user -->|"sends messages"| node_waentry
node_waentry -->|"loads plugins"| node_wa_plugins
node_waentry -->|"initializes data"| node_wa_store
node_wa_plugins -->|"dispatches commands"| node_ai_plugin
node_ai_plugin -->|"handles AI"| node_ai_service
node_wa_plugins -->|"dispatches commands"| node_downloaders
node_wa_plugins -->|"dispatches commands"| node_stickers
node_wa_plugins -->|"dispatches commands"| node_menus
node_ai_service -->|"checks intent"| node_intent
node_ai_service -->|"builds context"| node_context
node_ai_service -->|"builds prompt"| node_prompt
node_ai_service -->|"retrieves knowledge"| node_knowledge
node_ai_service -->|"uses memory"| node_memory
node_ai_service -->|"requests generation"| node_models
node_models -->|"queries providers"| node_llm
node_ai_service -->|"runs commands"| node_executor
node_discord_user -->|"issues commands"| node_discord_app
node_discord_app -->|"connects client"| node_music_commands
node_music_commands -->|"uses playback"| node_player_manager
node_player_manager -->|"dispatches audio"| node_audio_nodes
node_discord_app -->|"initializes database"| node_discord_db

click node_waentry "https://github.com/nelson4111/wabot/blob/main/main.js"
click node_wa_plugins "https://github.com/nelson4111/wabot/tree/main/plugins"
click node_wa_store "https://github.com/nelson4111/wabot/blob/main/lib/database.js"
click node_ai_plugin "https://github.com/nelson4111/wabot/tree/main/plugins/ai"
click node_downloaders "https://github.com/nelson4111/wabot/tree/main/plugins/downloader"
click node_stickers "https://github.com/nelson4111/wabot/blob/main/lib/sticker.js"
click node_menus "https://github.com/nelson4111/wabot/tree/main/plugins/menu"
click node_ai_service "https://github.com/nelson4111/wabot/blob/main/lib/ai/core/AIService.js"
click node_context "https://github.com/nelson4111/wabot/blob/main/lib/ai/core/ContextBuilder.js"
click node_prompt "https://github.com/nelson4111/wabot/blob/main/lib/ai/core/PromptBuilder.js"
click node_intent "https://github.com/nelson4111/wabot/blob/main/lib/ai/core/IntentDetector.js"
click node_knowledge "https://github.com/nelson4111/wabot/blob/main/lib/ai/knowledge/KnowledgeRetriever.js"
click node_memory "https://github.com/nelson4111/wabot/tree/main/lib/ai/memory"
click node_executor "https://github.com/nelson4111/wabot/blob/main/lib/ai/core/CommandExecutor.js"
click node_models "https://github.com/nelson4111/wabot/blob/main/lib/ai/providers/ModelManager.js"
click node_discord_app "https://github.com/nelson4111/wabot/blob/main/bot-discord/index.js"
click node_music_commands "https://github.com/nelson4111/wabot/tree/main/bot-discord/src/commands/Music"
click node_player_manager "https://github.com/nelson4111/wabot/blob/main/bot-discord/src/loaders/loadPlayerManager.js"
click node_discord_db "https://github.com/nelson4111/wabot/blob/main/bot-discord/src/structures/Database.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_waentry,node_wa_plugins,node_wa_store,node_user,node_discord_user toneBlue
class node_ai_plugin,node_downloaders,node_stickers,node_menus toneAmber
class node_ai_service,node_context,node_prompt,node_intent,node_knowledge,node_memory,node_executor,node_models toneMint
class node_discord_app,node_music_commands,node_player_manager,node_discord_db toneRose
class node_llm,node_audio_nodes toneIndigo
```

## Components

### WhatsApp runtime

- [Bot runtime](https://github.com/nelson4111/wabot/blob/main/main.js): `main.js`
- [Plugin handlers](https://github.com/nelson4111/wabot/tree/main/plugins): `plugins`
- [JSON database](https://github.com/nelson4111/wabot/blob/main/lib/database.js): `lib/database.js`

### Bot capabilities

- [AI commands](https://github.com/nelson4111/wabot/tree/main/plugins/ai): `plugins/ai`
- [Media downloaders](https://github.com/nelson4111/wabot/tree/main/plugins/downloader): `plugins/downloader`
- [Sticker tools](https://github.com/nelson4111/wabot/blob/main/lib/sticker.js): `lib/sticker.js`
- [Menus](https://github.com/nelson4111/wabot/tree/main/plugins/menu): `plugins/menu`

### AI subsystem

- [AI coordinator](https://github.com/nelson4111/wabot/blob/main/lib/ai/core/AIService.js): `lib/ai/core/AIService.js`
- [Context builder](https://github.com/nelson4111/wabot/blob/main/lib/ai/core/ContextBuilder.js): `lib/ai/core/ContextBuilder.js`
- [Prompt builder](https://github.com/nelson4111/wabot/blob/main/lib/ai/core/PromptBuilder.js): `lib/ai/core/PromptBuilder.js`
- [Intent detector](https://github.com/nelson4111/wabot/blob/main/lib/ai/core/IntentDetector.js): `lib/ai/core/IntentDetector.js`
- [Knowledge retrieval](https://github.com/nelson4111/wabot/blob/main/lib/ai/knowledge/KnowledgeRetriever.js): `lib/ai/knowledge/KnowledgeRetriever.js`
- [Conversation memory](https://github.com/nelson4111/wabot/tree/main/lib/ai/memory): `lib/ai/memory`
- [Command executor](https://github.com/nelson4111/wabot/blob/main/lib/ai/core/CommandExecutor.js): `lib/ai/core/CommandExecutor.js`
- [Model selection](https://github.com/nelson4111/wabot/blob/main/lib/ai/providers/ModelManager.js): `lib/ai/providers/ModelManager.js`

### Discord music

- [Discord bot](https://github.com/nelson4111/wabot/blob/main/bot-discord/index.js): `bot-discord/index.js`
- [Music commands](https://github.com/nelson4111/wabot/tree/main/bot-discord/src/commands/Music): `bot-discord/src/commands/Music`
- [Audio player manager](https://github.com/nelson4111/wabot/blob/main/bot-discord/src/loaders/loadPlayerManager.js): `bot-discord/src/loaders/loadPlayerManager.js`
- [Discord database](https://github.com/nelson4111/wabot/blob/main/bot-discord/src/structures/Database.js): `bot-discord/src/structures/Database.js`

### Other components

- **WhatsApp user**
- **AI providers**
- **Discord user**
- **Lavalink nodes**

## Connections

- WhatsApp user → Bot runtime: sends messages
- Bot runtime → Plugin handlers: loads plugins
- Bot runtime → JSON database: initializes data
- Plugin handlers → AI commands: dispatches commands
- AI commands → AI coordinator: handles AI
- Plugin handlers → Media downloaders: dispatches commands
- Plugin handlers → Sticker tools: dispatches commands
- Plugin handlers → Menus: dispatches commands
- AI coordinator → Intent detector: checks intent
- AI coordinator → Context builder: builds context
- AI coordinator → Prompt builder: builds prompt
- AI coordinator → Knowledge retrieval: retrieves knowledge
- AI coordinator → Conversation memory: uses memory
- AI coordinator → Model selection: requests generation
- Model selection → AI providers: queries providers
- AI coordinator → Command executor: runs commands
- Discord user → Discord bot: issues commands
- Discord bot → Music commands: connects client
- Music commands → Audio player manager: uses playback
- Audio player manager → Lavalink nodes: dispatches audio
- Discord bot → Discord database: initializes database
