# reymontg/tg-keyboard architecture

> Architecture diagram of the GitHub repository reymontg/tg-keyboard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/reymontg/tg-keyboard
- Repository: https://github.com/reymontg/tg-keyboard

## Overview

tg-keyboard is a PHP builder for Telegram keyboard and button structures, including Bot API and MTProto representations. A caller creates button objects, arranges them into reply or inline keyboards, configures keyboard options, then serializes or converts the result for its target syntax. The README documents row, stack, direct-button and coordinate editing, plus force-reply and hide variants; the tree and source index also show conversion support. Edges reflect explicit README workflows or source-index references; unsampled paths are represented only at their known directory level.

Main entry points: [`src/Keyboard/KeyboardMarkup.php`](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard/KeyboardMarkup.php) (Reply keyboard), [`src/Keyboard/KeyboardInline.php`](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard/KeyboardInline.php) (Inline keyboard), [`src/Button/KeyboardButton.php`](https://github.com/reymontg/tg-keyboard/blob/main/src/Button/KeyboardButton.php) (Reply button types), [`src/Keyboard.php`](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard.php) (Keyboard operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["Keyboard authoring"]
  node_keyboard_core["Keyboard operations<br/>[Keyboard.php]"]
  node_reply_keyboard["Reply keyboard<br/>[KeyboardMarkup.php]"]
  node_inline_keyboard["Inline keyboard<br/>[KeyboardInline.php]"]
  node_special_keyboards["Hide and force reply"]
  node_keyboard_options["Keyboard options"]
end

subgraph group_buttons["Button models"]
  node_button_base["Button base<br/>[Button.php]"]
  node_button_color["Button colors<br/>[Color.php]"]
  node_inline_factory["Inline button types<br/>[InlineButton.php]"]
  node_inline_variants["Inline button variants"]
  node_reply_factory["Reply button types<br/>[KeyboardButton.php]"]
  node_reply_variants["Reply button variants"]
  node_poll_type["Poll choices<br/>[PollType.php]"]
  node_url_helper["URL accessors<br/>[Url.php]"]
end

subgraph group_encoding["Conversion and encoding"]
  node_api_mtproto["API and MTProto output<br/>[Keyboard.php]"]
end

node_caller(("Library caller"))
node_telegram(("Telegram API / MTProto consumer"))

node_caller -->|"creates buttons"| node_inline_factory
node_caller -->|"creates buttons"| node_reply_factory
node_caller -->|"builds keyboard"| node_reply_keyboard
node_caller -->|"builds keyboard"| node_inline_keyboard
node_caller -.->|"chooses variant"| node_special_keyboards
node_caller -->|"edits layout"| node_keyboard_core
node_reply_keyboard -->|"creates buttons"| node_reply_factory
node_reply_keyboard -->|"adds buttons"| node_keyboard_core
node_inline_keyboard -->|"creates buttons"| node_inline_factory
node_inline_keyboard -->|"adds buttons"| node_keyboard_core
node_special_keyboards -->|"uses options"| node_keyboard_options
node_button_base -->|"encodes color"| node_button_color
node_inline_factory -->|"instantiates"| node_inline_variants
node_reply_factory -->|"instantiates"| node_reply_variants
node_reply_factory -->|"sets poll type"| node_poll_type
node_inline_variants -->|"extends"| node_button_base
node_reply_variants -->|"extends"| node_button_base
node_inline_variants -->|"uses URL accessors"| node_url_helper
node_reply_variants -->|"uses URL accessors"| node_url_helper
node_keyboard_core -->|"converts keyboards"| node_api_mtproto
node_reply_keyboard -.->|"serializes output"| node_api_mtproto
node_inline_keyboard -.->|"serializes output"| node_api_mtproto
node_api_mtproto -.->|"emits representations"| node_telegram

click node_keyboard_core "https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard.php"
click node_reply_keyboard "https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard/KeyboardMarkup.php"
click node_inline_keyboard "https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard/KeyboardInline.php"
click node_special_keyboards "https://github.com/reymontg/tg-keyboard/tree/main/src/Keyboard"
click node_keyboard_options "https://github.com/reymontg/tg-keyboard/tree/main/src/Keyboard/Utils"
click node_button_base "https://github.com/reymontg/tg-keyboard/blob/main/src/Button.php"
click node_button_color "https://github.com/reymontg/tg-keyboard/blob/main/src/Button/Color.php"
click node_inline_factory "https://github.com/reymontg/tg-keyboard/blob/main/src/Button/InlineButton.php"
click node_inline_variants "https://github.com/reymontg/tg-keyboard/tree/main/src/Button/InlineButton"
click node_reply_factory "https://github.com/reymontg/tg-keyboard/blob/main/src/Button/KeyboardButton.php"
click node_reply_variants "https://github.com/reymontg/tg-keyboard/tree/main/src/Button/KeyboardButton"
click node_poll_type "https://github.com/reymontg/tg-keyboard/blob/main/src/Button/PollType.php"
click node_url_helper "https://github.com/reymontg/tg-keyboard/blob/main/src/Button/Utils/Url.php"
click node_api_mtproto "https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_keyboard_core,node_reply_keyboard,node_inline_keyboard,node_special_keyboards,node_keyboard_options toneBlue
class node_button_base,node_button_color,node_inline_factory,node_inline_variants,node_reply_factory,node_reply_variants,node_poll_type,node_url_helper toneAmber
class node_api_mtproto,node_telegram toneMint
class node_caller toneIndigo
```

## Components

### Keyboard authoring

- [Keyboard operations](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard.php): `src/Keyboard.php`
- [Reply keyboard](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard/KeyboardMarkup.php): `src/Keyboard/KeyboardMarkup.php`
- [Inline keyboard](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard/KeyboardInline.php): `src/Keyboard/KeyboardInline.php`
- [Hide and force reply](https://github.com/reymontg/tg-keyboard/tree/main/src/Keyboard): `src/Keyboard`
- [Keyboard options](https://github.com/reymontg/tg-keyboard/tree/main/src/Keyboard/Utils): `src/Keyboard/Utils`

### Button models

- [Button base](https://github.com/reymontg/tg-keyboard/blob/main/src/Button.php): `src/Button.php`
- [Button colors](https://github.com/reymontg/tg-keyboard/blob/main/src/Button/Color.php): `src/Button/Color.php`
- [Inline button types](https://github.com/reymontg/tg-keyboard/blob/main/src/Button/InlineButton.php): `src/Button/InlineButton.php`
- [Inline button variants](https://github.com/reymontg/tg-keyboard/tree/main/src/Button/InlineButton): `src/Button/InlineButton`
- [Reply button types](https://github.com/reymontg/tg-keyboard/blob/main/src/Button/KeyboardButton.php): `src/Button/KeyboardButton.php`
- [Reply button variants](https://github.com/reymontg/tg-keyboard/tree/main/src/Button/KeyboardButton): `src/Button/KeyboardButton`
- [Poll choices](https://github.com/reymontg/tg-keyboard/blob/main/src/Button/PollType.php): `src/Button/PollType.php`
- [URL accessors](https://github.com/reymontg/tg-keyboard/blob/main/src/Button/Utils/Url.php): `src/Button/Utils/Url.php`

### Conversion and encoding

- [API and MTProto output](https://github.com/reymontg/tg-keyboard/blob/main/src/Keyboard.php): `src/Keyboard.php`

### Other components

- **Library caller**
- **Telegram API / MTProto consumer**

## Connections

- Library caller → Inline button types: creates buttons (evidence: `README.md`)
- Library caller → Reply button types: creates buttons (evidence: `README.md`)
- Library caller → Reply keyboard: builds keyboard (evidence: `README.md`)
- Library caller → Inline keyboard: builds keyboard (evidence: `README.md`)
- Library caller → Hide and force reply: chooses variant (evidence: `README.md`)
- Library caller → Keyboard operations: edits layout (evidence: `README.md`)
- Reply keyboard → Reply button types: creates buttons (evidence: `src/Keyboard/KeyboardMarkup.php`)
- Reply keyboard → Keyboard operations: adds buttons (evidence: `src/Keyboard/KeyboardMarkup.php`)
- Inline keyboard → Inline button types: creates buttons (evidence: `README.md`)
- Inline keyboard → Keyboard operations: adds buttons (evidence: `README.md`)
- Hide and force reply → Keyboard options: uses options (evidence: `src/Keyboard/KeyboardForceReply.php`)
- Button base → Button colors: encodes color (evidence: `src/Button.php`)
- Inline button types → Inline button variants: instantiates (evidence: `src/Button/InlineButton.php`)
- Reply button types → Reply button variants: instantiates (evidence: `src/Button/KeyboardButton.php`)
- Reply button types → Poll choices: sets poll type (evidence: `src/Button/KeyboardButton.php`)
- Inline button variants → Button base: extends (evidence: `src/Button/InlineButton.php`)
- Reply button variants → Button base: extends (evidence: `src/Button/KeyboardButton.php`)
- Inline button variants → URL accessors: uses URL accessors (evidence: `src/Button/InlineButton/LoginUrl.php`)
- Reply button variants → URL accessors: uses URL accessors (evidence: `src/Button/KeyboardButton/Webapp.php`)
- Keyboard operations → API and MTProto output: converts keyboards (evidence: `src/Keyboard.php`)
- Reply keyboard → API and MTProto output: serializes output (evidence: `src/Keyboard/KeyboardMarkup.php`)
- Inline keyboard → API and MTProto output: serializes output (evidence: `src/Keyboard/KeyboardInline.php`)
- API and MTProto output → Telegram API / MTProto consumer: emits representations (evidence: `README.md`)
