# renatobo/telegrarm architecture

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

- Interactive diagram: https://gitdiagram.com/renatobo/telegrarm
- Repository: https://github.com/renatobo/telegrarm

## Overview

##### Project type and purpose
- This is a WordPress plugin (“TelegrARM”) that extends ARMember to send user-event notifications (new registrations, profile updates).
- It lives entirely inside the WordPress environment (hooks, options, plugin files, database).

##### File structure
- Top-level plugin entry point: telegrarm.php
- Feature modules:
- telegrarm_after_new_user_notification.php (handles new-user events)
- telegrarm_update_profile_external.php (handles profile-update events)
- telegrarm_settings.php (admin UI for bot token, channels, field mappings)
- uninstall.php (cleanup on plugin removal)
- Standard plugin assets: README.md, license, git workflows, packaging scripts—these live outside of the runtime environment.

##### README for technical stack
- WordPress 6.7+ / PHP 8.0+
- Depends on ARMember plugin (for membership events)
- Uses Telegram Bot API (external, out of scope per “show WordPress environment only”)

a. WordPress Core
- Plugin loader, action/filter dispatch system, options API, database API
b. ARMember Plugin
- Fires two key actions: “armember_user_registered” and “armember_profile_updated”
c. TelegrARM Plugin
- Registers hooks on ARMember events
- Settings page under WP Admin > Settings > Telegram Bot
- Stores credentials & mappings in wp_options
d. WordPress Database
- wp_options table holds TelegrARM settings
- (Optionally) any transient data (not used here)

##### Relationships and data flow (within WP)
- User triggers event → WP Core routes to ARMember
- ARMember emits action → TelegrARM’s listener functions fire
- TelegrARM reads settings from wp_options → builds notification payload
- (External: sends HTTP request to Telegram; omit in WP-only view)

##### Architectural patterns and design principles
- Modular plugin architecture: one file per notification type
- WordPress actions/filters as the integration/extension mechanism
- Separation of concerns:
- telegrarm_settings.php handles admin UI
- event handlers handle only data collection/formatting
- uninstall.php cleans up stored options

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "WordPress Environment"
        WP_Core["WordPress Core"]:::core
        ARMember["ARMember Plugin"]:::armember
        subgraph "TelegrARM Plugin"
            Telegrarm_Entry["telegrarm.php (Entry Point)"]:::telegrarm
            Telegrarm_Settings["telegrarm_settings.php"]:::telegrarm
            Telegrarm_NewUser["telegrarm_after_new_user_notification.php"]:::telegrarm
            Telegrarm_Update["telegrarm_update_profile_external.php"]:::telegrarm
            Telegrarm_Uninstall["uninstall.php"]:::telegrarm
        end
        DB["wp_options (Database)"]:::db
    end

    WP_Core -->|"route membership events"| ARMember
    ARMember -->|"do_action('armember_user_registered')"| Telegrarm_NewUser
    ARMember -->|"do_action('armember_profile_updated')"| Telegrarm_Update

    Telegrarm_Entry -->|"add_action('armember_user_registered')"| Telegrarm_NewUser
    Telegrarm_Entry -->|"add_action('armember_profile_updated')"| Telegrarm_Update
    Telegrarm_Entry -->|"add_action('admin_menu')"| Telegrarm_Settings
    Telegrarm_Entry -->|"register_uninstall_hook"| Telegrarm_Uninstall

    Telegrarm_Settings -->|"get_option() / update_option()"| DB
    Telegrarm_NewUser -->|"get_option()"| DB
    Telegrarm_Update -->|"get_option()"| DB
    Telegrarm_Uninstall -->|"delete_option()"| DB

    subgraph "Legend"
        LegendCore["WordPress Core"]:::core
        LegendAR["First-party Plugin (ARMember)"]:::armember
        LegendTG["TelegrARM Plugin"]:::telegrarm
        LegendDB["Database (wp_options)"]:::db
    end

    click Telegrarm_Entry "https://github.com/renatobo/telegrarm/blob/main/telegrarm.php"
    click Telegrarm_NewUser "https://github.com/renatobo/telegrarm/blob/main/telegrarm_after_new_user_notification.php"
    click Telegrarm_Update "https://github.com/renatobo/telegrarm/blob/main/telegrarm_update_profile_external.php"
    click Telegrarm_Settings "https://github.com/renatobo/telegrarm/blob/main/telegrarm_settings.php"
    click Telegrarm_Uninstall "https://github.com/renatobo/telegrarm/blob/main/uninstall.php"

    classDef core fill:#dddddd,stroke:#888888,stroke-width:1px
    classDef armember fill:#aaccff,stroke:#6666aa,stroke-width:1px
    classDef telegrarm fill:#ccffcc,stroke:#66aa66,stroke-width:1px
    classDef db fill:#ffccaa,stroke:#aa6633,stroke-width:1px
```
