LearnGPT

Project
Learning made easy
LearnGPT

A full-stack study platform that combines AI-generated flashcards, a Pomodoro timer, and a feature-rich Telegram bot — letting users manage notes, tasks, and study sessions directly from Telegram as well as the web.
The bot communicates through a webhook endpoint (/api/telegram/webhook) secured with a secret_token header. Each incoming update is routed to a command handler that covers notes (/notes, /addnote, /flashcards, /regencard, /editcard, /addcard), tasks (/tasks, /addtask, /donetask, /taskcounter), AI summarisation (/summarise — accepts a file upload), and inline search across community notes (@bot <query>). State for multi-step flows (e.g., waiting for a file after /summarise) is tracked per-chat in a lightweight in-memory map, cleared on /cancel.
User-pasted text or an uploaded file is sent to the LLM via a Next.js API route. The prompt enforces a strict JSON structure (term / definition / example). Zod validates the response before it is persisted; invalid responses are retried with an error-correction prompt appended. Streaming is used so cards appear incrementally rather than after a full round-trip.
The timer is modelled as an explicit state machine (idle → work → short-break → long-break → idle) using a useReducer hook. Using a state machine instead of ad-hoc boolean flags makes illegal transitions (e.g., pausing a completed session) impossible by construction. The interval ID is stored in a ref rather than state to avoid re-render side effects on each tick. Pomodoro counts per task are tracked and exposed via /taskcounter in the bot.
Notes, flashcard decks, and tasks are stored in MongoDB. Cards embed directly inside their parent note document (sub-document array) since they are always accessed together, avoiding unnecessary round-trips. Task completion and pomodoro counters are updated with atomic $set / $inc operations to prevent race conditions from concurrent web and bot access.
The bot registers an inline_query handler so users can type @bot <query> in any Telegram chat for live, as-you-type community note search without opening a dedicated chat — results are returned asInlineQueryResultArticle objects with a debounced MongoDB text-index query on the backend.
Dual-interface app: a Next.js web frontend and a webhook-driven Telegram bot share the same API routes and MongoDB backend. The bot exposes notes, flashcard, task, and AI-summarise commands via Telegram's Bot API; the Pomodoro timer runs entirely as client state. An LLM API route handles both flashcard generation and document summarisation.
Made with