# teamultroid/ultroid architecture

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

- Interactive diagram: https://gitdiagram.com/teamultroid/ultroid
- Repository: https://github.com/teamultroid/ultroid

## Overview

1. **What this repo is**  
   Ultroid is a long-running **Telegram userbot** with an additional **assistant/bot sidecar** and **voice/video-call music features**. The core runtime is Python 3.10+ and the main Telegram SDK is **Telethon**; voice chat/music functionality is built around **PyTgCalls**.

2. **Primary runtime shape**  
   The application is organized as a **single service process** that boots from `pyUltroid/__main__.py` and the `startup` scripts, then initializes Telegram clients, loads config, connects to storage, and dynamically imports feature modules. The root-level `startup`, `Dockerfile`, `docker-compose.yml`, `heroku.yml`, and `okteto-pipeline.yml` show that the same codebase is meant to run locally or in container/PaaS environments.

3. **Main execution boundary: user client vs assistant client**  
   There are two distinct Telegram-facing surfaces:
   - the **main userbot client** for commands sent through the logged-in user session,
   - the **assistant bot/client** under `assistant/`, which handles PM interactions, callbacks, inline behavior, and helper workflows.  
   This split is important architecturally because many features are exposed through the user account, while conversational UX and inline responses are delegated to the assistant.

4. **Plugin-driven feature layer**  
   Most application behavior lives in `plugins/`. This is the main extension boundary: each file is a feature module, not a microservice. The plugin set spans moderation, AFK, anti-flood, notes, filters, media tools, search/download/upload, profile utilities, scheduling, sticker/image/video tools, NSFW filtering, and automation. Support plugins like `_help.py`, `_inline.py`, `_ultroid.py`, `_userlogs.py`, and `_wspr.py` provide shared UX and logging behaviors.

5. **Assistant subsystem**  
   The `assistant/` package contains the assistant-side command and interaction handlers: callbacks, inline stuff, games, PM bot logic, start/help handlers, YTDL support, and a `manager/` subpackage for admin/help/AFK/sticker management. This is a distinct command surface from `plugins/`, but it reuses the same config, database, and utility layers.

6. **Persistence and state management**  
   Persistent state is abstracted through `pyUltroid/dB/`. The repo supports multiple backing stores as indicated by the README: **Redis**, **MongoDB**, or **SQLDB**. Feature-specific DB modules such as `afk_db.py`, `blacklist_db.py`, `notes_db.py`, `greetings_db.py`, `warn_db.py`, and others suggest a modular persistence model where each feature owns its own stored state rather than using one monolithic schema.

7. **Shared framework and helpers**  
   `pyUltroid/fns/` and `pyUltroid/_misc/` are the shared utility boundary used by both plugins and assistant modules. These files contain generic helpers for admin checks, execution, info formatting, gDrive, tools, downloads, and wrappers/decorators. `pyUltroid/startup/` contains bootstrapping logic such as client setup, database initialization, connection helpers, and runtime utilities.

8. **Media and external service integrations**  
   Several plugins are integration-heavy rather than purely local: YouTube/download tooling, Google Drive upload/share, Twitter/Unsplash/weather lookups, QR/image/pdf/video/audio conversion, and web uploads. These features form the repo’s outbound data-flow boundary: Telegram command -> plugin -> external API/service or local processing -> Telegram response.

9. **Localization and message content**  
   User-facing strings are externalized under `strings/strings/*.yml`, with many languages supported. That means command handlers usually route output through a localization layer rather than hardcoding text in the plugins, which matters for diagramming because message formatting is a shared cross-cutting concern.

10. **Deployment and bootstrap tooling**  
   The repo is packaged for several deployment modes: local shell startup, Docker, Heroku, Okteto, and Termux. Files like `.env.sample`, `installer.sh`, `install-termux`, `resources/session/*`, and `sessiongen` indicate that runtime setup depends on environment variables plus a generated Telegram **session string**. The architecture therefore assumes environment-driven configuration and external secret injection rather than built-in credential management.

