This desktop app tracks user nutrition and includes an AI-powered personalized diet recommendation system.
- JavaFX calorie tracker (existing flows preserved)
- SQLite persistence (
food_tracker.db) - ML microservice (
/ml-service, FastAPI) - Model training scripts (
/model) - Java integration layer to call ML service
- Backend endpoint:
GET /ai/recommendation/{userId} - AI panel in JavaFX UI with:
- Recommended daily calories
- Macro targets (protein/carbs/fats)
- User cluster type (
userType) - Meal suggestions
src/main/java/...Java app + controllers + DAO + UIml-service/FastAPI service for prediction + clustering + retrainingmodel/training scripts + model artifacts:calorie_model.pkl(regression)clustering_model.pkl(KMeans)
- Model: custom linear regression (
model/train_calorie_model.py) - Input: age, weight, height, goal, activity level
- Output: recommended daily calories
- Fat loss: high protein, moderate carbs, lower fat
- Maintenance: balanced split
- Muscle gain: high protein + higher carbs
- Features:
- average daily calories
- average protein intake
- average carbs
- average fats
- Cluster labels:
high proteinhigh carbbalanced
- Python endpoint:
POST /ml/retrain - Java helper endpoint:
POST /ai/retrain(optional trigger from active users)
- Java 17+
- Maven wrapper (
mvnw.cmd) - Python 3.10+
cd java-calorie-tracker-app
python model/train_calorie_model.pyCreates:
model/calorie_model.pklmodel/clustering_model.pkl
cd java-calorie-tracker-app
pip install -r ml-service/requirements.txt
python ml-service/run_server.pyHealth check: http://127.0.0.1:8000/ml/health
cd java-calorie-tracker-app
.\mvnw.cmd javafx:runIf you want to call GET /ai/recommendation/{userId} directly:
cd java-calorie-tracker-app
.\mvnw.cmd spring-boot:runDefault API base: http://localhost:8080
GET /ai/recommendation/{userId}POST /ai/feedback
Example response:
{
"recommendedCalories": 2280,
"protein": 140,
"carbs": 250,
"fats": 70,
"userType": "high carb",
"explanation": "Suggested daily calories: 2280. This estimate is based on your muscle gain goal and activity level (active). In the model, higher body weight pushed calories upward, age had a small effect, and muscle gain goal generally increases target calories in this prediction.",
"mealSuggestions": [
"Keep consistency: include Chicken Breast in one meal today.",
"Add Chicken Breast (protein-focused option)",
"Add White Rice (carb-support option)"
]
}POST /ml/recommendationPOST /ml/retrain
Feedback payload example:
{
"userId": 1,
"followedRecommendation": true,
"currentWeight": 72.4,
"recommendedCalories": 2200,
"recommendedProtein": 145,
"recommendedCarbs": 240,
"recommendedFats": 65
}- Goal values used by ML:
fat_loss,maintenance,muscle_gain - ML service base URL defaults to
http://127.0.0.1:8000- Override with env var:
ML_SERVICE_BASE_URL - Or JVM property:
-Dml.service.base-url=http://host:port
- Override with env var: