A .NET Web API that leverages Google Gemini to estimate the nutritional composition of dishes from photographs. Backend for the CalorieAI Mobile Client.
- Visual Food Recognition — analyzes images to identify ingredients and portion sizes
- Nutritional Estimation — calculates calories, proteins, fats, and carbohydrates per ingredient
- Context-Aware — supports user notes (e.g., "hidden sauce", "extra cheese") to refine accuracy
- OpenAPI Support — fully documented with Swagger UI
| Framework | ASP.NET Core Minimal API (.NET 10) |
| AI Model | Google Gemini 2.0 Flash |
| Error Handling | Global IExceptionHandler + ProblemDetails (RFC 9457) |
| Configuration | Options pattern with startup validation |
| Testing | xUnit + NSubstitute + WebApplicationFactory |
git clone https://github.com/dgluhotorenko/CalorieEstimatorApi.git
cd CalorieEstimatorApiConfigure your API key using User Secrets (keys stay local, never in git):
dotnet user-secrets set "ApiKeys:Google" "YOUR_API_KEY"Run with the http launch profile (the mobile client expects the API on http://localhost:5064):
dotnet run --launch-profile httpOpen Swagger UI at http://localhost:5064/swagger.
To expose the API to a physical device without deployment, use Dev Tunnels:
winget install Microsoft.DevTunnels
devtunnel user login
devtunnel host -p 5064 --allow-anonymousUse the generated HTTPS URL in your mobile client configuration.
Accepts multipart/form-data:
| Field | Type | Required | Description |
|---|---|---|---|
image |
file | yes | Photo of the dish (max 5 MB) |
notes |
string | no | Additional context for the AI |
Returns a JSON FoodAnalysisResult with dish name, total calories, confidence score, and per-ingredient breakdown (weight, calories, protein, fat, carbs).
cd CalorieApi.Tests
dotnet test