A local nutrition tracking app powered by AI
YuHeng features a decoupled prompt management system that keeps AI instructions separate from the application logic. This allows for easier iteration on AI behavior without changing code.
The system is centered around the PromptManager class in lib/prompts.ts:
.txt files in the prompts/ directory at the project root.promptManager is a singleton instance used throughout the backend API.A typical prompt file (e.g., prompts/dish-init-prompt.txt) contains base instructions and placeholders for runtime data:
You are a professional nutritionist.
Please analyze this food photo in .
Return the results in ...
When the code requests a prompt, it passes a variables object:
const prompt = await promptManager.getPrompt('dish-init-prompt', {
language: 'English',
unit: 'kcal'
});
The PromptManager reads the file and replaces all occurrences of and with the provided values.