How vtvz/rustify works
Project Type and Purpose
• This is a Rust-based backend application that implements a Telegram Bot (“Rustify”) to let users interact with Spotify tracks, fetch lyrics from multiple providers, and perform analysis (e.g., profanity, listening spam prevention).
• There is also a small TypeScript microservice (“lyrics-provider”) that standardizes access to external lyrics sources.
• The project includes database migrations (Postgres), metrics collection (InfluxDB), observability dashboards (Grafana via Terraform/Jsonnet), and deployment automation (Docker Compose, Ansible).
Major Components
a. Telegram Bot Service (Rust)
• Handlers & Commands – src/telegram/…
• Business Logic – user_service, track_status_service, lyrics modules, profanity checks
• Queue Clients – publishes tasks for analysis/profanity checks
• Metrics – pushes to InfluxDB via src/metrics/influx.rs
b. Lyrics Provider Service (TypeScript)
• Exposes HTTP endpoints to fetch & normalize lyrics (AzLyrics, Genius, Musixmatch, Lrclib)
c. Database (PostgreSQL)
• Stores users, track statuses, whitelists, analysis results (migrations/)
d. Queue (e.g., Redis or other broker)
• Channels for “profanity_check”, “track_analysis” tasks
e. Worker Processes (Rust)
• Jobs that consume queue tasks (src/workers/)
• Perform heavy operations (e.g., calling lyrics‐provider, profanity module)
f. External APIs
• Telegram Bot API
• Spotify API (auth via src/spotify_auth_service.rs)
• Multiple lyrics providers (through lyrics-provider service)
g. Observability
• InfluxDB Collectors (via metrics module)
• Grafana Dashboards (infra/grafana/)
h. Deployment / Infra-as-Code
• Docker Compose definitions (docker-compose.yml, Dockerfiles)
• Ansible playbooks and roles (_infra/ansible/)
• Terraform/Jsonnet for Grafana (_infra/grafana/)
Interactions & Data Flows
1. User → Telegram API → Bot Service
2. Bot authenticates via Spotify API → if needed, stores tokens in Postgres
3. Bot enqueues lyrics‐fetch or profanity‐check jobs to the Queue
4. Worker service pulls task → calls Lyrics Provider Service (HTTP) → gets lyrics
→ performs profanity analysis → updates Postgres
5. Bot retrieves results from Postgres → replies to user
6. Throughout, metrics are emitted to InfluxDB
Architectural Patterns & Principles
• Asynchronous, decoupled microservices via message queues
• Single Responsibility: separate Bot, Worker, Provider services
• Infrastructure as Code (Ansible + Terraform) for reproducible deployments
• Clear layering: API layer (Telegram), Service layer (Rust code), Data layer (Postgres), Observability layer (Influx/Grafana)