# nadam/userinfobot architecture

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

- Interactive diagram: https://gitdiagram.com/nadam/userinfobot
- Repository: https://github.com/nadam/userinfobot

## Overview

##### Project type and purpose
- Type: A lightweight server-side Telegram bot deployed as a Java web application on Google App Engine.
- Purpose: Listens for forwarded messages in Telegram, extracts the original user’s ID, and replies with that ID.

##### File structure
- pom.xml – Maven build configuration (dependencies, plugins, App Engine deploy).
- src/main/java/se/anyro/userinfobot
– BuildVars.java – holds compile-time constants (e.g., bot token).
– UserInfoServlet.java – HTTP servlet handling incoming webhook updates.
- src/main/webapp/WEB-INF
– web.xml – servlet mapping and init parameters.
– appengine-web.xml – Google App Engine deployment descriptors.
– logging.properties – logging configuration.

Pattern: A single-module webapp using the Java Servlet API, packaged by Maven, and deployed to App Engine. It integrates two main libraries: TgBotApi (Telegram API) and GSON (JSON parsing).

##### Incorporate README insights
- Dependencies: TgBotApi for Telegram Bot API calls; GSON for JSON.
- Deployment target: Google App Engine standard environment for Java.
- No database or persistent storage – stateless, on-demand processing of each webhook call.

##### Main components
a. External Telegram Servers
– Telegram calls your bot’s webhook URL when a message is forwarded.
– Your bot uses Telegram API to send a reply.
b. Google App Engine Environment
– Servlet Container (Jetty or App Engine’s built-in server).
– UserInfoServlet:
- Parses incoming JSON updates (GSON).
- Extracts user info from the “forward_from” field.
- Uses TgBotApi to call sendMessage back to Telegram.
– BuildVars: holds configuration (bot token, webhook URL).
c. Build & Deployment
– Maven (pom.xml) builds .war, resolves dependencies, and deploys to App Engine using gcloud/appengine maven plugin.

##### Architectural patterns and design principles
- Stateless HTTP webhook handler – no persistent state in the app.
- Single-responsibility Servlet – solely processes “forwarded” updates and replies.
- Configuration-as-code (BuildVars + web.xml + appengine-web.xml).
- Dependency injection is minimal – components are instantiated directly in servlet init.

##### Essential elements
- Annotations on key components (e.g., “UserInfoServlet: handles /webhook, parses JSON”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    Telegram["Telegram Servers"]:::external

    %% App Engine Runtime
    subgraph "App Engine Runtime"
        ServletContainer["Servlet Container (Jetty)"]:::runtime
        UserInfoServlet["UserInfoServlet"]:::component
        BuildVars["BuildVars (config)"]:::component
    end

    %% Libraries
    subgraph "Libraries"
        GSON["GSON Library"]:::library
        TgBotApi["TgBotApi Library"]:::library
    end

    %% Configuration Files
    subgraph "Configuration"
        WebXml["web.xml"]:::config
        AppEngineXml["appengine-web.xml"]:::config
        Logging["logging.properties"]:::config
        README["README.md"]:::config
    end

    %% Build & Deployment Pipeline
    subgraph "Build & Deployment"
        LocalDev["Local Dev"]:::pipeline
        Maven["Maven"]:::pipeline
        GCloud["gcloud/appengine plugin"]:::pipeline
    end

    %% Data Flow
    Telegram -->|"HTTPS POST /webhook"| UserInfoServlet
    UserInfoServlet -->|"reads constants"| BuildVars
    UserInfoServlet -->|"deserializes JSON"| GSON
    UserInfoServlet -->|"invokes sendMessage()"| TgBotApi
    TgBotApi -->|"HTTPS request"| Telegram

    %% Configuration Loading
    WebXml --> ServletContainer
    AppEngineXml --> ServletContainer
    Logging --> ServletContainer
    README --> LocalDev

    %% Deployment Flow
    LocalDev -->|"runs mvn appengine:deploy"| Maven
    Maven -->|"deploy war"| GCloud
    GCloud -->|"deploy to"| ServletContainer

    %% Click Events
    click Maven "https://github.com/nadam/userinfobot/blob/master/pom.xml"
    click BuildVars "https://github.com/nadam/userinfobot/blob/master/src/main/java/se/anyro/userinfobot/BuildVars.java"
    click UserInfoServlet "https://github.com/nadam/userinfobot/blob/master/src/main/java/se/anyro/userinfobot/UserInfoServlet.java"
    click WebXml "https://github.com/nadam/userinfobot/blob/master/src/main/webapp/WEB-INF/web.xml"
    click AppEngineXml "https://github.com/nadam/userinfobot/blob/master/src/main/webapp/WEB-INF/appengine-web.xml"
    click Logging "https://github.com/nadam/userinfobot/blob/master/src/main/webapp/WEB-INF/logging.properties"
    click README "https://github.com/nadam/userinfobot/blob/master/README.md"

    %% Styles
    classDef external fill:#dddddd,stroke:#333,stroke-width:1px
    classDef runtime fill:#bbddff,stroke:#333,stroke-width:1px
    classDef component fill:#ffffff,stroke:#333,stroke-width:1px
    classDef library fill:#bbffbb,stroke:#333,stroke-width:1px
    classDef pipeline fill:#ddffdd,stroke:#333,stroke-width:1px
    classDef config fill:#ffffff,stroke:#666,stroke-width:1px,stroke-dasharray: 5 5
```
