Only inside Telegram
The Mini App opens from a button in the bot and identifies the person by Telegram’s login data.
AI product · Telegram bot and Mini App
From a food photo to a food diary.
You send the bot a photo, text or voice note about your food. AI models recognize the dishes, estimate grams, calories and macros, and log everything to a diary with a daily target.

01 / The task
A photo, text or voice note — and back comes a card with calories, macros and the day’s progress. Three conditions set the boundaries.
The Mini App opens from a button in the bot and identifies the person by Telegram’s login data.
Every recognition is a paid model call, and the product has a free plan.
On Vercel’s Hobby plan, background jobs run once a day; the project has two of them.
A photo caption is a hint for the model. Text like “a bowl of borscht and two slices of bread” or a voice note up to a minute gives the same result.
Dishes, grams, calories, macros and the day’s progress. If the bot got it wrong, reply to the card: “it was turkey, 200 g”, and the entry is recalculated.
Calorie and macro rings, a target from the Mifflin–St Jeor formula, grams on a slider, charts, favorite dishes in one tap.
Based on 7 days of stats and habits like skipping breakfast. Pro — every day, Free — twice a week.
Diet No. 5, Diet No. 9 and four more: the bot notes on the card whether the food fits the diet.
A photo captioned “can I?” is checked against the diet without being logged. If the day is empty, the bot sends an evening reminder and offers “ate as usual”.
03 / How I worked
The code was written by AI agents from my briefs. Below are decisions from the project documents.
163 server unit tests, 16 for the Mini App, 112 integration tests on PostgreSQL in CI. They found three defects: for example, the API accepted a challenge of 400 g of protein a day.
The daily limit is deducted atomically, in a single SQL query. One recognition per person at a time; repeated Telegram updates are dropped.
A 30-second timeout and a retry on network failure; the reply comes within 45 seconds at most. If the model fails, the attempt is refunded.
The Mini App opens only with verified Telegram data (HMAC-SHA256); RLS closes the tables to the Supabase public API.
Based on the repository’s code and documentation as of 19 October 2026. There are no figures on users or model accuracy here.
05 / Screens
The shots were taken from a working build of the Mini App, but the data is simulated: the user “Anya”, her meals and the AI’s replies are fictitious. Any shot opens full size. Swipe sideways
Everything runs in a single Vercel function on the free plan.
Stack TypeScript · Node 22 · Fastify · grammY · Prisma · PostgreSQL (Supabase) · React + Vite · Telegram Mini App · Telegram Stars · Vitest · GitHub Actions · Vercel
The bot is open to everyone: send it a photo of your lunch.
Open botBusiness analysis artifacts reconstructed from the repository’s code and documentation as of 19 October 2026. Every step, relationship and number is checked against a file; the paths are in the captions and in the “As text” blocks.
7.1 · Process, BPMN notation
Four lanes: the person, the Vercel function, the AI models and the database. There is no confirmation step: the entry is created immediately and can be edited afterwards — with buttons, in the Mini App or by replying to the card. The diagram is in two parts, linked by connectors A, B and C.
Part 1 · before recognition
Part 2 · recognition, card and editing
Three branches of the “What arrived?” gateway are not drawn: the “can I?” check (story US-4 below), text right after a recent entry, and “My dishes” without recognition — they are described in “As text”. The vision model names are not given: in production they are set by environment variables.
Source: in apps/bot-api/src — bot/handlers/food.ts:34–537 · api/routes/webhook.ts:28–79 · services/limits.ts:51–95 · services/locks.ts:18–29 · lib/ai.ts:9–202 · bot/mealCard.ts:22–74; at the root — vercel.json:10–15
Paths are relative to apps/bot-api/src; vercel.json, CRON.md, HANDOFF.md and docs/ are at the repository root.
waitUntil, Telegram gets a reply immediately and processing continues in the background. api/routes/webhook.ts:55–79update_id in the ProcessedUpdate table — even on another function instance; Telegram gets “ok” without processing. api/routes/webhook.ts:28–63google/gemini-2.5-flash); the bot shows what it heard and parses it as text. bot/handlers/food.ts:404–457 · ai/food.ts:141–154The update_id deduplication is described from the code and is not covered by tests. The 0.7 re-ask threshold is the default value in config.ts:30.
7.2 · Scheduled process
Once a day, at 18:00 UTC, a single function sends out advice, settles challenge results and reminds about empty days, all within 60 seconds. A repeat run is safe: a unique key prevents a second piece of advice for the same date, and anyone not reached gets theirs on the next run.
The price of Vercel’s free plan is precision: advice set for 08:00 arrives at 21:00 Moscow time. The diagram follows vercel.json and CRON.md; the schedule description in the README is outdated.
Source: in apps/bot-api/src — api/routes/cron.ts:15–32 · cron/dailyAdvice.ts:14–123 · prompts/advice.ts:22–34; at the root — vercel.json:46–55 · CRON.md:10–29, 65–72
Paths are relative to apps/bot-api/src; vercel.json, CRON.md, HANDOFF.md and docs/ are at the repository root.
/api/cron/hourly once a day, at 18:00 UTC (21:00 Moscow time): the Hobby plan allows two jobs a day; the second, at 08:00 UTC, handles monthly reports and subscriptions. vercel.json:46–55 · CRON.md:10–15CRON_SECRET and restores the webhook if Telegram is pointing elsewhere: the bot once stayed silent for three weeks after the webhook was removed. api/guards.ts:14–16 · api/routes/cron.ts:16–20 · HANDOFF.md:115DailyAdvice with a unique key (userId, date, kind) and sent to the chat as “🥗 Daily advice”; Free users get a note about Pro. cron/dailyAdvice.ts:86–96 · ../prisma/schema.prisma:175–1877.3 · ER diagram, crow’s foot notation
10 key models out of 15 in Prisma; challenges and the feed are collapsed into groups. The profile, diary, limits and subscriptions are tied to the user and deleted along with them; the AI cost log stays but loses its link to the person.
Person
UserAccount
idtgUserIdTelegram idtztime zoneProfileProfile and targets
userId→ User, 0..1targetKcal …calorie and macro targetsmedicalDietstherapeutic dietsDiary
MealMeal
iduserId→ UsereatenAttgMessageIdcard in the chatMealItemMeal item
idmealId→ Mealdish · gramsQuickCheck“Can I?” check
iduserId→ Userrecognitionfor logging without a second callRecipeMy dish
iduserId→ Usernametogether with userIdsourceMealId≈ Meal, no keyDailyAdviceAdvice or report
iduserId→ Userdate · kindtogether with userIdLimits and money
UsageCounterRecognition counter
userId→ Userdatelocal dayphotoCountSubscriptionPro subscription
iduserId→ Userplan · statusAiUsageAI call log
iduserId→ User, 0..1costUsdcall costWhen the person is deleted, the log stays, userId → NULL.
Collapsed
Challenges3 tables
Challenge · ChallengeParticipant · ChallengeDay; author and participants → User.
Feed2 tables, a stub without a screen
FeedVote · FeedReport; → Meal and → User.
Outside Prisma, created by code
ProcessedUpdate — repeated updates, kept for 2 days. RecognitionLock — one recognition at a time, userId without a key. BenchImage — model comparison bench photos, 2 hours.
In total the schema has 15 models, 9 enums and 17 foreign-key relationships; there are 10 migrations. The cards show the keys and fields that explain each table’s role; all 17 relationships are in “As text”. The feed is a stub: the schema and the service exist, but there is no screen and no API routes.
Source: apps/bot-api/prisma/schema.prisma · apps/bot-api/prisma/migrations · apps/bot-api/src/services/users.ts:51–63 · docs/ARCHITECTURE.md:89, 123–126
Line numbers refer to apps/bot-api/prisma/schema.prisma; the paths src/… and prisma/… are relative to apps/bot-api, HANDOFF.md is at the repository root.
| Foreign key | References | Cardinality | On delete | Line |
|---|---|---|---|---|
Profile.userId | User | 1 : 0..1 | Cascade | schema.prisma:87 |
Meal.userId | User | 1 : 0..N | Cascade | schema.prisma:124 |
MealItem.mealId | Meal | 1 : 0..N | Cascade | schema.prisma:160 |
QuickCheck.userId | User | 1 : 0..N | Cascade | schema.prisma:313 |
Recipe.userId | User | 1 : 0..N | Cascade | schema.prisma:221 |
DailyAdvice.userId | User | 1 : 0..N | Cascade | schema.prisma:178 |
UsageCounter.userId | User | 1 : 0..N | Cascade | schema.prisma:292 |
Subscription.userId | User | 1 : 0..N | Cascade | schema.prisma:203 |
AiUsage.userId | User | 0..1 : 0..N | SetNull | schema.prisma:40 |
Challenge.ownerId | User | 1 : 0..N | Cascade | schema.prisma:246 |
ChallengeParticipant.userId | User | 1 : 0..N | Cascade | schema.prisma:264 |
ChallengeParticipant.challengeId | Challenge | 1 : 0..N | Cascade | schema.prisma:262 |
ChallengeDay.challengeId | Challenge | 1 : 0..N | Cascade | schema.prisma:277 |
FeedVote.mealId | Meal | 1 : 0..N | Cascade | schema.prisma:327 |
FeedVote.voterId | User | 1 : 0..N | Cascade | schema.prisma:328 |
FeedReport.mealId | Meal | 1 : 0..N | Cascade | schema.prisma:341 |
FeedReport.reporterId | User | 1 : 0..N | Cascade | schema.prisma:342 |
Recipe.sourceMealId → Meal.id: a saved dish survives the deletion of the source meal schema.prisma:230ChallengeDay.userId → User.id: a column with no relation in Prisma or in the migration schema.prisma:278 · prisma/migrations/20260917150000_challengesRecognitionLock.userId → User.id: a table outside Prisma src/services/locks.ts:11ProcessedUpdate (updateId PK, createdAt): repeated Telegram updates; rows older than 2 days are deleted src/api/routes/webhook.ts:28–47RecognitionLock (userId PK, lockedAt): one recognition per person; a stuck lock is released after 90 seconds src/services/locks.ts:8–29BenchImage (id PK, dataUrl, createdAt): model comparison bench photos, kept for 2 hours src/api/bench.ts:48–56Deleting an account is a single action: prisma.user.delete; the delete rules do the rest src/services/users.ts:51–63. The schema has 9 enums and 10 migrations. The Meal.photoS3Key field is unused and not shown on the diagram HANDOFF.md:122.
7.4 · User journey
The journey is reconstructed from the code, not from interviews: at each stage — what the person does, how the product responds and which failure is handled in advance. There is no emotion curve: there is no data on how people feel.
1 · minute 0
bot/handlers/account.ts:19–86
2 · three steps
apps/webapp/src/App.tsx:29–80 · apps/webapp/src/screens/Onboarding.tsx:28–94 · services/nutrition.ts:26–46
3 · ~10 seconds
bot/handlers/food.ts:34–112, 404–456
4 · optional
bot/handlers/food.ts:206–237, 370–391 · bot/cards.ts:45–48
5 · after every entry
services/nextStep.ts:1–44 · bot/handlers/account.ts:89–106
6 · evening and the next day
cron/reminders.ts:19–63 · cron/schedule.ts:41–53 · cron/dailyAdvice.ts:56–98
Open gaps
Fig. 7.4The time labels are not measurements: “~10 seconds” is an estimate from the bot’s own text (“it takes ten seconds”). Stages 1 and 2 can be done in any order: a photo is accepted even without onboarding, and then the card shows calories without a target. Paths are relative to apps/bot-api/src unless stated otherwise.
7.5 · Requirements
Six stories the product already fulfills, with “Given — When — Then” acceptance criteria. 25 of 30 criteria are confirmed by integration tests on a real PostgreSQL; the other five are marked “from code”.
Fig. 7.5The stories are formulated from the code and tests: there is no backlog in this format in the repository. The tests stub out the model calls — they check the product’s behavior, not recognition quality. The tests are in apps/bot-api/src/__tests__/integration, reminders.test.ts is one level up.
7.6 · Research
Only the method is here. The results, charts and the decision are in a separate write-up.
Based on the repository’s code and documentation as of 19 October 2026; the model research is a separate branch from 20 October 2026, not merged into main. The diagrams are simplified; the full versions are in the “As text” blocks.