# riozee/mikixbot architecture

> Architecture diagram of the GitHub repository riozee/mikixbot, 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/mikixbot
- Repository: https://github.com/riozee/mikixbot

## Overview

##### Project type and purpose
- This is a multi-process Node.js chatbot aggregator (“Miki Bot”) that unifies Telegram, WhatsApp, RSS, statistics, and a command & database layer into separate child processes.
- Purpose: spawn and supervise all bot sub-processes, route messages via an IPC protocol, and persist data in MongoDB.

##### File structure
- main/main.js: the orchestrator (heart) – forks sub-processes, mediates IPC, restarts on error.
- main/subproses/: each JS is a self-contained child process:
- bot/telegram.js, bot/whatsapp.js – platform adapters (indera & anggota gerak)
- perintah.js – command handler (otak)
- database.js – MongoDB wrapper (memori)
- rss.js – RSS feed fetcher
- statistic.js – usage statistics collector
- main/alat/: utility modules for media & math conversions (gif_konversi.js, webp_konversi.js, mathjs.js).
- main/utils.js: IPC class (signals vs queries).
- res/: static JSON/text datasets (word lists, Quran surahs, translations).
- package.json: Node dependencies & scripts.

##### Inspect README for extra clues
- Outlines IPC model:
- “sinyal” (fire-and-forget) vs “kueri” (request/reply with id tracking)
- IPC.kirimSinyal / IPC.kirimKueri semantics
- Defines roles: heart/main.js, brain/perintah.js, memory/database.js, sensors/telegram & whatsapp.
- Lists external requirements: ffmpeg, imagemagick, webpmux, MongoDB Atlas.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main orchestrator
    Main["Main Process\n(main/main.js)"]:::orchestrator

    %% Child Processes group
    subgraph "Child Processes"
        direction TB
        Telegram["Telegram Bot Adapter\n(telegram.js)"]:::process
        WhatsApp["WhatsApp Bot Adapter\n(whatsapp.js)"]:::process
        Perintah["Command Engine\n(perintah.js)"]:::process
        DatabaseProc["Database Engine\n(database.js)"]:::process
        RSS["RSS Feed Fetcher\n(rss.js)"]:::process
        Statistic["Statistics Collector\n(statistic.js)"]:::process
    end

    %% Utilities group
    subgraph "Utility Modules"
        direction TB
        GIF["GIF Conversion\n(gif_konversi.js)"]:::util
        WebP["WebP Conversion\n(webp_konversi.js)"]:::util
        MathJS["MathJS Wrapper\n(mathjs.js)"]:::util
    end

    %% Static Data group
    subgraph "Static Data"
        direction TB
        EnglishWords["1000 English Words\n(1000englishwords.txt)"]:::static
        IndonesianWords["Indonesian Words\n(indonesianwords.txt)"]:::static
        QuranSurahs["Quran Surahs\n(res/surahquran/*.json)"]:::static
        Translations["Text Translations\n(en.json, id.json)"]:::static
    end

    %% External services
    TelegramAPI["Telegram API"]:::external
    WhatsAppAPI["WhatsApp API"]:::external
    MongoDB["MongoDB Atlas"]:::db

    %% Connections: forks
    Main -->|fork| Telegram
    Main -->|fork| WhatsApp
    Main -->|fork| Perintah
    Main -->|fork| DatabaseProc
    Main -->|fork| RSS
    Main -->|fork| Statistic

    %% IPC channels
    Main <-->|"IPC (sinyal/kueri)"| Telegram
    Main <-->|"IPC (sinyal/kueri)"| WhatsApp
    Main <-->|"IPC (sinyal/kueri)"| Perintah
    Main <-->|"IPC (sinyal/kueri)"| DatabaseProc
    Main <-->|"IPC (sinyal/kueri)"| RSS
    Main <-->|"IPC (sinyal/kueri)"| Statistic

    %% Restart on error
    Main -.->|restart on error| Telegram
    Main -.->|restart on error| WhatsApp
    Main -.->|restart on error| Perintah
    Main -.->|restart on error| DatabaseProc
    Main -.->|restart on error| RSS
    Main -.->|restart on error| Statistic

    %% Child to external APIs
    Telegram -->|HTTPS| TelegramAPI
    WhatsApp -->|HTTPS| WhatsAppAPI

    %% Database connection
    DatabaseProc -->|MongoDB Driver| MongoDB

    %% Child to utilities
    Telegram -.->|uses| GIF
    Telegram -.->|uses| WebP
    WhatsApp -.->|uses| GIF
    WhatsApp -.->|uses| WebP
    Perintah -.->|uses| MathJS
    RSS -.->|uses| MathJS
    Statistic -.->|uses| MathJS
    DatabaseProc -.->|uses| MathJS

    %% Child to static data
    Perintah -.->|reads| EnglishWords
    Perintah -.->|reads| IndonesianWords
    RSS -.->|reads| QuranSurahs
    Perintah -.->|reads| Translations

    %% IPC utilities to Main
    utils["IPC Utilities\n(utils.js)"]:::util
    Main -->|requires| utils

    %% Click Events
    click Main "https://github.com/riozee/mikixbot/blob/main/main/main.js"
    click utils "https://github.com/riozee/mikixbot/blob/main/main/utils.js"
    click Telegram "https://github.com/riozee/mikixbot/blob/main/main/subproses/bot/telegram.js"
    click WhatsApp "https://github.com/riozee/mikixbot/blob/main/main/subproses/bot/whatsapp.js"
    click Perintah "https://github.com/riozee/mikixbot/blob/main/main/subproses/perintah.js"
    click DatabaseProc "https://github.com/riozee/mikixbot/blob/main/main/subproses/database.js"
    click RSS "https://github.com/riozee/mikixbot/blob/main/main/subproses/rss.js"
    click Statistic "https://github.com/riozee/mikixbot/blob/main/main/subproses/statistic.js"
    click GIF "https://github.com/riozee/mikixbot/blob/main/main/alat/gif_konversi.js"
    click WebP "https://github.com/riozee/mikixbot/blob/main/main/alat/webp_konversi.js"
    click MathJS "https://github.com/riozee/mikixbot/blob/main/main/alat/mathjs.js"
    click EnglishWords "https://github.com/riozee/mikixbot/blob/main/res/1000englishwords.txt"
    click IndonesianWords "https://github.com/riozee/mikixbot/blob/main/res/indonesianwords.txt"
    click QuranSurahs "https://github.com/riozee/mikixbot/blob/main/res/surahquran/*.json"
    click Translations "https://github.com/riozee/mikixbot/blob/main/res/teks/en.json"
    click Translations "https://github.com/riozee/mikixbot/blob/main/res/teks/id.json"

    %% Styles
    classDef orchestrator fill:#f9f,stroke:#333,stroke-width:2px
    classDef process fill:#bbf,stroke:#333
    classDef util fill:#bfb,stroke:#333
    classDef static fill:#fbf,stroke:#333
    classDef external fill:#fbb,stroke:#333,stroke-dasharray: 5 5
    classDef db fill:#ffb,stroke:#333,stroke-width:2px,stroke-dasharray: 2 2
```
