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,36 @@
-- +goose Up
CREATE TABLE ingredient_mappings (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
canonical_name VARCHAR(255) NOT NULL,
canonical_name_ru VARCHAR(255),
spoonacular_id INTEGER UNIQUE,
aliases JSONB NOT NULL DEFAULT '[]'::jsonb,
category VARCHAR(50),
default_unit VARCHAR(20),
-- Nutrients per 100g
calories_per_100g DECIMAL(8, 2),
protein_per_100g DECIMAL(8, 2),
fat_per_100g DECIMAL(8, 2),
carbs_per_100g DECIMAL(8, 2),
fiber_per_100g DECIMAL(8, 2),
storage_days INTEGER,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_ingredient_mappings_aliases
ON ingredient_mappings USING GIN (aliases);
CREATE INDEX idx_ingredient_mappings_canonical_name
ON ingredient_mappings (canonical_name);
CREATE INDEX idx_ingredient_mappings_category
ON ingredient_mappings (category);
-- +goose Down
DROP TABLE IF EXISTS ingredient_mappings;

View File

@@ -0,0 +1,58 @@
-- +goose Up
CREATE TYPE recipe_source AS ENUM ('spoonacular', 'ai', 'user');
CREATE TYPE recipe_difficulty AS ENUM ('easy', 'medium', 'hard');
CREATE TABLE recipes (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
source recipe_source NOT NULL DEFAULT 'spoonacular',
spoonacular_id INTEGER UNIQUE,
title VARCHAR(500) NOT NULL,
description TEXT,
title_ru VARCHAR(500),
description_ru TEXT,
cuisine VARCHAR(100),
difficulty recipe_difficulty,
prep_time_min INTEGER,
cook_time_min INTEGER,
servings SMALLINT,
image_url TEXT,
calories_per_serving DECIMAL(8, 2),
protein_per_serving DECIMAL(8, 2),
fat_per_serving DECIMAL(8, 2),
carbs_per_serving DECIMAL(8, 2),
fiber_per_serving DECIMAL(8, 2),
ingredients JSONB NOT NULL DEFAULT '[]'::jsonb,
steps JSONB NOT NULL DEFAULT '[]'::jsonb,
tags JSONB NOT NULL DEFAULT '[]'::jsonb,
avg_rating DECIMAL(3, 2) NOT NULL DEFAULT 0.0,
review_count INTEGER NOT NULL DEFAULT 0,
created_by UUID REFERENCES users (id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_recipes_title_fts ON recipes
USING GIN (to_tsvector('simple',
coalesce(title_ru, '') || ' ' || coalesce(title, '')));
CREATE INDEX idx_recipes_ingredients ON recipes USING GIN (ingredients);
CREATE INDEX idx_recipes_tags ON recipes USING GIN (tags);
CREATE INDEX idx_recipes_cuisine ON recipes (cuisine);
CREATE INDEX idx_recipes_difficulty ON recipes (difficulty);
CREATE INDEX idx_recipes_prep_time ON recipes (prep_time_min);
CREATE INDEX idx_recipes_calories ON recipes (calories_per_serving);
CREATE INDEX idx_recipes_source ON recipes (source);
CREATE INDEX idx_recipes_rating ON recipes (avg_rating DESC);
-- +goose Down
DROP TABLE IF EXISTS recipes;
DROP TYPE IF EXISTS recipe_difficulty;
DROP TYPE IF EXISTS recipe_source;

View File

@@ -0,0 +1,25 @@
-- +goose Up
CREATE TABLE saved_recipes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title TEXT NOT NULL,
description TEXT,
cuisine TEXT,
difficulty TEXT,
prep_time_min INT,
cook_time_min INT,
servings INT,
image_url TEXT,
ingredients JSONB NOT NULL DEFAULT '[]',
steps JSONB NOT NULL DEFAULT '[]',
tags JSONB NOT NULL DEFAULT '[]',
nutrition JSONB,
source TEXT NOT NULL DEFAULT 'ai',
saved_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_saved_recipes_user_id ON saved_recipes(user_id);
CREATE INDEX idx_saved_recipes_saved_at ON saved_recipes(user_id, saved_at DESC);
-- +goose Down
DROP TABLE saved_recipes;