11. **Operational flow to show in a diagram**  
   The clearest high-level flow is: **environment/session init → database connection → Telethon client startup → dynamic loading of plugins and assistant modules → command/event handling → optional persistence/external API calls → Telegram replies**. The assistant client and the main userbot share the same storage and helper layers, but they expose different interaction channels.

12. **Key boundaries to draw**  
   For an architecture diagram, the main boxes should be: **Telegram clients**, **plugin/assistant handlers**, **shared core utilities**, **persistent storage adapters**, and **external services/integrations**. The important distinction is that Ultroid is not a monolith of one command loop; it is a **plugin-based Telegram automation platform** with a separate assistant surface and a pluggable storage backend.

Main entry points: [`plugins`](https://github.com/teamultroid/ultroid/tree/main/plugins) (Plugins), [`assistant/manager`](https://github.com/teamultroid/ultroid/tree/main/assistant/manager) (Assistant manager), [`pyUltroid/startup`](https://github.com/teamultroid/ultroid/tree/main/pyUltroid/startup) (Startup flow), [`pyUltroid/loader.py`](https://github.com/teamultroid/ultroid/blob/main/pyUltroid/loader.py) (Loader core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime & bootstrap"]
  node_main_entry["Main entry<br/>python entrypoint<br/>[__main__.py]"]
  node_startup_flow["Startup flow<br/>bootstrap"]
  node_env_setup["Env & session<br/>deploy setup<br/>[ssgen.py]"]
  node_deploy_targets["Deploy targets<br/>runtime targets"]
end

subgraph group_surface["Telegram surfaces"]
  node_main_client(("Userbot client<br/>telethon client<br/>[BaseClient.py]"))
  node_assistant_client(("Assistant sidecar<br/>assistant client"))
  node_assistant_manager["Assistant manager<br/>assistant handlers"]
  node_plugin_layer["Plugins<br/>feature modules"]
end

subgraph group_core["Shared core"]
  node_shared_loader["Loader core<br/>module loader<br/>[loader.py]"]
  node_shared_utils["Helpers<br/>utility layer"]
  node_misc_layer["Misc core<br/>support layer"]
  node_localization["Strings<br/>i18n catalog"]
end

subgraph group_state["Persistence"]
  node_db_core[("DB core<br/>storage abstraction")]
  node_feature_state[("Feature state<br/>module stores<br/>[base.py]")]
  node_redis_mongo_sql[("Redis/Mongo/SQL<br/>backing stores")]
end

subgraph group_ext["External integrations"]
  node_tg_apis(("Telegram API<br/>telegram network"))
  node_media_services["Media services<br/>external APIs"]
  node_media_tools["Media tools<br/>processing tools<br/>[audiotools.py]"]
end

node_env_setup -->|"starts"| node_main_entry
node_deploy_targets -.->|"provisions"| node_env_setup
node_main_entry -->|"boots"| node_startup_flow
node_startup_flow -->|"creates"| node_main_client
node_startup_flow -->|"creates"| node_assistant_client
node_startup_flow -->|"connects"| node_db_core
node_startup_flow -->|"loads"| node_shared_loader
node_shared_loader -->|"imports"| node_plugin_layer
node_shared_loader -->|"imports"| node_assistant_manager
node_plugin_layer -->|"uses"| node_shared_utils
node_plugin_layer -->|"uses"| node_misc_layer
node_assistant_manager -->|"uses"| node_shared_utils
node_assistant_manager -->|"uses"| node_misc_layer
node_plugin_layer -->|"formats"| node_localization
node_assistant_manager -->|"formats"| node_localization
node_plugin_layer -->|"persists"| node_feature_state
node_assistant_manager -->|"persists"| node_feature_state
node_db_core -->|"backed by"| node_redis_mongo_sql
node_feature_state -->|"built on"| node_db_core
node_main_client -->|"talks to"| node_tg_apis
node_assistant_client -->|"talks to"| node_tg_apis
node_plugin_layer -->|"calls"| node_media_services
node_plugin_layer -->|"processes"| node_media_tools
node_assistant_manager -->|"calls"| node_media_services

click node_main_entry "https://github.com/teamultroid/ultroid/blob/main/pyUltroid/__main__.py"
click node_startup_flow "https://github.com/teamultroid/ultroid/tree/main/pyUltroid/startup"
click node_env_setup "https://github.com/teamultroid/ultroid/blob/main/resources/session/ssgen.py"
click node_deploy_targets "https://github.com/teamultroid/ultroid/tree/main/Dockerfile"
click node_main_client "https://github.com/teamultroid/ultroid/blob/main/pyUltroid/startup/BaseClient.py"
click node_assistant_client "https://github.com/teamultroid/ultroid/tree/main/assistant"
click node_assistant_manager "https://github.com/teamultroid/ultroid/tree/main/assistant/manager"
click node_plugin_layer "https://github.com/teamultroid/ultroid/tree/main/plugins"
click node_shared_loader "https://github.com/teamultroid/ultroid/blob/main/pyUltroid/loader.py"
click node_shared_utils "https://github.com/teamultroid/ultroid/tree/main/pyUltroid/fns"
click node_misc_layer "https://github.com/teamultroid/ultroid/tree/main/pyUltroid/_misc"
click node_localization "https://github.com/teamultroid/ultroid/tree/main/strings/strings"
click node_db_core "https://github.com/teamultroid/ultroid/tree/main/pyUltroid/dB"
click node_feature_state "https://github.com/teamultroid/ultroid/blob/main/pyUltroid/dB/base.py"
click node_media_tools "https://github.com/teamultroid/ultroid/blob/main/plugins/audiotools.py"

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_main_entry,node_startup_flow,node_env_setup,node_deploy_targets toneBlue
class node_main_client,node_assistant_client,node_assistant_manager,node_plugin_layer toneAmber
class node_shared_loader,node_shared_utils,node_misc_layer,node_localization toneMint
class node_db_core,node_feature_state,node_redis_mongo_sql toneRose
class node_tg_apis,node_media_services,node_media_tools toneIndigo
```

## Components

### Runtime & bootstrap

Process entrypoints and environment-driven startup paths.

- [Main entry](https://github.com/teamultroid/ultroid/blob/main/pyUltroid/__main__.py): python entrypoint · Bootstraps the application process and hands off to startup logic. · `pyUltroid/__main__.py`
- [Startup flow](https://github.com/teamultroid/ultroid/tree/main/pyUltroid/startup): bootstrap · Initial runtime setup: clients, config, database, and dynamic loading. · `pyUltroid/startup`
- [Env & session](https://github.com/teamultroid/ultroid/blob/main/resources/session/ssgen.py): deploy setup · Environment variables, session-string generation, and platform-specific launch helpers. · `resources/session/ssgen.py`
- [Deploy targets](https://github.com/teamultroid/ultroid/tree/main/Dockerfile): runtime targets · Docker, Heroku, Okteto, Termux, and local shell startup environments. · `Dockerfile`

### Telegram surfaces

Main userbot client and assistant sidecar interactions.

- [Userbot client](https://github.com/teamultroid/ultroid/blob/main/pyUltroid/startup/BaseClient.py): telethon client · Primary logged-in Telegram user session that executes most commands. · `pyUltroid/startup/BaseClient.py`
- [Assistant sidecar](https://github.com/teamultroid/ultroid/tree/main/assistant): assistant client · Secondary bot/client surface for PMs, callbacks, inline UX, and helper flows. · `assistant`
- [Assistant manager](https://github.com/teamultroid/ultroid/tree/main/assistant/manager): assistant handlers · Admin, help, AFK, sticker, and misc assistant workflows. · `assistant/manager`
- [Plugins](https://github.com/teamultroid/ultroid/tree/main/plugins): feature modules · Main extension boundary for userbot commands and event handlers. · `plugins`

### Shared core

Common utilities, loaders, localization, and support code.

- [Loader core](https://github.com/teamultroid/ultroid/blob/main/pyUltroid/loader.py): module loader · Dynamic import and runtime wiring for feature modules. · `pyUltroid/loader.py`
- [Helpers](https://github.com/teamultroid/ultroid/tree/main/pyUltroid/fns): utility layer · Shared admin checks, execution helpers, info formatting, wrappers, and support functions. · `pyUltroid/fns`
- [Misc core](https://github.com/teamultroid/ultroid/tree/main/pyUltroid/_misc): support layer · Cross-cutting decorators, assistant glue, and runtime helper wrappers. · `pyUltroid/_misc`
- [Strings](https://github.com/teamultroid/ultroid/tree/main/strings/strings): i18n catalog · Localized message catalogs used by handlers and plugins. · `strings/strings`

### Persistence

Backends and feature-scoped state adapters.

- [DB core](https://github.com/teamultroid/ultroid/tree/main/pyUltroid/dB): storage abstraction · Database facade and backend selection for persistent state. · `pyUltroid/dB`
- [Feature state](https://github.com/teamultroid/ultroid/blob/main/pyUltroid/dB/base.py): module stores · Per-feature state modules for AFK, filters, notes, warnings, blacklists, and similar data. · `pyUltroid/dB/base.py`
- **Redis/Mongo/SQL**: backing stores · Supported persistence backends for runtime state.

### External integrations

Outbound services and media-processing boundaries.

- **Telegram API**: telegram network · Telegram transport used by both userbot and assistant clients.
- **Media services**: external APIs · YouTube, Google Drive, Twitter, Unsplash, weather, web upload, and other outbound integrations.
- [Media tools](https://github.com/teamultroid/ultroid/blob/main/plugins/audiotools.py): processing tools · Local conversion, compression, QR, PDF, image, audio, video, and archive tooling. · `plugins/audiotools.py`

## Connections

- Env & session → Main entry: starts · Deployment setup launches the Python entrypoint.
- Deploy targets → Env & session: provisions · Container and platform targets provide environment and startup wiring.
- Main entry → Startup flow: boots · Entrypoint hands control to startup orchestration.
- Startup flow → Userbot client: creates · Startup initializes the main Telegram user client.
- Startup flow → Assistant sidecar: creates · Startup also initializes the assistant sidecar.
- Startup flow → DB core: connects · Runtime connects to the database abstraction.
- Startup flow → Loader core: loads · Startup dynamically imports feature modules.
- Loader core → Plugins: imports · Loader activates userbot plugins.
- Loader core → Assistant manager: imports · Loader activates assistant-side handlers.
- Plugins → Helpers: uses · Plugins rely on common helper functions.
- Plugins → Misc core: uses · Plugins share decorators and wrapper utilities.
- Assistant manager → Helpers: uses · Assistant handlers reuse shared helpers.
- Assistant manager → Misc core: uses · Assistant handlers reuse assistant glue and wrappers.
- Plugins → Strings: formats · Plugins resolve user-facing strings through localization catalogs.
- Assistant manager → Strings: formats · Assistant flows also use localized messages.
- Plugins → Feature state: persists · Feature handlers store module-specific state.
- Assistant manager → Feature state: persists · Assistant workflows also use feature-scoped storage.
- DB core → Redis/Mongo/SQL: backed by · Core storage can be backed by Redis, MongoDB, or SQLDB.
- Feature state → DB core: built on · Feature stores are implemented through the shared DB layer.
- Userbot client → Telegram API: talks to · Primary userbot communicates with Telegram.
- Assistant sidecar → Telegram API: talks to · Assistant surface communicates with Telegram.
- Plugins → Media services: calls · Integration plugins fetch or upload data to external services.
- Plugins → Media tools: processes · Media-oriented plugins perform local transformations and conversions.
- Assistant manager → Media services: calls · Assistant features can invoke external media and helper services.
