# riozee/miki-whatsappbot architecture

> Architecture diagram of the GitHub repository riozee/miki-whatsappbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/riozee/miki-whatsappbot
- Repository: https://github.com/riozee/miki-whatsappbot

## Overview

##### Project Type and Purpose
- This is a Node.js + TypeScript WhatsApp chat-bot (“Miki”) built around a plugin-based command framework. It connects to WhatsApp, listens for messages, and dispatches them to modular command handlers (plugins).

##### File Structure Overview
- Top-level config & metadata:
- miki-config.json – runtime configuration for the bot
- languages/en.json, id.json – i18n message templates
- package.json, tsconfig.json – build and dependency definitions
- src/ – main application code:
- main.ts – entrypoint; initializes the WhatsApp client and event loop
- handlers/ – core event processing:
– database.ts – persistence layer (e.g., read/write user state)
– handler.ts – central dispatcher that routes incoming messages to plugins
- plugins/ – each .ts file implements a single chat command or feature
- utils/ – shared functions and constants (logging, message builders, helper methods)
- .vscode, linting/prettier configs, and license are auxiliary.

##### Key Architectural Patterns
- Event-Driven / Plugin Architecture: Incoming WhatsApp events → handler → appropriate plugin → optional database calls or utils → reply.
- Modular Separation:
- Core Engine (main.ts + handler.ts)
- Plugins (individual features)
- Services (database handler)
- Shared Utilities (logging, constants, i18n)

##### Main Components
a. WhatsApp Client (external service)
b. Bot Core (main.ts + handler.ts)
c. Plugin Modules (each command in src/plugins/)
d. Database/Persistence Layer (e.g., local JSON or external DB via handlers/database.ts)
e. Configuration & Language Store (miki-config.json + languages/*.json)
f. Utilities Library (src/utils/)

##### Relationships and Data Flow
- Delivers “message” events via Baileys or similar WA API
- Extracts command identifier, user metadata
- Routes to the specific plugin based on command name
- read/write user stats, AFK flags, warning counts, etc.
- Sends replies, media, or stickers back to the user
- Config & Language are read by Bot Core & Plugins at startup or runtime

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Service
    WAC["WhatsApp Client\n(Baileys API)"]:::external
    click WAC "https://github.com/riozee/miki-whatsappbot/blob/master/src/main.ts"

    %% Configuration & Language
    subgraph "Config & Language"
        CFG["miki-config.json"]:::config
        EN["languages/en.json"]:::config
        ID["languages/id.json"]:::config
        PKG["package.json"]:::config
        TSF["tsconfig.json"]:::config
    end
    click CFG "https://github.com/riozee/miki-whatsappbot/blob/master/miki-config.json"
    click EN "https://github.com/riozee/miki-whatsappbot/blob/master/languages/en.json"
    click ID "https://github.com/riozee/miki-whatsappbot/blob/master/languages/id.json"
    click PKG "https://github.com/riozee/miki-whatsappbot/blob/master/package.json"
    click TSF "https://github.com/riozee/miki-whatsappbot/blob/master/tsconfig.json"

    %% Core Engine
    subgraph "Core Engine"
        Main["main.ts"]:::core
        Handler["handler.ts"]:::core
    end
    click Main "https://github.com/riozee/miki-whatsappbot/blob/master/src/main.ts"
    click Handler "https://github.com/riozee/miki-whatsappbot/blob/master/src/handlers/handler.ts"

    %% Database Service
    DB["database.ts\n(Persistence Layer)"]:::db
    click DB "https://github.com/riozee/miki-whatsappbot/blob/master/src/handlers/database.ts"

    %% Plugin Modules
    PModules["Plugin Modules\n(src/plugins/)"]:::plugin
    click PModules "https://github.com/riozee/miki-whatsappbot/tree/master/src/plugins/"

    %% Utilities & Types
    subgraph "Utils & Type Definitions"
        CST["constants.ts"]:::util
        MSG["message.ts"]:::util
        MTH["methods.ts"]:::util
        LOG["logger.ts"]:::util
        LM["logger-msg.ts"]:::util
        TD["types.d.ts"]:::config
    end
    click CST "https://github.com/riozee/miki-whatsappbot/blob/master/src/utils/constants.ts"
    click MSG "https://github.com/riozee/miki-whatsappbot/blob/master/src/utils/message.ts"
    click MTH "https://github.com/riozee/miki-whatsappbot/blob/master/src/utils/methods.ts"
    click LOG "https://github.com/riozee/miki-whatsappbot/blob/master/src/utils/logger.ts"
    click LM "https://github.com/riozee/miki-whatsappbot/blob/master/src/utils/logger-msg.ts"
    click TD "https://github.com/riozee/miki-whatsappbot/blob/master/src/@types/types.d.ts"

    %% Data Flow
    WAC -->|"emitMessage"| Main
    Main -->|"dispatchEvent"| Handler
    Handler -->|"dispatchCommand"| PModules
    PModules -->|"dbRead/dbWrite"| DB
    PModules -->|"sendReply"| WAC
    CFG --- Main
    CFG --- PModules
    EN --- Main
    EN --- PModules
    ID --- Main
    ID --- PModules

    %% Styles
    classDef external fill:#bbdefb,stroke:#1e88e5,color:#1e88e5;
    classDef core fill:#c8e6c9,stroke:#43a047,color:#43a047;
    classDef plugin fill:#ffe0b2,stroke:#fb8c00,color:#e65100;
    classDef db fill:#fff9c4,stroke:#fdd835,color:#fdd835;
    classDef config fill:#eceff1,stroke:#546e7a,color:#546e7a;
    classDef util fill:#d1c4e9,stroke:#8e24aa,color:#8e24aa;
```
