Skip to content

Repository files navigation

Recipe Management Shared Models

This repository contains shared models and types used across the Recipe Management platform services.

Overview

The shared models provide a consistent interface for recipe data exchange between:

  • Frontend (React/TypeScript)
  • AI Service (Spring Boot/Java)
  • Storage Service (Spring Boot/Java)

Models

Recipe Model

The core Recipe model includes all recipe-related fields with consistent naming and types across services.

Key Fields

  • recipeName: Recipe title (consistent naming)
  • ingredients: List of ingredient strings with quantities
  • instructions: Step-by-step cooking instructions
  • servings: Number of servings
  • nutritionalInfo: Structured nutritional data
  • tips: Recipe tips and additional information
  • source: Origin of recipe ("ai-generated", "manual", etc.)

Timing Fields

  • prepTimeMinutes / cookTimeMinutes: Integer minutes
  • prepTime / cookTime: Human-readable strings (e.g., "15 minutes")
  • totalTimeMinutes: Calculated total time

Response DTOs

In addition to core persistence models, shared response DTOs are available for service API boundaries in both TypeScript and Java:

  • RecipeResponse: Enriched API response payload containing the core recipe fields plus author metadata (authorDisplayName, authorAvatarUrl, author) and social interaction state (likeCount, isLikedByCurrentUser, isSavedByCurrentUser).
  • AuthorDto: Author profile information (uid, displayName, avatarUrl).
  • PagedRecipeResponse: Standard paginated wrapper containing recipes, size, totalCount, and nextPageToken.

Title & RecipeName Alias Policy

To support backward compatibility across services:

  • Core Recipe entities standardize on recipeName.
  • RecipeResponse emits both recipeName and title (or supports payloads specifying either key), allowing existing consumers expecting title and updated consumers expecting recipeName to consume responses without breaking.

Usage

TypeScript (Frontend)

import { Recipe, RecipeResponse, PagedRecipeResponse, AuthorDto, NutritionalInfo, RecipeTips } from '@recipe-management/shared';

// Use the shared types
const recipe: Recipe = {
  recipeName: "Spaghetti Carbonara",
  ingredients: ["400g spaghetti", "200g pancetta"],
  instructions: ["Boil pasta", "Fry pancetta"],
  servings: 4,
  source: "manual"
};

Java (Backend Services)

import com.recipe.shared.model.Recipe;
import com.recipe.shared.model.RecipeResponse;
import com.recipe.shared.model.PagedRecipeResponse;
import com.recipe.shared.model.AuthorDto;
import com.recipe.shared.model.NutritionalInfo;

// Use the shared models
Recipe recipe = Recipe.builder()
    .recipeName("Spaghetti Carbonara")
    .ingredients(Arrays.asList("400g spaghetti", "200g pancetta"))
    .instructions(Arrays.asList("Boil pasta", "Fry pancetta"))
    .servings(4)
    .source("manual")
    .build();

Migration Guide

From Existing Models

Frontend Changes

Replace the existing Recipe interface in src/types/nutrition.ts with:

import { Recipe, RecipeResponse } from '@recipe-management/shared';

AI Service Changes

Replace RecipeDTO with the shared Recipe model. Key mapping:

  • recipeName → recipeName (already consistent)
  • estimatedTimeMinutes → totalTimeMinutes
  • estimatedTime → totalTime

Storage Service Changes

Replace the existing Recipe entity with the shared model. Key mapping:

  • title → recipeName in core persistence (Recipe)
  • API endpoints returning RecipeResponse provide both recipeName and title aliases for backward compatibility.
  • nutrition (Map) → nutritionalInfo (NutritionalInfo)
  • tips (Map) → tips (RecipeTips)

Building

TypeScript

npm run build:ts

Java

mvn compile

Both

npm run build  # Builds both TypeScript and Java

Publishing

# Publish TypeScript package to npm
npm publish

# Publish Java package to Maven repository
mvn deploy

Compatibility

The shared models are designed to be backward compatible where possible, with utility methods for data conversion between old and new formats.

Contributing

When adding new fields to the Recipe model:

  1. Update both TypeScript and Java versions
  2. Ensure backward compatibility
  3. Update this README
  4. Add conversion utilities if needed# Test commit

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages