Skip to content

nondescript74/Reczipes3

Repository files navigation

Reczipes

AI-powered recipe extraction for iOS.

Reczipes converts photos of recipes into structured, searchable data using Apple Vision OCR and LLM reasoning.

Key capabilities

β€’ OCR extraction using Apple Vision
β€’ LLM-assisted interpretation of recipe structure
β€’ Allergen and FODMAP dietary analysis
β€’ Structured recipe data for storage and retrieval
β€’ Modern SwiftUI architecture with CloudKit synchronization

Architecture

Pipeline:

Image β†’ OCR extraction β†’ LLM interpretation β†’ structured recipe model β†’ user interface

Technologies:

  • Swift / SwiftUI
  • Apple Vision
  • Claude API
  • CloudKit

Transform recipe card photos into structured, digital recipes using Claude's vision AI.

Built with SwiftUI for iOS 17+ | Uses Claude Sonnet 4 | Integrates with your existing RecipeModel


🎯 What This Does

Take a photo of any recipe card, cookbook page, or handwritten recipe, and instantly get:

  • βœ… Structured recipe data matching your existing RecipeModel
  • βœ… Multiple ingredient sections (e.g., "For the dough", "For the filling")
  • βœ… Multiple instruction sections with proper numbering
  • βœ… Metric conversions when available
  • βœ… Recipe notes, tips, warnings, and timing
  • βœ… Yield and serving information
  • βœ… Source references and page numbers

Before & After

Input: Photo of a recipe card
Output: Complete RecipeModel with all sections properly parsed

πŸ“¦ What You Get

Core Files (Production)

  1. ImagePreprocessor.swift (3.9 KB) - Image enhancement for OCR
  2. ClaudeAPIClient.swift (11 KB) - Claude API integration
  3. RecipeExtractorViewModel.swift (2.3 KB) - State management
  4. RecipeExtractorView.swift (11 KB) - Main user interface
  5. RecipeDetailView.swift (12 KB) - Recipe display with formatting
  6. ImagePicker.swift (1.5 KB) - Camera/photo library helper
  7. RecipeExtractorConfig.swift (6.4 KB) - Configuration & security

Documentation & Examples

  1. ExampleAppIntegration.swift (13 KB) - Complete integration example
  2. RecipeExtractorTests.swift (16 KB) - Testing utilities
  3. QUICK_START.md - 5-minute setup guide
  4. IMPLEMENTATION_GUIDE.md - Detailed implementation
  5. ARCHITECTURE.md - System design documentation

Total: 94.4 KB of production-ready code + comprehensive docs

πŸš€ Quick Start

1. Requirements

  • iOS 17.0+
  • Xcode 15.0+
  • Claude API key (Get one here)
  • Your existing RecipeModel.swift

2. Installation (2 minutes)

# Add all .swift files to your Xcode project
# Drag them into your project navigator

3. Configuration (2 minutes)

Update Info.plist:

<key>NSCameraUsageDescription</key>
<string>Take photos of recipe cards</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Select recipe images from your library</string>

Set up API key (choose one method):

// Method 1: Keychain (Recommended)
KeychainManager.shared.save(key: "claudeAPIKey", value: "sk-ant-api03-...")

// Method 2: Environment Variable (Development)
// Xcode β†’ Edit Scheme β†’ Run β†’ Environment Variables
// Add: CLAUDE_API_KEY = sk-ant-api03-...

4. Integration (1 minute)

import SwiftUI

@main
struct YourApp: App {
    var body: some Scene {
        WindowGroup {
            TabView {
                RecipeListView()
                    .tabItem { Label("Recipes", systemImage: "book.fill") }
                
                if let apiKey = APIKeyHelper.getAPIKey() {
                    RecipeExtractorView(apiKey: apiKey)
                        .tabItem { Label("Extract", systemImage: "camera.fill") }
                }
            }
        }
    }
}

That's it! You now have Claude-powered recipe extraction.

πŸ“± How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Take Photo  │────▢│ Preprocess   │────▢│ Send to     │────▢│ Get Recipe   β”‚
β”‚ or Select   β”‚     β”‚ (enhance)    β”‚     β”‚ Claude API  β”‚     β”‚ Data         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Image Preprocessing (Automatic)

Your old, faded recipe cards get enhanced:

  • Grayscale conversion - Reduces color noise
  • Contrast boost (+50%) - Makes text pop
  • Sharpening - Clearer character recognition
  • Noise reduction - Cleans up artifacts

Users can toggle preprocessing on/off and compare before/after.

Claude Integration

The system sends your image to Claude with detailed instructions to:

  1. Extract all text from the image
  2. Identify ingredient sections
  3. Parse measurements and units
  4. Recognize instruction steps
  5. Capture notes and variations
  6. Output structured JSON matching your RecipeModel

Your Recipe Model

The extracted data perfectly matches your existing structure:

RecipeModel(
    title: "Chocolate Chip Cookies",
    yield: "24 cookies",
    ingredientSections: [...],  // Multiple sections supported
    instructionSections: [...], // Numbered steps
    notes: [...]                // Tips, warnings, timing
)

πŸ’° Cost

~$0.02 per recipe extraction

Based on Claude Sonnet 4 pricing:

  • Input: ~2,000 tokens ($0.006)
  • Output: ~1,000 tokens ($0.015)
  • Total: ~$0.021 per recipe

