Architecture: Integrations
Telegram TDLib
- Transport entry:
backend/tg_client/dialogs/tdlib/base.py - Raw wrappers:
backend/tg_client/dialogs/tdlib/api/* - Runtime usage:
- command execution through service calls
- update callbacks attached in
owner_worker.py
Messaging (NATS / JetStream)
Relevant files:
backend/tg_client/messaging/api.pybackend/tg_client/messaging/envelopes.pybackend/tg_client/messaging/subjects.pybackend/tg_client/messaging/topology.pybackend/tg_client/messaging/config.py
Actual integration points visible in code:
- commands are published as
CommandEnvelope - owner workers consume shard-based command streams
- live events are published both as durable event envelopes and transient live subjects
- WebSocket consumer subscribes to targeted
rt.*live subjects
Ownership / lease backend
Visible from code:
publish_command()resolvesexpected_owner_epoch- owner runtime checks lease/epoch before handling commands
- configuration points live in
backend/tg_client/messaging/config.py - owner runtime obtains coordinator through
tg_client.ownership.registry
This docs set covers the integration boundary but not the entire ownership backend implementation in detail.
Cache / projection backend
DialogCacheuses DjangocacheCacheProjectionUpdaterstores snapshots/recent eventsReplayServicereplays recent events from cache-backed snapshot data
Needs verification based on code: the exact cache backend (Redis / memory / something else) is defined by Django settings, not by dialogs itself.
Cloud storage
Relevant files:
backend/tg_client/dialogs/services/save_to_cloud.pybackend/tg_client/dialogs/services/media_loader.pybackend/tg_client/dialogs/services/file_generation.py
Observed behavior:
- uses
default_storageand explicit boto3 client helpers - can auto-create the bucket when missing
- provides presigned GET/PUT URLs
- stores Telegram media by stable keys derived from remote unique ids or file ids
Database / ORM
Dialogs runtime depends on Django ORM models from backend/tg_client/models.py:
UserBotCustomEmojiCommandExecution
The subsystem does not define a repository layer; services/runtime access ORM-backed helpers directly.