How mwasifanwar/culinaryai works
Project Type and Purpose
• culinaryai is a backend‐focused AI service (a Python “monolith” organized into clear modules) that offers:
• Recipe generation (text and image‐to‐recipe)
• Flavor prediction and pairing
• Food chemistry analysis & nutrition calculation
• It exposes its functionality via an API layer (src/api/server.py) and is configured by config.yaml.
File‐Structure → Architectural Components
• src/api/
• server.py – REST (or HTTP) endpoints; the “entry point” for all external requests.
• src/data_processing/
• recipe_parser.py, molecular_processor.py, flavor_analyzer.py – preprocess and extract structured data from raw recipe text or molecular data.
• src/food_science/
• chemistry_analyzer.py, nutrition_calculator.py, pairing_engine.py – core domain logic for molecular gastronomy, nutrition, and flavor pairings.
• src/generative_models/
• flavor_predictor.py, recipe_generator.py, image_to_recipe.py – inference wrappers around trained ML/DL models that generate text or predict flavor profiles.
• src/multi_modal/
• cross_modal_encoder.py, fusion_model.py – components to fuse image and text representations for multi‐modal inference.
• src/utils/
• config.py – loads config.yaml; helpers.py – shared utility functions.
• main.py – bootstraps the server (loads config, initializes modules, starts listening).
Key Architectural Patterns
• Modular decomposition: each domain area (API, data processing, food science, generative models, multi-modal) lives in its own namespace.
• Pipeline pattern: requests flow through preprocessing → domain logic → model inference → postprocessing.
• Inversion of Control: central server orchestrates sub‐modules rather than having modules call each other implicitly.
• Configuration‐driven: behavior and model paths are injected via config.yaml and config.py.
Components & Interactions
a. External Clients
• Web/mobile UI or CLI → HTTP/JSON → src/api/server.py
b. API Layer (src/api)
• Receives request, authenticates/validates → routes to one of four pipelines:
– Data‐Processing Pipeline
– Food‐Science Pipeline
– Generative‐Model Pipeline
– Multi‐Modal Pipeline
c. Data‐Processing Module
• recipe_parser → molecular_processor → flavor_analyzer
• Outputs structured data (ingredients, molecular features)
d. Food‐Science Module
• chemistry_analyzer ↔ nutrition_calculator ↔ pairing_engine
• Consumes structured data or raw input
e. Generative‐Models Module
• recipe_generator → flavor_predictor → image_to_recipe
• Uses model checkpoints loaded via config
f. Multi‐Modal Module
• cross_modal_encoder → fusion_model
• Takes image bytes + text; returns fused embeddings for downstream generative or analysis tasks
g. Utilities & Config
• config.py provides global settings to all modules
• helpers.py supplies common routines (logging, data formatting)
Relationships & Data Flow
• Within each pipeline, directional flow: preprocessing → domain logic → model inference → response builder
• Shared utils and config as lateral dependencies injected into each module
• (Optionally) a model‐registry or filesystem block for “Model Checkpoints” accessed by generative_models and multi_modal
Technologies & External Services
• Python 3.x, FastAPI or Flask (in server.py), PyTorch or TensorFlow for ML models, YAML for config
• Potential external storage: S3 or local disk for model artifacts
• (If present) a database for caching results or telemetry
Final Checklist
[ ] Main components boxed & labeled
[ ] External dependencies: Clients, Model Store, Config
[ ] Clear indication of module interactions (e.g., generative_models ↔ multi_modal)
[ ] Footnote explaining pipeline patterns and modular organization