Technical Overview

WeeknightChef is a proof-of-concept iOS application. This page provides a high-level overview of the technical implementation, including the technology stack, architecture, and API integrations.

Technology Stack

Technologies used in the application.

Frontend

SwiftUI (iOS 16+)
Native iOS UI framework with declarative syntax. MVVM architecture with ObservableObject for state management.

Backend

Supabase
Backend-as-a-Service providing PostgreSQL database, authentication, storage, and serverless edge functions.

Database

PostgreSQL
Robust relational database with Row Level Security (RLS) policies for data isolation and security.

AI Integration

OpenAI GPT-4o-mini
Large language model for recipe generation and modification. Structured JSON output with prompt engineering.

Image Generation

Replicate Flux
AI image generation for food photography. Cost-effective alternative to DALL-E with consistent aesthetic.

Nutrition API

USDA FoodData Central
Free government API for comprehensive nutrition information. Integrated for recipe nutritional analysis.

Concurrency

async/await
Modern Swift concurrency for asynchronous operations. URLSession for network requests with proper error handling.

Serverless

Supabase Edge Functions
TypeScript-based serverless functions for API orchestration. Handles AI API calls and business logic server-side.

Architecture Overview

Application architecture using MVVM pattern with separation between Views, ViewModels, and Services.

WeeknightChef application architecture diagram

Architectural Decisions

MVVM Pattern: Separation between UI (Views), business logic (ViewModels), and data access (Services).

Serverless Edge Functions: AI API calls and sensitive operations handled server-side. API keys stored server-side. Cost optimization and rate limiting implemented in Edge Functions.

Offline-First Design: Guest mode uses local persistence (UserDefaults). Data migrates to cloud storage upon authentication. App functions without network connectivity.

API Integrations

Third-party APIs integrated into the application.

OpenAI GPT-4o-mini - Recipe Generation

Purpose: Generate personalized recipes from minimal user input (protein type + dietary preferences)
Implementation: Server-side Edge Function with structured prompt engineering. Returns JSON-formatted recipes with ingredients, steps, and metadata.
Features: Recipe modification ("make it spicier"), reroll functionality, context-aware generation based on user preferences.
Cost Optimization: Uses GPT-4o-mini (10x cheaper than GPT-4) with efficient prompt design to minimize token usage.

Replicate Flux - Image Generation

Purpose: Generate appetizing food photography for recipes
Implementation: Two-step AI pipeline: GPT-4o-mini distills recipe into visual description, then Flux generates image from description.
Features: Consistent aesthetic, image caching and deduplication, Supabase Storage integration for hosting.
Cost Optimization: Flux Schnell model at $0.003/image (6x cheaper than DALL-E). Images cached to avoid regeneration.

USDA FoodData Central - Nutrition Data

Purpose: Provide accurate nutritional information for recipes
Implementation: Free government API with 1,000 requests/hour limit. Ingredient-based nutrition calculation.
Features: Comprehensive nutrition data (calories, macros, vitamins, minerals), ingredient matching with fuzzy logic.
Cost: Completely free - no API costs for nutrition data.

Supabase - Backend Services

Purpose: Complete backend infrastructure (database, auth, storage, serverless functions)
Implementation: PostgreSQL with Row Level Security, Supabase Auth for user management, Storage for images, Edge Functions for serverless logic.
Features: Real-time subscriptions, automatic API generation, built-in security policies, scalable infrastructure.
Architecture: All sensitive operations (API keys, business logic) handled in Edge Functions, not client-side.

Feature Implementation

Implementation details for key features.

AI Recipe Generation Workflow

  1. User selects protein type and dietary preferences
  2. iOS app sends request to Supabase Edge Function
  3. Edge Function constructs optimized prompt for OpenAI
  4. GPT-4o-mini generates structured recipe JSON
  5. Edge Function enriches with USDA nutrition data
  6. Recipe returned to app and displayed with loading states
  7. User can modify, reroll, or save recipe

Offline-First Guest Mode

Guest users can use the app without authentication. All data stored locally using UserDefaults. When user signs up or signs in, guest data migrates to cloud storage.

Smart Week Filling

Algorithm fills empty days in meal plan with system recipes based on user-selected style (Balanced Mix, Chicken Lover, Vegetarian, Quick Meals). Uses random selection for variety while respecting dietary constraints. Uses pre-populated database of 375 recipes.

Grocery List with Offline Sync

Batched sync queue for grocery list mutations. Changes apply instantly locally, then sync to server when network available. Debounced flush prevents excessive API calls. Category organization with per-user overrides and hierarchical categorization fallback (user → global → heuristics).

Development Workflow & Project Planning

Development phases and project organization.

Phase 1

Foundation
Project setup, database schema, service architecture, authentication

Phase 2

Recipe Generation
AI integration, Edge Functions, recipe UI, nutrition data

Phase 3

Authentication
User accounts, guest mode, data migration, cookbook

Phase 4

Meal Planning
Weekly calendar, drag-and-drop, multi-week navigation

Phase 5

Image Generation
AI image pipeline, caching, storage integration

Phase 6

System Recipes
375 pre-populated recipes, database seeding, instant access

Phase 7

Smart Features
Week filling, grocery lists, preferences

Phase 8

Polish
UX enhancements, error handling, offline support

Project Management Approach

Documentation: Planning documents, status tracking, and implementation guides maintained throughout development.

Development Process: Phased approach with milestones. Each phase builds on previous work with validation checkpoints.

Cost Management: Use of free tiers (USDA API, Supabase free tier) and cost-optimized AI models (GPT-4o-mini, Flux Schnell).

Security: API keys stored server-side, Row Level Security policies, encrypted data transmission, secure authentication.

Implementation Details

Technical implementation details.

  • Multi-API Integration: Integration of 4 APIs (OpenAI, Replicate, USDA, Supabase) with error handling and fallbacks
  • Cost Optimization: Uses GPT-4o-mini model and caching strategies to reduce AI costs
  • Offline-First Architecture: Full functionality without network, sync when connectivity restored
  • Data Migration: Guest-to-authenticated user data migration
  • Security: Server-side API key management, Row Level Security, encrypted storage, secure authentication
  • Performance: Database query optimization, image caching, lazy loading, state management
  • User Experience: Animations, haptic feedback, loading states, error recovery, empty states
  • Scalability: Serverless architecture, database indexing, data models, storage
  • Code Structure: MVVM architecture, async/await patterns, error handling, documentation
  • Production Status: App Store submission ready with legal compliance, error handling, testing

Technologies Used

Technologies and domains covered in the project.

iOS Development

SwiftUI, MVVM architecture, async/await, Combine framework, Core Data alternatives, iOS design patterns

Backend Development

PostgreSQL, REST APIs, serverless functions, database design, authentication systems, storage solutions

AI Integration

LLM prompt engineering, structured output generation, AI image generation, cost optimization, API integration

System Design

Architecture patterns, scalability considerations, offline-first design, data synchronization, caching strategies

Security

API key management, Row Level Security, data encryption, secure authentication, privacy compliance (GDPR/CCPA)

Project Management

Phased development, documentation, status tracking, cost monitoring, iterative improvement

Project Summary

WeeknightChef is a proof-of-concept iOS application that integrates multiple APIs (OpenAI, Replicate, USDA, Supabase) for recipe generation, image creation, nutrition data, and backend services. The application uses MVVM architecture, serverless edge functions for API orchestration, and offline-first design with local data persistence.