How giandomanc/ai-nutritionist works
This is an API-only Next.js Telegram nutrition bot. Telegram updates enter the webhook and are dispatched through Telegraf middleware to onboarding, profile, meal, and general-message handlers. The main user workflow collects a profile, interprets text or voice as a meal/advice/day-analysis command, then replies with estimates or analysis; meal confirmation and recent advice are session state. Source excerpts show key calls, while some subsystem links rely on the SOURCE INDEX; unsampled features are not expanded beyond documented or indexed evidence.
Main entry points: bot.ts Bot dispatcher · userMessage.ts Message handler · daily-analysis.service.ts Daily analysis · command.service.ts Command parsing
Components 25
Webhook and bot
- Webhook route
app/api/telegram/route.ts - Bot dispatcher
bot/bot.ts
User interaction
- User middleware
bot/middleware/loadUser.ts - Profile onboarding
bot/handlers/onboarding.ts - Start handler
bot/handlers/start.ts - Profile handler
bot/handlers/profile.ts - Meal interactions
bot/handlers/meal.ts - Message handler
bot/handlers/userMessage.ts - Advice session
bot/session/advice-session.ts - Voice transcription
bot/utils/transcribeTelegramVoice.ts - Analysis reply
bot/utils/replyWithTodayAnalysis.ts
Nutrition services
- Daily analysis
services/daily-analysis.service.ts - Meal records
services/meals/meal-record.service.ts
AI services
- Command parsing
services/ai/command.service.ts - Meal parsing
services/ai/meal-parser.service.ts - AI coaching
services/ai/coach.service.ts - Audio AI
services/ai/audio.service.ts - Groq client
services/ai/groq.client.ts - AI prompts and schemas
services/ai/prompts.ts - JSON extraction
services/ai/json.ts - AI data types
services/ai/types.ts
State and storage
- Prisma client
lib/prisma.ts - PostgreSQL
- Date utilities
lib/date.ts
Other components
- Telegram user
Connections 36
- Telegram user → Webhook route: sends updates
README.md - Webhook route → Bot dispatcher: forwards updates
app/api/telegram/route.ts - Bot dispatcher → User middleware: runs middleware
bot/bot.ts - Bot dispatcher → Profile onboarding: registers handler
bot/bot.ts - Bot dispatcher → Start handler: registers handler
bot/bot.ts - Bot dispatcher → Profile handler: registers handler
bot/bot.ts - Bot dispatcher → Meal interactions: registers handler
bot/bot.ts - Bot dispatcher → Message handler: registers handler
bot/bot.ts - User middleware → Prisma client: loads user
bot/middleware/loadUser.ts - Profile onboarding → Prisma client: creates profile
bot/handlers/onboarding.ts - Message handler → Command parsing: parses message
bot/handlers/userMessage.ts - Message handler → Voice transcription: transcribes voice
bot/handlers/userMessage.ts - Message handler → Advice session: uses advice state
bot/handlers/userMessage.ts - Message handler → Analysis reply: requests analysis reply
bot/handlers/userMessage.ts - Message handler → Daily analysis: requests food advice
bot/handlers/userMessage.ts - Message handler → Meal records: saves meal items
bot/handlers/userMessage.ts - Meal interactions → Meal records: uses meal services
bot/handlers/meal.ts - Voice transcription → Audio AI: transcribes audio
bot/utils/transcribeTelegramVoice.ts - Analysis reply → Daily analysis: requests analysis
bot/utils/replyWithTodayAnalysis.ts - Command parsing → Meal parsing: parses meal
services/ai/command.service.ts - Command parsing → Groq client: classifies command
services/ai/command.service.ts - Command parsing → AI prompts and schemas: uses prompt and schema
services/ai/command.service.ts - Command parsing → JSON extraction: extracts JSON
services/ai/command.service.ts - Meal parsing → Groq client: requests completion
services/ai/meal-parser.service.ts - Meal parsing → AI prompts and schemas: uses prompt and schema
services/ai/meal-parser.service.ts - Meal parsing → JSON extraction: extracts JSON
services/ai/meal-parser.service.ts - AI coaching → Groq client: generates response
services/ai/coach.service.ts - AI coaching → AI prompts and schemas: uses prompts
services/ai/coach.service.ts - Audio AI → Groq client: transcribes audio
services/ai/audio.service.ts - Daily analysis → Prisma client: reads today's meals
services/daily-analysis.service.ts - Daily analysis → Date utilities: gets day boundary
services/daily-analysis.service.ts - Daily analysis → AI coaching: generates analysis
services/daily-analysis.service.ts - Daily analysis → AI prompts and schemas: builds analysis prompts
services/daily-analysis.service.ts - Meal records → Prisma client: persists meals
services/meals/meal-record.service.ts - Meal records → Date utilities: uses date boundary
services/meals/meal-record.service.ts - Prisma client → PostgreSQL: connects to
lib/prisma.ts