# mrdiz2112/gamebot architecture

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

- Interactive diagram: https://gitdiagram.com/mrdiz2112/gamebot
- Repository: https://github.com/mrdiz2112/gamebot

## Overview

##### Main Components
- Telegram Bot Interface: At the core is the Telegram bot built using the Grammy framework. This endpoint receives Telegram commands (/start, /help, /add, etc.) and channel inputs for notifications.
- Bot Handlers: Under src/bot/handlers you have different command and message handlers (e.g., BasicCommandHandler, GameCommandHandler, PartyCommandHandler, etc.) that process incoming messages and dispatch them to appropriate services.
- Services Layer: In src/services you have services like GameService, NotificationService along with parsers (e.g., SteamParser) to process game information.
- Database Integration: Prisma is used as the ORM to interact with a PostgreSQL database (see prisma/schema.prisma). The services will connect to the database via the Prisma client.
- Utility Modules & Logger: The project uses utilities such as the logger (src/utils/logger.ts) powered by Winston for logging and error tracking.
- Deployment/Containerization: Docker-related files (Dockerfile, docker-compose files) and environment scripts show that the application is containerized for both development and production.
- Configuration: Environment files (.env, .env.example) ensure proper configuration of sensitive keys (bot token and database URL).

##### Relationships/Interactions
- Telegram Bot Framework receives requests → dispatches the request to relevant bot handlers.
- Bot Handlers call the services (GameService, NotificationService) to execute business logic.
- Services interact with the database using Prisma to store and retrieve game data (prices, categories, tracking info).
- A specific parser (SteamParser) is used in the context of game addition and price scraping; it parses data from external sources (Steam) and feeds it into the services.
- Notification Service is responsible for compiling and sending notifications back to Telegram groups or topics.
- The utility Logger provides application-wide logging and can be depicted as an overlay used by all components.
- Deployment components (Dockerfile, docker-compose configurations) should be shown outside the core business logic to indicate deployment environments (development vs. production).

