A local nutrition tracking app powered by AI
This document details the core logic and integration flows of YuHeng, explaining how different components interact to process user requests.
YuHeng uses an asynchronous flow to ensure the UI remains responsive even during complex AI analysis.
sequenceDiagram
participant User
participant Frontend
participant API as Backend (API)
participant DB as Database
participant LLM as AI Provider
User->>Frontend: Upload Photo / Enter Text
Frontend->>API: POST /api/nutrition/recognize
API->>DB: Create RecognitionTask (status: pending)
API-->>Frontend: Return taskId
par Background Task
API->>LLM: Send Image + Prompt
LLM-->>API: Return JSON dishes
API->>DB: Update RecognitionTask (status: complete, results)
end
loop Every 2 seconds
Frontend->>API: GET /api/nutrition/tasks/[id]
API-->>Frontend: Return status + results
end
Frontend->>User: Display Results for Review
When a user adjusts their personal portion or shares a meal, the following calculation occurs:
LoggedCalories = TotalCalories * (PersonalPortion / TotalDish).When a user changes their region in settings:
SettingsPage updates the local state and triggers saveSettings.g and oz, the app attempts to convert current target values to keep them consistent for the user.recognition_language and region context to improve localized accuracy.