# dangerblack/boardgame_night_bot architecture

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

- Interactive diagram: https://gitdiagram.com/dangerblack/boardgame_night_bot
- Repository: https://github.com/dangerblack/boardgame_night_bot

## Overview

##### Project Overview
- This project is a Telegram bot-based application designed to help organize board game nights. It enables event scheduling, RSVP tracking, and integrates with Telegram to manage interactions.
- The project is written in Go and includes both a bot component (handling Telegram interactions) and a web component (serving an API and rendering HTML templates).

##### Analyzing the File Structure
- Top-level files and config:
- .gitignore, CONTRIBUTING.md, LICENSE.md, and README.md indicate a well-documented open-source project.
- Dockerfile and docker-compose configuration files suggest that the app is containerized.
- go.mod and go.sum indicate dependency management via Go modules.
- Key directories in the project:
- src: Contains all Go source code. Notable subdirectories include:
- database: Implements database access and management.
- language: Likely for handling language-specific functionalities or parsing (in addition to the localization files).
- telegram: Contains functionalities for Telegram interactions.
- web: Further divided into 'api' (with controllers) and a server file, suggesting a REST/HTTP API endpoint.
- models: Contains data models shared across the system.
- localization: Holds .toml files for different active languages—this provides support for internationalization.
- templates: Contains HTML templates used by the web server to render pages (like error pages and event details).

##### Architectural Components and Interactions
- Main Application Entry:
- src/main.go acts as the entry point. It likely initializes the configuration environment, loads dependencies, and then bootstraps both the Telegram bot and the web server.
- Telegram Module:
- Hosted under src/telegram. This module is responsible for managing interactions with the Telegram API. It handles incoming messages, commands, and integrations that allow users to schedule or RSVP to events.
- Web/API Module:
- Located in src/web and its api sub-directory. This module likely exposes endpoints (RESTful or otherwise) that provide additional functionalities such as event viewing or API-based interactions.
- It uses controllers to parse requests and routes them through the business logic.
- Database Module:
- Managed in src/database (with db.go). Handles storage for events, RSVP data, and potentially other persistent state. The configuration for DB_PATH (provided in the environment variables) indicates that persistence might be file-based or use a local database instance.
- Models:
- Defined in src/models. This provides a shared domain model that underpins the communication between modules.
- Localization and Language Support:
- With the localization folder containing active language files and the src/language subdirectory, the system clearly supports multi-language capabilities, potentially providing localized content based on user preferences.
- Templates:
- The templates folder houses HTML files that will be rendered by the web server, indicating a server-side rendering component for events and error pages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    Entry["Main Application Entry"]:::core

    %% External Services
    ExtTelAPI["Telegram API"]:::external
    ExtWebClient["Web Client"]:::external

    %% Modules
    subgraph "Modules"
        T["Telegram Module"]:::core

        subgraph "Web/API Module"
            WS["Web Server"]:::core
            AC["API Controller"]:::core
        end

        D["Database Module"]:::db
        M["Models/Business Logic"]:::core

        subgraph "Localization Module"
            LH["Language Handler"]:::core
            LF["Localization Files"]:::core
        end
    end

    %% Connections from Entry
    Entry -->|"initializes"| T
    Entry -->|"initializes"| WS
    Entry -->|"initializes"| AC

    %% Telegram Module Interactions
    ExtTelAPI -->|"sends_updates"| T
    T -->|"processes_commands"| M
    T -->|"db_access"| D
    T ---|"localization"| LH
    T ---|"localization"| LF

    %% Web/API Module Interactions
    ExtWebClient -->|"http_request"| WS
    WS -->|"routes_to"| AC
    AC -->|"business_logic"| M
    AC -->|"crud_ops"| D
    WS ---|"localization"| LH
    WS ---|"localization"| LF
    AC ---|"localization"| LH
    AC ---|"localization"| LF

    %% Shared Models and Database
    M ---|"data_models"| D

    %% Click Events
    click Entry "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/main.go"
    click T "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/telegram/telegram.go"
    click WS "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/web/server.go"
    click AC "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/web/api/controller.go"
    click D "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/database/db.go"
    click M "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/models/models.go"
    click LH "https://github.com/dangerblack/boardgame_night_bot/blob/main/src/language/language.go"
    click LF "https://github.com/dangerblack/boardgame_night_bot/tree/main/localization"

    %% Styles
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef db fill:#cfc,stroke:#333,stroke-width:2px;
```
