How reywaltz/telemetr works
Project type and purpose
• Telemetr is a Python-based monitoring tool for collecting statistics about Telegram channels.
• It bundles three “mini-apps” (an auth bot, a fetcher, and a REST API) into a cohesive service that reads/writes data to a Postgres database and logs events.
File structure
• Top-level orchestrator: app.py.
• Apps folder:
• apps/auth_bot – a Telegram bot that handles user authentication and commands.
• apps/fetcher – a worker that periodically scrapes channel stats.
• apps/telemetr/api – a Flask/FastAPI-style REST API exposing stats.
• internal: domain logic modules (admin, categories, channels, users), plus infrastructure adapters:
• internal/telegram – Telegram client wrapper.
• internal/postgres – ORM/DAO layer.
• pkg/log: centralized logging (file logger + interface).
• schema.sql + requirements.txt.
Key insights from README
• Single-purpose: monitor Telegram channel statistics.
• No frontend beyond the Telegram bot and the JSON API.
Main components
a. External services
• Telegram Bot API (for auth_bot).
• Telemetr web source (for fetcher scrapes).
b. Micro-apps (deployed together or as separate processes)
• Auth Bot
• Fetcher Worker
• Telemetr REST API
c. Database
• Postgres (tables: users, categories, channels, admin, stats).
d. Shared libraries/internals
• Domain logic (internal/*).
• Infrastructure adapters (internal/postgres, internal/telegram).
• Logging (pkg/log).
Relationships and data flows
• Auth Bot ↔ Telegram API: receives commands → uses internal modules → reads/writes Postgres → replies to user.
• Fetcher → Telemetr website: scrapes stats → transforms via internal/channel & internal/categories → writes to Postgres.
• REST API ← clients: HTTP requests → handlers in apps/telemetr/api → query Postgres via internal/postgres → respond.
• All components import pkg/log to record events.
Architectural patterns and principles
• Layered architecture:
• Presentation/adapters: bots + API.
• Domain: internal/* modules encapsulating business logic.
• Infrastructure: DB adapters, HTTP/Telegram clients, logging.
• Separation of concerns: each app has a single responsibility.
• Dependency inversion: domain modules don’t depend on external libraries directly; they use small adapters.