# marco-antonio-rodrigues/telegrambot-esp32-cam architecture

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

- Interactive diagram: https://gitdiagram.com/marco-antonio-rodrigues/telegrambot-esp32-cam
- Repository: https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam

## Overview

##### Project Type and Purpose
- This is an embedded IoT project (firmware) running on an ESP32-CAM module.
- Purpose: detect motion via a PIR sensor, capture images with the camera, and send those images (or status messages) to a Telegram chat via the Telegram Bot API.

##### File Structure
- Top‐level:
- platformio.ini – build/deploy config for PlatformIO
- / – project headers and library READMEs
- lib/ESPmDNS/ – mDNS support library and examples
- src/ – main firmware modules (env.cpp/h, main.cpp, managerUsers, router, telegram)
- data/ & images/ – static assets, documentation files
- test/ – test scaffolding (empty)
- The presence of src/*.cpp and platformio.ini indicates embedded firmware code.
- The lib/ESPmDNS folder shows use of mDNS for local network discovery.

##### README
- Hardware components: ESP32-CAM, PIR sensor, optional microSD, USB-to-serial adapter.
- Logic flow: PIR → ESP32-CAM triggers photo capture → Telegram API sends image → optional user commands.
- Key variables and endpoints are configured in src/env.cpp.
- Libraries needed: camera driver, PIR input (GPIO 12), Wi-Fi, Telegram Bot client, ESPmDNS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        PIR["PIR Motion Sensor"]:::hardware
        ESP["ESP32-CAM Module"]:::hardware
        USB["Power Supply/USB-Serial Adapter"]:::hardware
    end

    %% Firmware Layer
    subgraph "ESP32 Firmware"
        Main["Core Firmware\n(main.cpp)"]:::firmware
        Sensor["Sensor Manager"]:::firmware
        Camera["Camera Controller"]:::firmware
        Config["Configuration Module"]:::firmware
        TgClient["Telegram Client"]:::firmware
        Router["Command Router"]:::firmware
        Users["User Manager"]:::firmware
        MDNS["mDNS Service"]:::firmware
    end

    %% Network Layer
    subgraph "Network Layer"
        Wifi["Wi-Fi Connectivity"]:::network
        Internet["Internet"]:::network
    end

    %% External Service
    subgraph "External Service"
        TelegramAPI["Telegram Bot API"]:::external
    end

    %% PlatformIO
    PlatformIO["platformio.ini"]:::config

    %% Connections
    PIR -->|"signal (GPIO12)"| ESP
    USB -->|"power & programming"| ESP

    ESP -->|hardware input| Sensor
    Sensor -->|"motion event"| Main
    Main -->|"capture request"| Camera
    Camera -->|"image data"| TgClient

    Config -->|"provide credentials\n& Bot token"| TgClient
    Config -->|"provide credentials\n& Bot token"| Router
    Config -->|"hostname config"| MDNS

    MDNS -->|"mDNS announce"| Wifi

    ESP -->|"TCP/IP"| Wifi
    Wifi --> Internet

    TgClient -->|"HTTP POST /sendPhoto"| Internet
    Internet -->|"forward to API"| TelegramAPI
    TelegramAPI -->|"getUpdates responses"| Internet
    Internet -->|"delivers updates"| Router

    Router -->|"route command"| Users
    Router -->|"control commands"| Main
    Router -->|"send messages"| TgClient

    %% PlatformIO links
    PlatformIO -.-> Main
    PlatformIO -.-> Sensor
    PlatformIO -.-> Camera
    PlatformIO -.-> Config
    PlatformIO -.-> TgClient
    PlatformIO -.-> Router
    PlatformIO -.-> Users
    PlatformIO -.-> MDNS

    %% Click Events
    click Config "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/env.cpp"
    click Config "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/env.h"
    click TgClient "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/telegram.cpp"
    click TgClient "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/telegram.h"
    click Router "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/router.cpp"
    click Router "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/router.h"
    click Users "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/managerUsers.cpp"
    click Users "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/managerUsers.h"
    click Main "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/src/main.cpp"
    click MDNS "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/lib/ESPmDNS/src/ESPmDNS.cpp"
    click MDNS "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/lib/ESPmDNS/src/ESPmDNS.h"
    click PlatformIO "https://github.com/marco-antonio-rodrigues/telegrambot-esp32-cam/blob/master/platformio.ini"

    %% Styles
    classDef hardware fill:#dddddd,stroke:#444,stroke-width:1px
    classDef firmware fill:#AED6F1,stroke:#1F618D,stroke-width:1px
    classDef network fill:#A9DFBF,stroke:#196F3D,stroke-width:1px
    classDef external fill:#F5CBA7,stroke:#B9770E,stroke-width:1px
    classDef config fill:#FCF3CF,stroke:#B7950B,stroke-width:1px
```
