diff --git a/Architecture.md b/Architecture.md index 4282630..96f1934 100644 --- a/Architecture.md +++ b/Architecture.md @@ -4,8 +4,106 @@ The `telegram` and `telegram.ext` packages contain several classes that make wri You have met most of them in the [[tutorial|Extensions---Your-first-Bot]]. Because all of that can be a bit overwhelming, the below diagram gives you an overview of how the different components interact with each other. -[[/assets/ptb_architecture.png]] -[[LaTeX + TikZ source of this diagram|/assets/ptb_architecture.tex]] +```mermaid +flowchart TD; + AppBuilder(" + ext.ApplicationBuilder + builder pattern for + ext.ApplicationBuilder + "); + App(" + ext.Application + + • entry point for the whole application + • provides convenience methods for running the whole app via run_polling/webhook() + • administers handlers and error handlers + • administers user/chat/bot_data + "); + BaseHandler(" + ext.BaseHandler + specifies if and how + it handles updates + "); + BaseRateLimiter(" + ext.BaseRateLimiter + interface for rate limiting + API requests + "); + BaseRequest(" + request.BaseRequest + interface for handling the + networking backend + "); + BasePersistence(" + ext.BasePersistence + interface for persisting + data from ext.Application + across restarts + "); + BaseUpdateProcessor(" + ext.BaseUpdateProcessor + interface for processing + updates concurrently + "); + Bot(" + (ext.Ext)Bot + Telegram Bot API client + used to make requests + to the API + "); + CallbackContext(" + ext.CallbackContext + Convenience class for unified + access to different objects within + handler/job/error callbacks + "); + CallbackDataCache(" + ext.CallbackDataCache + in-memory LRU-cache for + arbitrary callback_data + "); + ContextTypes(" + ext.ContextTypes + specifies types of + the context argument + "); + Defaults(" + ext.Defaults + gathers default values for frequently + used parameters of (ext.Ext)Bot, + Ext.JobQueue and ext.BaseHandler + "); + JobQueue(" + ext.JobQueue + schedules tasks to run + at specific times + "); + Updater(" + ext.Updater + fetches updates from Telegram + and puts them into the update_queue + "); + + AppBuilder -- builds --> App; + App -- accesses to build context --> ContextTypes; + App -- "provides arguments for
handler callbacks, processes exceptions
raised in handler callbacks" --> BaseHandler; + App -- processes exceptions
raised in jobs --> JobQueue; + App -- fetches data
and passes it to
ext.BasePersistence --> CallbackDataCache; + App -- fetches updates from
the update_queue --> Updater; + App -- updates in
regular intervals --> BasePersistence; + App -- gets default values
for parameters --> Defaults; + App -- dispatches updates --> BaseUpdateProcessor; + BaseUpdateProcessor -- processes updates
in specified
concurrency scheme--> BaseHandler; + ContextTypes -- specifies types --> CallbackContext; + BasePersistence -- holds a reference --> Bot; + BaseRateLimiter -- rate limits requests
to the API --> BaseRequest; + Bot -- dispatches requests
to the API --> BaseRateLimiter; + Bot -- gets default values
for parameters --> Defaults; + Bot -- stores arbitrary
callback_data --> CallbackDataCache; + JobQueue -- accesses to
build context --> ContextTypes; + Updater -- calls get_updates
& set/delete_webhook --> Bot; + +``` ---