Extract 100 recipes for ~$2.

✨ Features

For Users

  • πŸ“Έ Camera & Photo Library support
  • 🎨 Image Enhancement toggle with preview
  • ⚑ Fast extraction (15-30 seconds)
  • βœ… Comprehensive parsing of complex recipes
  • πŸ”„ Error recovery with retry options
  • πŸ“€ Share functionality for extracted recipes

For Developers

  • πŸ—οΈ MVVM architecture with proper separation
  • πŸ§ͺ Comprehensive test suite included
  • πŸ”’ Secure API key management (Keychain + Environment)
  • πŸ“Š Detailed error handling with specific types
  • βš™οΈ Highly configurable (preprocessing levels, timeouts, etc.)
  • πŸ“ Well-documented with inline comments

Technical Highlights

  • SwiftUI-native with @Published properties
  • Async/await for modern concurrency
  • Core Image for GPU-accelerated preprocessing
  • Proper memory management
  • No external dependencies (except Claude API)

🎨 Customization

Adjust Preprocessing Intensity

// In RecipeExtractorConfig.swift
static let contrastLevel: Float = 1.8  // Default: 1.5
static let sharpnessLevel: Float = 0.9  // Default: 0.7

Modify Extraction Prompt

// In ClaudeAPIClient.swift
let systemPrompt = """
You are an expert at extracting recipes...
[Add your custom instructions here]
"""

Change UI Appearance

All views are standard SwiftUI - modify colors, layouts, and styling as needed.

πŸ”’ Security

API Key Protection

  • βœ… Never hardcoded in source files
  • βœ… Keychain storage with iOS encryption
  • βœ… Environment variables for development
  • βœ… Not in version control (.gitignore patterns)
  • βœ… Centralized access through APIKeyHelper

Best Practices Included

  • Secure credential storage
  • Rate limiting considerations
  • Error message sanitization
  • Debug mode controls

πŸ“Š Performance

Benchmarks

  • Image preprocessing: < 2 seconds
  • API request: 10-30 seconds (network dependent)
  • UI updates: Instant (reactive)
  • Memory usage: ~20-35 MB peak

Optimization Tips

  • Enable preprocessing for old recipe cards
  • Disable preprocessing for high-quality digital images
  • Use lightweight preprocessing for color preservation
  • Implement caching for frequently accessed recipes

πŸ§ͺ Testing

Included Test Suite

// Unit Tests
- ImagePreprocessor functionality
- RecipeModel parsing
- Keychain operations

// Integration Tests  
- API client request/response
- ViewModel state management

// Manual Testing Guide
- Checklist for all features
- Edge case scenarios
- Performance validation

Test Your Integration

// Use provided test image generator
let testImage = TestImageGenerator.generateTestRecipeImage()

// Or use sample recipes
let sampleRecipe = RecipeModel.sampleRecipe

πŸ“š Documentation

Document Purpose
QUICK_START.md 5-minute setup guide
IMPLEMENTATION_GUIDE.md Detailed integration steps
ARCHITECTURE.md System design and patterns
ExampleAppIntegration.swift Complete working example
RecipeExtractorTests.swift Testing utilities

πŸ†˜ Troubleshooting

Common Issues

"No recipe could be extracted"

  • βœ… Enable image preprocessing
  • βœ… Ensure text is legible in photo
  • βœ… Try better lighting/focus

"API Error (401)"

  • βœ… Check API key is correct
  • βœ… Verify key starts with sk-ant-
  • βœ… Confirm key is properly stored

"API Error (429)"

  • βœ… Rate limit reached
  • βœ… Wait a moment and retry
  • βœ… Implement request throttling

Preprocessing makes image worse

  • βœ… Use lightweight mode
  • βœ… Disable for high-quality photos
  • βœ… Adjust contrast/sharpness values

πŸš€ What's Next?

Extend the functionality:

  1. Core Data Integration - Persist extracted recipes
  2. Recipe Editing - Allow users to correct extractions
  3. Batch Processing - Extract multiple recipes at once
  4. Nutrition Info - Add nutritional data extraction
  5. Recipe Search - Full-text search across extracted recipes
  6. Collections - Organize recipes into cookbooks
  7. Export Options - PDF, plain text, JSON

πŸ“„ License

This implementation is provided as-is for use in your iOS applications.

πŸ™ Acknowledgments

  • Built with Claude Sonnet 4 by Anthropic
  • Uses Core Image for preprocessing
  • SwiftUI for modern iOS UI
  • Compatible with your existing RecipeModel architecture

Need Help?

  1. Check QUICK_START.md for setup issues
  2. Review IMPLEMENTATION_GUIDE.md for integration questions
  3. See ARCHITECTURE.md for design decisions
  4. Test with RecipeExtractorTests.swift
  5. Reference ExampleAppIntegration.swift for patterns

Get Your API Key

Visit console.anthropic.com to:

  1. Create an Anthropic account
  2. Generate an API key
  3. Add credits to your account

Ready to digitize your recipe collection? 🍳

Start with the Quick Start Guide β†’

Built with ❀️ using Claude Sonnet 4

About

AI-powered recipe extraction using Apple Vision OCR and LLM reasoning. Converts photos of recipes into structured data with allergen and FODMAP analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors