feat: implement Iteration 1 — AI recipe recommendations

Backend:
- Add Groq LLM client (llama-3.3-70b) for recipe generation with JSON
  retry strategy (retries only on parse errors, not API errors)
- Add Pexels client for parallel photo search per recipe
- Add saved_recipes table (migration 004) with JSONB fields
- Add GET /recommendations endpoint (profile-aware prompt building)
- Add POST/GET/GET{id}/DELETE /saved-recipes CRUD endpoints
- Wire gemini, pexels, recommendation, savedrecipe packages in main.go

Flutter:
- Add Recipe, SavedRecipe models with json_serializable
- Add RecipeService (getRecommendations, getSavedRecipes, save, delete)
- Add RecommendationsNotifier and SavedRecipesNotifier (Riverpod)
- Add RecommendationsScreen with skeleton loading and refresh FAB
- Add RecipeDetailScreen (SliverAppBar, nutrition tooltip, steps with timer)
- Add SavedRecipesScreen with Dismissible swipe-to-delete and empty state
- Update RecipesScreen to TabBar (Recommendations / Saved)
- Add /recipe-detail route outside ShellRoute (no bottom nav)
- Extend ApiClient with getList() and deleteVoid()

Project:
- Add CLAUDE.md with English-only rule for comments and commit messages

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-02-21 22:43:29 +02:00
parent 24219b611e
commit e57ff8e06c
41 changed files with 5994 additions and 353 deletions

View File

@@ -0,0 +1,121 @@
import 'package:json_annotation/json_annotation.dart';
part 'recipe.g.dart';
@JsonSerializable(explicitToJson: true)
class Recipe {
final String title;
final String description;
final String cuisine;
final String difficulty;
@JsonKey(name: 'prep_time_min')
final int prepTimeMin;
@JsonKey(name: 'cook_time_min')
final int cookTimeMin;
final int servings;
@JsonKey(name: 'image_url', defaultValue: '')
final String imageUrl;
@JsonKey(name: 'image_query', defaultValue: '')
final String imageQuery;
@JsonKey(defaultValue: [])
final List<RecipeIngredient> ingredients;
@JsonKey(defaultValue: [])
final List<RecipeStep> steps;
@JsonKey(defaultValue: [])
final List<String> tags;
@JsonKey(name: 'nutrition_per_serving')
final NutritionInfo? nutrition;
const Recipe({
required this.title,
required this.description,
required this.cuisine,
required this.difficulty,
required this.prepTimeMin,
required this.cookTimeMin,
required this.servings,
this.imageUrl = '',
this.imageQuery = '',
this.ingredients = const [],
this.steps = const [],
this.tags = const [],
this.nutrition,
});
factory Recipe.fromJson(Map<String, dynamic> json) => _$RecipeFromJson(json);
Map<String, dynamic> toJson() => _$RecipeToJson(this);
}
@JsonSerializable()
class RecipeIngredient {
final String name;
final double amount;
final String unit;
const RecipeIngredient({
required this.name,
required this.amount,
required this.unit,
});
factory RecipeIngredient.fromJson(Map<String, dynamic> json) =>
_$RecipeIngredientFromJson(json);
Map<String, dynamic> toJson() => _$RecipeIngredientToJson(this);
}
@JsonSerializable()
class RecipeStep {
final int number;
final String description;
@JsonKey(name: 'timer_seconds')
final int? timerSeconds;
const RecipeStep({
required this.number,
required this.description,
this.timerSeconds,
});
factory RecipeStep.fromJson(Map<String, dynamic> json) =>
_$RecipeStepFromJson(json);
Map<String, dynamic> toJson() => _$RecipeStepToJson(this);
}
@JsonSerializable()
class NutritionInfo {
final double calories;
@JsonKey(name: 'protein_g')
final double proteinG;
@JsonKey(name: 'fat_g')
final double fatG;
@JsonKey(name: 'carbs_g')
final double carbsG;
@JsonKey(defaultValue: true)
final bool approximate;
const NutritionInfo({
required this.calories,
required this.proteinG,
required this.fatG,
required this.carbsG,
this.approximate = true,
});
factory NutritionInfo.fromJson(Map<String, dynamic> json) =>
_$NutritionInfoFromJson(json);
Map<String, dynamic> toJson() => _$NutritionInfoToJson(this);
}

View File

@@ -0,0 +1,97 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'recipe.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
Recipe _$RecipeFromJson(Map<String, dynamic> json) => Recipe(
title: json['title'] as String,
description: json['description'] as String,
cuisine: json['cuisine'] as String,
difficulty: json['difficulty'] as String,
prepTimeMin: (json['prep_time_min'] as num).toInt(),
cookTimeMin: (json['cook_time_min'] as num).toInt(),
servings: (json['servings'] as num).toInt(),
imageUrl: json['image_url'] as String? ?? '',
imageQuery: json['image_query'] as String? ?? '',
ingredients:
(json['ingredients'] as List<dynamic>?)
?.map((e) => RecipeIngredient.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
steps:
(json['steps'] as List<dynamic>?)
?.map((e) => RecipeStep.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
tags:
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList() ?? [],
nutrition: json['nutrition_per_serving'] == null
? null
: NutritionInfo.fromJson(
json['nutrition_per_serving'] as Map<String, dynamic>,
),
);
Map<String, dynamic> _$RecipeToJson(Recipe instance) => <String, dynamic>{
'title': instance.title,
'description': instance.description,
'cuisine': instance.cuisine,
'difficulty': instance.difficulty,
'prep_time_min': instance.prepTimeMin,
'cook_time_min': instance.cookTimeMin,
'servings': instance.servings,
'image_url': instance.imageUrl,
'image_query': instance.imageQuery,
'ingredients': instance.ingredients.map((e) => e.toJson()).toList(),
'steps': instance.steps.map((e) => e.toJson()).toList(),
'tags': instance.tags,
'nutrition_per_serving': instance.nutrition?.toJson(),
};
RecipeIngredient _$RecipeIngredientFromJson(Map<String, dynamic> json) =>
RecipeIngredient(
name: json['name'] as String,
amount: (json['amount'] as num).toDouble(),
unit: json['unit'] as String,
);
Map<String, dynamic> _$RecipeIngredientToJson(RecipeIngredient instance) =>
<String, dynamic>{
'name': instance.name,
'amount': instance.amount,
'unit': instance.unit,
};
RecipeStep _$RecipeStepFromJson(Map<String, dynamic> json) => RecipeStep(
number: (json['number'] as num).toInt(),
description: json['description'] as String,
timerSeconds: (json['timer_seconds'] as num?)?.toInt(),
);
Map<String, dynamic> _$RecipeStepToJson(RecipeStep instance) =>
<String, dynamic>{
'number': instance.number,
'description': instance.description,
'timer_seconds': instance.timerSeconds,
};
NutritionInfo _$NutritionInfoFromJson(Map<String, dynamic> json) =>
NutritionInfo(
calories: (json['calories'] as num).toDouble(),
proteinG: (json['protein_g'] as num).toDouble(),
fatG: (json['fat_g'] as num).toDouble(),
carbsG: (json['carbs_g'] as num).toDouble(),
approximate: json['approximate'] as bool? ?? true,
);
Map<String, dynamic> _$NutritionInfoToJson(NutritionInfo instance) =>
<String, dynamic>{
'calories': instance.calories,
'protein_g': instance.proteinG,
'fat_g': instance.fatG,
'carbs_g': instance.carbsG,
'approximate': instance.approximate,
};

View File

@@ -0,0 +1,64 @@
import 'package:json_annotation/json_annotation.dart';
import 'recipe.dart';
part 'saved_recipe.g.dart';
@JsonSerializable(explicitToJson: true)
class SavedRecipe {
final String id;
final String title;
final String? description;
final String? cuisine;
final String? difficulty;
@JsonKey(name: 'prep_time_min')
final int? prepTimeMin;
@JsonKey(name: 'cook_time_min')
final int? cookTimeMin;
final int? servings;
@JsonKey(name: 'image_url')
final String? imageUrl;
@JsonKey(defaultValue: [])
final List<RecipeIngredient> ingredients;
@JsonKey(defaultValue: [])
final List<RecipeStep> steps;
@JsonKey(defaultValue: [])
final List<String> tags;
@JsonKey(name: 'nutrition_per_serving')
final NutritionInfo? nutrition;
final String source;
@JsonKey(name: 'saved_at')
final DateTime savedAt;
const SavedRecipe({
required this.id,
required this.title,
this.description,
this.cuisine,
this.difficulty,
this.prepTimeMin,
this.cookTimeMin,
this.servings,
this.imageUrl,
this.ingredients = const [],
this.steps = const [],
this.tags = const [],
this.nutrition,
required this.source,
required this.savedAt,
});
factory SavedRecipe.fromJson(Map<String, dynamic> json) =>
_$SavedRecipeFromJson(json);
Map<String, dynamic> toJson() => _$SavedRecipeToJson(this);
}

View File

@@ -0,0 +1,57 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'saved_recipe.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
SavedRecipe _$SavedRecipeFromJson(Map<String, dynamic> json) => SavedRecipe(
id: json['id'] as String,
title: json['title'] as String,
description: json['description'] as String?,
cuisine: json['cuisine'] as String?,
difficulty: json['difficulty'] as String?,
prepTimeMin: (json['prep_time_min'] as num?)?.toInt(),
cookTimeMin: (json['cook_time_min'] as num?)?.toInt(),
servings: (json['servings'] as num?)?.toInt(),
imageUrl: json['image_url'] as String?,
ingredients:
(json['ingredients'] as List<dynamic>?)
?.map((e) => RecipeIngredient.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
steps:
(json['steps'] as List<dynamic>?)
?.map((e) => RecipeStep.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
tags:
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList() ?? [],
nutrition: json['nutrition_per_serving'] == null
? null
: NutritionInfo.fromJson(
json['nutrition_per_serving'] as Map<String, dynamic>,
),
source: json['source'] as String,
savedAt: DateTime.parse(json['saved_at'] as String),
);
Map<String, dynamic> _$SavedRecipeToJson(SavedRecipe instance) =>
<String, dynamic>{
'id': instance.id,
'title': instance.title,
'description': instance.description,
'cuisine': instance.cuisine,
'difficulty': instance.difficulty,
'prep_time_min': instance.prepTimeMin,
'cook_time_min': instance.cookTimeMin,
'servings': instance.servings,
'image_url': instance.imageUrl,
'ingredients': instance.ingredients.map((e) => e.toJson()).toList(),
'steps': instance.steps.map((e) => e.toJson()).toList(),
'tags': instance.tags,
'nutrition_per_serving': instance.nutrition?.toJson(),
'source': instance.source,
'saved_at': instance.savedAt.toIso8601String(),
};