A local nutrition tracking app powered by AI
✅ Implementation Status: Completed & Stable
YuHeng implements a sophisticated client-side queue for image recognition tasks. This allows users to upload multiple photos in quick succession and handle recognition results asychronously.
The recognition system is split between a persistent client-side store and a persistent server-side queue managed by PostgreSQL.
lib/recognition-store.ts)localStorage (yuheng_recognition_queue). This ensures that pending analysis tasks survive page reloads.useSyncExternalStore for reactive UI updates./api/nutrition/tasks/[id] endpoint to check for status updates from the server-side queue.lib/queue.ts)pgboss schema). This ensures tasks survive server restarts.instrumentation.ts on server boot, ensuring it starts automatically.queue_concurrency: Controls parallel processing (Default: 5).queue_retry_limit: Automatic retries on failure (Default: 3)./add or via Home page.POST /api/nutrition/recognize, which enqueues a job in pg-boss and returns a taskId.QueueManager worker picks up the job, calls the AI provider, and updates the task status in the recognition_tasks table.RecognitionStore polls for completion.A key refinement of the recognition system is the Guided Retry feature, which allows users to improve AI accuracy through natural language feedback.
if (userPrompt) {
promptText += `\n\nUSER ADDITIONAL INSTRUCTIONS: ${userPrompt}\nPlease prioritize these instructions while maintaining the overall output format.`;
}
recognition_tasks table)While images are stored on the client, the task metadata is tracked in PostgreSQL to support server-side asynchronous processing.
| Column | Type | Description |
|---|---|---|
id |
UUID | Unique task identifier |
status |
STRING | pending, processing, completed, failed |
result |
JSON | The recognized list of dishes |
error |
STRING | Error message if analysis failed |
created_at |
TIMESTAMP | Task creation time |
updated_at |
TIMESTAMP | Last status update |