# urstrulycherry/mybot architecture

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

- Interactive diagram: https://gitdiagram.com/urstrulycherry/mybot
- Repository: https://github.com/urstrulycherry/mybot

## Overview

##### Main Components
- Entry Point & Core Engine:
- Index.ts as the starting point.
- A “Bot Engine” or “Message Dispatcher” component which receives incoming messages, interprets the command based on prefixes (".", "!", "#", "$"), and delegates to the appropriate module.
- Modules (Command Handlers):
- “modules” folder where each file (e.g., alive, calc, chat, cricket, currency, etc.) is an individual command module.
- Sub-folder “socialMedia” as a specialized group of modules handling media from platforms like Twitter, Instagram, and YouTube.
- Utility Services:
- Configuration & Data:
- Configuration aspect by including the “data” folder (with config.json and settings.json) along with the global configuration file (conf.ts); note these provide runtime parameters.
- External Dependencies:
- Use of external packages such as whatsapp-web.js, Puppeteer (via puppeteerManager.ts), and possibly others referenced in package.json. These are critical for the bot’s interactions and capabilities.

##### Relationships and Interactions
- Dependency from the Command Modules to the Utility Services for supporting operations like reply formatting, external requests, and media handling.
- Flow from configuration data into both the main engine and various modules so they can access global settings.

##### Architectural Patterns & Design Principles
- Modular Design: Emphasize that each chat command is implemented as its own module, making the system extensible (new features/modules can be added following the skeleton provided in the Contribution section of the README).
- Separation of Concerns: Distinct handling of core logic (message dispatch, configurations) versus module-specific implementations.
- Configuration-driven: The presence of configuration files (data/config.json, data/settings.json, and conf.ts) suggests that runtime behavior can be controlled externally, an important layer in the architecture.
- Consistent Interface: The common function signature for each module (as shown in the README snippet) signifies a uniform interface that aids in dynamic module loading.

- Be as detailed as possible by breaking the project down into its essential architectural elements.
- Clearly articulate the contract between the Bot Engine and the modules (the uniform process interface).
- Clarity around external integrations (WhatsApp for receiving messages, social media for downloading content).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Layer
    subgraph "Core Layer"
        A["Entry Point (index.ts)"]:::core
        B["Bot Engine / Message Dispatcher"]:::core
    end

    %% Modules Layer
    subgraph "Modules Layer"
        D["General Command Modules"]:::module
        E["Social Media Modules"]:::module
    end

    %% Utility Services
    subgraph "Utility Services"
        F["Utility Services"]:::utility
    end

    %% Configuration & Data
    subgraph "Configuration & Data"
        G1["Global Config (conf.ts)"]:::config
        G2["Data Files (data)"]:::config
    end

    %% External Dependencies
    H["External Dependencies"]:::external

    %% Connections
    H -->|"WhatsAppMessages"| A
    A -->|"initializes"| B
    B -->|"dispatchesCommand"| D
    B -->|"dispatchesCommand"| E
    D -->|"callsUtilities"| F
    E -->|"callsUtilities"| F
    G1 -->|"injectsSettings"| A
    G1 -->|"injectsSettings"| B
    G1 -->|"injectsSettings"| D
    G1 -->|"injectsSettings"| E
    G2 -->|"injectsSettings"| A
    G2 -->|"injectsSettings"| B
    G2 -->|"injectsSettings"| D
    G2 -->|"injectsSettings"| E
    F -->|"supportsOperations"| B

    %% Click Events
    click A "https://github.com/urstrulycherry/mybot/blob/master/index.ts"
    click B "https://github.com/urstrulycherry/mybot/blob/master/util/modules.ts"
    click D "https://github.com/urstrulycherry/mybot/tree/master/modules"
    click E "https://github.com/urstrulycherry/mybot/tree/master/modules/socialMedia"
    click F "https://github.com/urstrulycherry/mybot/tree/master/util"
    click G1 "https://github.com/urstrulycherry/mybot/blob/master/conf.ts"
    click G2 "https://github.com/urstrulycherry/mybot/tree/master/data"
    click H "https://github.com/urstrulycherry/mybot/blob/master/package.json"

    %% Styles
    classDef core fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef module fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef utility fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef config fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#000,stroke-width:2px;
```
