ai cooking
Data Object Flow#
This document describes the lifecycle of generation data in internal/recipes, from query args to regeneration.
1) params is created from query args (generation starts here)#
Entry point:
GET /recipes?location=...withouthquery arg- Handler:
internal/recipes/server.gohandleRecipes
Flow:
handleRecipescallsParseQueryArgs(...).ParseQueryArgs(internal/recipes/params.go) buildsgeneratorParamsfrom URL query args:location(required)date(optional, defaulted by store timezone/day boundary)instructions(optional)response_id(optional)
handleRecipespersists that object withSaveParams(...)underparams/<params_hash>.- This saved
paramsobject is the start signal for generation.kickgeneration(...)is launched immediately after.
2) shoppingList + recipes are generated from params#
Async generation path:
kickgeneration(...)callsgenerator.GenerateRecipes(ctx, params).- The generator returns an
ai.ShoppingListcontainingRecipes(andResponseID). SaveShoppingList(...)persists:shoppinglist/<params_hash>-> fullai.ShoppingListrecipe/<recipe_hash>-> each recipe object (withOriginHash = params_hash)
At this point, /recipes?h=<params_hash> can render the generated list.
3) Optional selection state is created to hold user choices#
After the list exists, a signed-in user can save/dismiss recipes:
POST /recipe/{hash}/savePOST /recipe/{hash}/dismiss
Both handlers (handleSaveRecipe, handleDismissRecipe) update recipeSelection (internal/recipes/selection.go):
SavedHashes []stringDismissedHashes []stringUpdatedAt time.Time
Storage key:
recipe_selection/<user_id>/<origin_hash>
This object is optional and exists only when the user starts interacting with save/dismiss actions.
4) Regeneration creates a new params from old params + selection#
Regeneration entry:
POST /recipes/{hash}/regenerate- Handler:
handleRegenerate
handleRegenerate calls paramsForAction(...), which:
- Loads old
paramsfromparams/<hash>. - Loads current
shoppingListfromshoppinglist/<hash>. - Loads
recipeSelectionfor(user_id, hash). - Merges selection state into params (
mergeParamsWithSelection), applies new instructions, and carries the latest response id when needed. - Computes a new hash from the updated params.
Then:
- New params is saved at
params/<new_hash>. kickgeneration(...)runs again with that new params.
Result:
selectionholds transient decision state for a given origin hash.- A new generation cycle begins when a new
paramsobject is created and saved. - Recipe follow-up questions are chained by the latest
response_idstored on the recipe thread; each answer updates that thread-level response id for the next turn.