Yaroslav Smirnov

Train Prompts Bot – Interactive Prompt Engineering Education Platform

A production-grade educational system for teaching prompt engineering through structured lessons, AI-powered evaluation, and quota management. Built with aiogram 3 (Telegram bot framework), PostgreSQL, and multi-provider AI orchestration, it demonstrates expertise in modular bot architecture, middleware patterns, and educational system design.

Why This Project Matters

Problem 1: Prompt Engineering Skill Gaps

Problem 2: Scale vs. Cost Trade-off

Problem 3: Content Management at Bot Scale

Business Impact:

System Architecture & Design

Core Layers

1. Telegram Bot Interface (aiogram 3)

2. Backend Core (Python 3.9+ Async)

3. Educational Content Model

Lesson (ordered collection)
├── Step 1 (text + example prompts)
├── Step 2 (text + example prompts)
├── ...
├── Step N (quiz challenge)

Quiz
├── Question (text)
├── Rubric (evaluation criteria for AI grader)
├── Reference Answer (for quality checking)

UserProgress
├── lessons_completed (set of lesson IDs)
├── current_step (which step in current lesson)
├── quiz_scores (score per quiz)
└── leaderboard_position (ranked by points)

4. AI Integration Architecture

Generation Request
├─→ Quota Check (Is daily limit exceeded?)
├─→ Provider Selection (LLM7 for text, Together.ai for images)
├─→ Request Dispatch
│   ├─→ Primary provider (95% success rate)
│   ├─→ Fallback on timeout/rate-limit (5s timeout)
│   └─→ Error response if all fail
└─→ Result formatting + quota decrement (atomic)

Quiz Evaluation Pipeline
├─→ AI analyzes user answer against rubric
├─→ Generates score (0-100) + feedback
├─→ Stores result persistently
└─→ Updates leaderboard position

5. Data Persistence (PostgreSQL)

Data Flow: Learning Session

  1. User Starts Bot/start message
  2. Auto-Registration → User record created if new
  3. Menu Selection → User selects “Start Lesson”
  4. Lesson Delivery → Bot sends step 1 (text + example prompts)
  5. User Attempts → User submits their own prompt
  6. AI Generation → System calls text generation API (quota decremented atomically)
  7. Result Display → Bot shows generated output
  8. Step Progression → User proceeds to step 2, or completes lesson
  9. Quiz Challenge → Final step is interactive quiz
  10. AI Grading → Quiz answer sent to LLM for evaluation
  11. Score Recording → Result stored, leaderboard updated
  12. Feedback → Bot displays score + AI feedback

Key Technical Features

1. Modular Handler Architecture

2. Middleware Pattern for Cross-Cutting Concerns

3. Quota Management System

4. AI Provider Resilience

5. Assessment Pipeline

6. Content Seeding & Versioning

Technologies & Stack

Bot Framework

Backend

Database

External Services

Development & Testing

Engineering Challenges & Trade-offs

Challenge 1: Session Management Without Traditional Web Requests

Problem: Web apps have clear request/response cycles; Telegram bots receive async updates at unpredictable times.
Solution: Middleware wraps handler execution—open transaction at message arrival, commit at handler exit
Trade-off: More complex error handling (if handler crashes mid-transaction, rollback required)
Result: Guaranteed data consistency; partial writes impossible

Challenge 2: Quota Management Under Concurrency

Problem: Two users trigger generation simultaneously → both read quota=10, both proceed → consume 20 (exceeds limit)
Solution: Use UPDATE users SET quota = quota - 1 WHERE user_id = ? AND quota > 0 to atomically check + decrement
Trade-off: Second request fails if quota exhausted (user sees “quota exceeded”); requires retry logic client-side
Result: Strict quota enforcement; no overshooting

Challenge 3: AI Provider Failures vs. User Experience

Problem: Together.ai down → image generation times out → user waits 30s then sees error
Solution: Implement 5-second timeout; if provider doesn’t respond, immediately return cached response or generic message
Trade-off: Sometimes show “AI service temporarily unavailable” instead of actual output; feels less responsive
Decision: Better to admit failure quickly than hang the user

Challenge 4: Structured Lessons in Unstructured Bot Format

Problem: Lessons have ordering (Step 1 → Step 2 → …) but bot is message-driven (no guaranteed state)
Solution: Persist current_step in database; on each message, check step, display content, wait for user interaction
Trade-off: Can’t easily show “Step 2 of 5” progress UI (Telegram bots have limited UI)
Result: Functional but less visually polished than web version

Challenge 5: Cost Control with AI Generation

Problem: Unlimited users = unlimited generation requests = runaway costs
Solution: Daily quotas (10 text, 5 images) + admin bypass for testing
Trade-off: Strict limits frustrate power users; require separate “pro” tier for higher quotas
Decision: Prevents financial disaster; pro tier can be added later

Current State & Demo Notes

Implemented Features

Architecture Decisions Evident

Not Yet Implemented (Out of Scope for MVP)

How This Project Demonstrates My Expertise

Backend Engineering

System Design

DevOps & Data

Teaching & Communication

AI Integration

</div>

Engineering Challenges Solved

Unstable AI Providers

Added retry-capable provider selection, timeouts, and graceful fallbacks to ensure reliable AI generation even when individual providers experience issues.

Per-Update DB Safety

Implemented session middleware with commit/rollback safety to prevent partial writes and ensure data consistency during concurrent operations.

User Abuse Prevention

Implemented daily generation quotas with automatic reset and admin bypass to prevent abuse while ensuring fair usage.

Content Consistency

Created startup seeding pipeline for lessons and quizzes to keep environments aligned and ensure consistent content across deployments.

Impact & Educational Value

Technical Achievements

  • End-to-end async architecture for high concurrency
  • Modular design with clear separation of concerns
  • Robust error handling with graceful degradation
  • Secure admin controls with role-based access
  • Scalable data model for content growth

Educational Value

  • Structured learning path for prompt engineering
  • Immediate AI feedback for skill development
  • Progress tracking and motivation through ratings
  • Hands-on practice with real AI systems
  • Scalable platform for content expansion

System Demonstration

Key Features in Action

  • Lesson navigation with step-by-step progress
  • AI-powered text and image generation
  • Quiz system with AI evaluation
  • User ratings and leaderboard
  • Admin console for management

View the Implementation

Discover the modular architecture, lesson system, and AI integration on GitHub

View on GitHub →