##### Architectural Patterns and Design Principles
- Modularization: The project has a clear separation between message handling, business logic (services), and persistence (database interactions via Prisma).
- Event-Driven/Command-Based Design: The bot responds to various Telegram commands that trigger corresponding event handlers and service calls.
- Containerization: Using Docker and multiple compose files to delineate development vs. production setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Telegram Bot Interface
    BotInterface["Telegram Bot Interface (Grammy)"]:::telegram

    %% Bot Handlers Subgraph
    subgraph "Bot Handlers"
        BasicCommandHandler["BasicCommandHandler"]:::handler
        GameCommandHandler["GameCommandHandler"]:::handler
        PartyCommandHandler["PartyCommandHandler"]:::handler
        NotificationHandler["NotificationHandler"]:::handler
        BaseHandler["BaseHandler"]:::handler
    end

    %% Services Layer Subgraph
    subgraph "Services Layer"
        GameService["GameService"]:::service
        NotificationService["NotificationService"]:::service
        SteamParser["SteamParser"]:::service
    end

    %% Database Integration
    Database["PostgreSQL Database (via Prisma ORM)"]:::db

    %% Utility Logger
    Logger["Winston Logger"]:::util

    %% Deployment Environment Subgraph
    subgraph "Deployment Environment"
        DockerfileNode["Dockerfile"]:::deployment
        DockerComposeNode["docker-compose.yml"]:::deployment
        DockerComposeDevNode["docker-compose.dev.yml"]:::deployment
        DockerComposeProdNode["docker-compose.prod.yml"]:::deployment
        DeployScript["deploy.sh"]:::deployment
        SetupDB["setup-db.sh"]:::deployment
    end

    %% Configuration
    Config["Configuration (.env.example & env)"]:::config

    %% Connections between components
    BotInterface -->|"receives_commands"| BasicCommandHandler
    BotInterface -->|"receives_commands"| GameCommandHandler
    BotInterface -->|"receives_commands"| PartyCommandHandler
    BotInterface -->|"receives_commands"| NotificationHandler
    BotInterface -->|"receives_commands"| BaseHandler

    %% Bot Handlers forward to Services Layer
    BasicCommandHandler -->|"processes_command"| GameService
    GameCommandHandler -->|"processes_game"| GameService
    PartyCommandHandler -->|"processes_party"| NotificationService
    NotificationHandler -->|"processes_notification"| NotificationService
    BaseHandler -->|"common_logic"| GameService

    %% SteamParser integration with GameService
    SteamParser -->|"parses_data"| GameService

    %% Services interact with Database
    GameService -->|"fetch/update_data"| Database
    NotificationService -->|"fetch/update_data"| Database

    %% Notification flow back to Telegram Bot Interface
    NotificationService -->|"send_notification"| BotInterface

    %% Logger interactions (dashed connectors represent logging overlays)
    BotInterface -.-> Logger
    BasicCommandHandler -.-> Logger
    GameCommandHandler -.-> Logger
    PartyCommandHandler -.-> Logger
    NotificationHandler -.-> Logger
    BaseHandler -.-> Logger
    GameService -.-> Logger
    NotificationService -.-> Logger
    SteamParser -.-> Logger

    %% Deployment and configuration influence the system
    Config -->|"configures"| BotInterface
    Config -->|"configures"| GameService
    Config -->|"configures"| NotificationService
    Config -->|"configures"| Database
    DeployScript -.-> BotInterface
    DockerfileNode -.-> BotInterface
    DockerComposeNode -.-> BotInterface

    %% Styles for components
    classDef telegram fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef handler fill:#B0E0E6,stroke:#333,stroke-width:2px;
    classDef service fill:#F4C2C2,stroke:#333,stroke-width:2px;
    classDef db fill:#98FB98,stroke:#333,stroke-width:2px;
    classDef util fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef config fill:#DDA0DD,stroke:#333,stroke-width:2px;

    %% Click Events for Telegram Bot Interface
    click BotInterface "https://github.com/mrdiz2112/gamebot/blob/master/src/bot/GameBot.ts"

    %% Click Events for Bot Handlers
    click BasicCommandHandler "https://github.com/mrdiz2112/gamebot/blob/master/src/bot/handlers/BasicCommandHandler.ts"
    click GameCommandHandler "https://github.com/mrdiz2112/gamebot/blob/master/src/bot/handlers/GameCommandHandler.ts"
    click PartyCommandHandler "https://github.com/mrdiz2112/gamebot/blob/master/src/bot/handlers/PartyCommandHandler.ts"
    click NotificationHandler "https://github.com/mrdiz2112/gamebot/blob/master/src/bot/handlers/NotificationHandler.ts"
    click BaseHandler "https://github.com/mrdiz2112/gamebot/blob/master/src/bot/handlers/BaseHandler.ts"

    %% Click Events for Services Layer
    click GameService "https://github.com/mrdiz2112/gamebot/blob/master/src/services/GameService.ts"
    click NotificationService "https://github.com/mrdiz2112/gamebot/blob/master/src/services/NotificationService.ts"
    click SteamParser "https://github.com/mrdiz2112/gamebot/blob/master/src/services/parsers/SteamParser.ts"

    %% Click Event for Database Integration
    click Database "https://github.com/mrdiz2112/gamebot/blob/master/prisma/schema.prisma"

    %% Click Event for Utility Logger
    click Logger "https://github.com/mrdiz2112/gamebot/blob/master/src/utils/logger.ts"

    %% Click Events for Deployment/Containerization
    click DockerfileNode "https://github.com/mrdiz2112/gamebot/tree/master/Dockerfile"
    click DockerComposeNode "https://github.com/mrdiz2112/gamebot/blob/master/docker-compose.yml"
    click DockerComposeDevNode "https://github.com/mrdiz2112/gamebot/blob/master/docker-compose.dev.yml"
    click DockerComposeProdNode "https://github.com/mrdiz2112/gamebot/blob/master/docker-compose.prod.yml"
    click DeployScript "https://github.com/mrdiz2112/gamebot/blob/master/env/deploy.sh"
    click SetupDB "https://github.com/mrdiz2112/gamebot/blob/master/env/setup-db.sh"

    %% Click Event for Configuration
    click Config "https://github.com/mrdiz2112/gamebot/blob/master/.env.example"
```
