How altiordev/easy_quiz_bot works
Project Overview and Main Components
• This project is a backend service for a Telegram-based quiz bot. It manages user authentication, quiz/test creation and execution, and integrates with PostgreSQL via Sequelize.
• The major building blocks include:
• Bot Module: Manages Telegram bot functionality using Telegraf, including scenes and keyboard interactions.
• API/Authentication Module: Provides Express endpoints for authentication (login, user registration) and CRUD operations for topics/tests/questions using RESTful design.
• Test Module: Handles quiz test logic, including question flow, managing user responses, and calculating results.
• Database Layer: Uses Sequelize to interface with a PostgreSQL database, mapping topics, tests, questions, options, and user answers.
• Middleware and Error Handling: Includes admin-checks, error handlers, and request/response validations.
• Utilities and Enums: Provides supporting functions and constants to support validation, data escaping, and status/error management.
Architectural Patterns and Design Principles
• Modularity: Emphasize that each main feature (auth, bot, tests) is in its own module and folder structure, simplifying maintenance and future extension.
• Separation of Concerns: Differentiate the Telegram bot logic from the RESTful API logic. Show clear boundaries between external communication (Telegram API) and internal service logic.
• Data Flow Direction:
• Incoming requests or messages (via webhook/polling or API calls) hit the Express app.
• Controllers route requests to service layers (auth.service, test.service, bot.service, etc.).
• Service layers interact with the database through Sequelize.
• Responses and updates flow back to the requester or, for bot interactions, are sent as Telegram messages.
• Use of TypeScript: Note that strong typing assists in maintaining well-defined interfaces (stored under src/interfaces).