# miketester10/m-crypto-bot-ts architecture

> Architecture diagram of the GitHub repository miketester10/m-crypto-bot-ts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/miketester10/m-crypto-bot-ts
- Repository: https://github.com/miketester10/m-crypto-bot-ts

## Overview

##### And Label Main Components
- Telegram Bot Interface: Represent this as the entry point for user interactions on Telegram. Indicate that this component receives commands from users.
- Bot Controller / Main Process: Use the src/main.ts file as the central coordinator. This component is responsible for initializing the bot and dispatching incoming messages to appropriate handlers.
- Callback & Command Handlers: Include modules like src/callback.ts and any dedicated handler modules (e.g., for processing user input or commands).
- Chart Generation Module: Include the src/chart.ts module that handles the creation or formatting of chart data using the retrieved crypto price information.
- Information Module: Depicted via the src/info.ts file, this component could provide detailed status or summary data, possibly for debugging or more advanced user queries.
- Shared Utilities and Types: Represent src/shared.ts and the entire src/types submodule as supporting components. These provide types and utilities that are used across the application for ensuring type safety and reusability.
- Deployment Environment: Since there is a Docker Compose file (docker-compose.yml), include a container or environment block showing that this service runs within a Docker environment, which may pertain to deployment, testing, or local development.

##### Relationships and Data Flow
- One branch goes to the Callback and Command Handlers (src/callback.ts, etc.) which then call into the Chart Module (src/chart.ts) and Info Module (src/info.ts) based on the type of request.

##### Architectural Patterns & Design Principles
- Modularity: Emphasize that the project is broken into self-contained modules, each with single responsibilities.
- Separation of Concerns: Clearly delineate between user interaction (Telegram), business logic (command handling, charting, info), and external interactions (Coingecko API).
- Type Safety: With explicit type definitions in src/types, point out that robust error checking and data structure integrity are maintained.
- Scalability/Extensibility: Note that while the current architecture is not overly complex (no microservices), it is designed to be extended easily by adding new command modules or integrating additional data sources.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Component
    Telegram["Telegram Bot Interface (Telegram)"]:::external

    %% Docker/Deployment Environment
    subgraph "Docker/Deployment Environment"
        Deployment["Deployment (docker-compose.yml)"]:::deployment
        BotController["Bot Controller (src/main.ts)"]:::internal
        Callback["Callback/Command Handlers (src/callback.ts)"]:::internal
        Chart["Chart Module (src/chart.ts)"]:::internal
        Info["Information Module (src/info.ts)"]:::internal
        API["External API Integration (src/cg_calls.ts)"]:::internal
        Error["Error Handling (src/errors.ts)"]:::internal
        SharedUtil["Shared Utilities (src/shared.ts)"]:::internal
        Types["Types (src/types)"]:::internal
    end

    %% Relationships - Data Flow
    Telegram -->|"receivesMessage"| BotController
    Deployment -->|"hosts"| BotController
    BotController -->|"routesCommands"| Callback
    BotController -->|"directAPIcall"| API
    Callback -->|"processChart"| Chart
    Callback -->|"processInfo"| Info
    Callback -->|"fetchData"| API

    %% Error Handling Links
    BotController -->|"error"| Error
    Callback -->|"error"| Error
    Chart -->|"error"| Error
    Info -->|"error"| Error
    API -->|"error"| Error

    %% Shared Utilities & Types used across modules (dotted connections)
    BotController --- SharedUtil
    BotController --- Types
    Callback --- SharedUtil
    Callback --- Types
    Chart --- SharedUtil
    Chart --- Types
    Info --- SharedUtil
    Info --- Types
    API --- SharedUtil
    API --- Types
    Error --- SharedUtil
    Error --- Types

    %% Click Events for Component Mapping
    click Telegram "https://github.com/miketester10/m-crypto-bot-ts/blob/main/README.md"
    click BotController "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/main.ts"
    click Callback "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/callback.ts"
    click API "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/cg_calls.ts"
    click Chart "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/chart.ts"
    click Info "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/info.ts"
    click Error "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/errors.ts"
    click SharedUtil "https://github.com/miketester10/m-crypto-bot-ts/blob/main/src/shared.ts"
    click Types "https://github.com/miketester10/m-crypto-bot-ts/tree/main/src/types"
    click Deployment "https://github.com/miketester10/m-crypto-bot-ts/blob/main/docker-compose.yml"

    %% Style Definitions
    classDef external fill:#FFDDCC,stroke:#FF6600,stroke-width:2px;
    classDef internal fill:#CCFFCC,stroke:#009900,stroke-width:2px;
    classDef deployment fill:#CCE5FF,stroke:#004085,stroke-width:2px,stroke-dasharray: 5 5;
```
