A comprehensive, full-stack application for managing recipes, featuring social interactions and personalized AI-powered recommendations.
RecipeShare.mp4
- Overview
- System Architecture
- Key Features
- Tech Stack
- Prerequisites
- Getting Started
- Model Training
- API Documentation
- Project Structure
- Contributing
RecipeShare is a modern web application designed to transform how users discover and share culinary experiences. It integrates a robust Java Spring Boot backend for core business logic, a Python FastAPI service for machine learning-based personalized recommendations, and a responsive React frontend for an engaging user experience.
The system follows a microservices-inspired architecture, ensuring scalability and separation of concerns.
graph TD
subgraph Client_Layer["Client Layer"]
Web["React Web App"]
Mobile["Mobile App"]
end
subgraph Gateway_Layer["API Gateway and Load Balancing"]
Nginx["Nginx / Ingress Controller"]
end
subgraph Service_Layer["Microservices Layer"]
direction TB
Auth["Identity Service (Spring Security + JWT)"]
Core["Core Business Service (Spring Boot)"]
ML["AI & ML Recommendation Engine (FastAPI + PyTorch)"]
end
subgraph Event_Bus["Event Driven Backbone"]
Kafka["Apache Kafka"]
Zookeeper["Zookeeper"]
end
subgraph Data_Layer["Data Persistence and Caching"]
Postgres["PostgreSQL (Primary DB)"]
Redis["Redis (L2 Cache & Session)"]
Elastic["Elasticsearch (Full Text Search)"]
end
%% Connections
Web -->|HTTPS REST| Nginx
Mobile -->|HTTPS REST| Nginx
Nginx -->|Reverse Proxy| Core
Core -->|Auth Provider| Auth
Core -->|Read & Write| Postgres
Core -->|Cache Operations| Redis
Core -->|Index & Search| Elastic
Core -->|Publish Events - User Actions| Kafka
Core -->|Synchronous HTTP Inference| ML
ML -->|Subscribe - Training Data Events| Kafka
ML -->|Fetch User History| Postgres
ML -->|Model Cache Access| Redis
Kafka -->|Async Model Updates| ML
Kafka -->|Push Notifications| Core
- Frontend (React): The user interface for browsing recipes, managing profiles, and interacting with the community.
- Java Backend (Spring Boot): The core application server handling user authentication, recipe CRUD operations, social features, and orchestration.
- ML Backend (FastAPI): A dedicated service that generates personalized recipe recommendations using advanced ML models (Two-Tower Neural Network + ALS).
- PostgreSQL: The primary relational database for storing user data, recipes, and interactions.
- Apache Kafka: Handles asynchronous event streaming (e.g., user clicks, likes) to trigger model updates and notifications.
- Redis: High-performance caching layer for session management and recommendation caching.
- Elasticsearch: Powers advanced search capabilities for recipes and ingredients.
- User Management: Secure registration, authentication, and detailed user profiles.
- Recipe Management: Create, edit, and delete recipes with support for rich media (images/videos).
- Social Interactions: Follow other chefs, like recipes, and comment on posts.
- Smart Recommendations: Personalized recipe feeds tailored to user preferences and behavior.
- Advanced Search: Find recipes by ingredients, tags, cooking time, or name.
- Activity Feed: Stay updated with the latest creations from users you follow.
- Framework: React (Vite)
- Language: TypeScript
- Styling: Tailwind CSS, Radix UI
- State Management: React Query / Context API
- Framework: Spring Boot 3.5.6
- Language: Java 17
- Database: PostgreSQL
- Search: Elasticsearch
- Messaging: Apache Kafka
- Caching: Redis
- Build Tool: Maven
- Framework: FastAPI
- Language: Python 3.10+
- ML Libraries: PyTorch, Scikit-learn, Implicit, Pandas, NumPy
- Models: Two-Tower Neural Network, Alternating Least Squares (ALS)
- Build Tool: Pip
Ensure you have the following installed:
- Docker & Docker Compose (Recommended for infrastructure)
- Java 17 (For running the Java Backend)
- Node.js 18+ & pnpm (For running the Frontend)
- Python 3.10+ (For running the ML Backend)
Start the required infrastructure services (Postgres, Kafka, Redis, Elasticsearch) using Docker Compose.
# From the project root
docker-compose up -dNote: This starts the infrastructure containers only. The application services must be run separately.
Navigate to the javaBackend directory and start the Spring Boot application.
cd javaBackend
# Run using Maven wrapper
./mvnw spring-boot:run- Server Port:
8090 - API Base URL:
http://localhost:8090/api
Navigate to the ML_Backend directory and start the FastAPI service.
cd ML_Backend
# Create a virtual environment
python -m venv env
# Activate the environment
# Windows:
.\env\Scripts\activate
# Linux/Mac:
source env/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run the application
uvicorn api.main:app --reload --port 8000- Server Port:
8000 - API Base URL:
http://localhost:8000
Navigate to the Recipe_frontend/recipe_frontend directory and start the development server.
cd Recipe_frontend/recipe_frontend
# Install dependencies
pnpm install
# Start development server
pnpm run dev- App URL:
http://localhost:5173(or as configured in console)
The recommendation engine is the core of RecipeShare's personalized experience. We employ a hybrid approach combining Collaborative Filtering and Deep Learning to deliver accurate, diverse, and socially relevant recommendations.
The ALS model serves as our primary collaborative filtering engine, optimized for implicit feedback datasets (views, likes, saves).
- Library:
implicit(GPU-accelerated) - Technique: Matrix Factorization with BM25 weighting to handle implicit interaction signals effectively.
- Hybrid Reranking Strategy:
- Social Boosting: Recipes interacted with by a user's "followees" receive a relevance boost.
- Content Similarity: Cosine similarity between user profiles and recipe embeddings ensures content relevance.
- Popularity Smoothing: A weighted popularity score helps address the cold-start problem for new users.
- Hyperparameters:
factors=128,regularization=0.05,iterations=30,alpha=40.
For advanced retrieval and semantic matching, we utilize a Two-Tower deep learning architecture implemented in PyTorch.
- Architecture:
- User Tower: Learns dense vector representations (embeddings) of user preferences.
- Recipe Tower: Learns dense vector representations of recipe features.
- Interaction: The dot product of these two vectors predicts the probability of user engagement.
- Training Configuration:
- Loss Function: Weighted Binary Cross Entropy (BCE) to handle class imbalance (positive vs. negative interactions).
- Optimizer: Adam (
lr=1e-3) withReduceLROnPlateauscheduler for adaptive learning rates. - Batch Size: 1024 (Optimized for T4 GPUs).
- Early Stopping: Monitors validation loss with a patience of 4 epochs to prevent overfitting.
We rigorously evaluate our models using a Train/Validation/Test (80/10/10) split strategy to ensure generalization to unseen data.
Key Evaluation Metrics:
- NDCG@K (Normalized Discounted Cumulative Gain): The primary metric for ranking quality. It accounts for the position of relevant items in the recommendation list (higher is better).
- Precision@K: Measures the percentage of recommended items that are relevant.
- Recall@K: Measures the percentage of total relevant items that were successfully retrieved.
- MAP (Mean Average Precision): Summarizes the precision-recall curve into a single score.
- MRR (Mean Reciprocal Rank): Evaluates how high the first relevant item appears in the list.
Our system doesn't rely on a single algorithm. We employ a sophisticated weighted reranking formula to combine multiple signals:
-
$S_{ALS}$ : Collaborative filtering score (User preferences). -
$S_{Social}$ : Social influence score (What friends are cooking). -
$S_{Popularity}$ : Global trend score (Trending recipes). -
$S_{Content}$ : Semantic similarity score (Recipe ingredients/tags matching user history).
New users without interaction history are seamlessly handled via a Popularity-Based Fallback mechanism, ensuring they receive high-quality trending recommendations immediately until sufficient personal data is collected.
The models are trained on a rich dataset representing diverse culinary interactions:
- Users: ~5,000 unique profiles
- Recipes: ~10,500 diverse recipes
- Interactions: ~700,000+ user actions (likes, saves, views)
- Sparsity: Optimized for high-sparsity environments typical of recommender systems.
Training Workflow:
The Recipe_User_Recommendations.ipynb notebook orchestrates the entire pipeline:
- Data Preprocessing: Loading interactions and generating sparse matrices.
- Model Training: Sequential training of ALS and Two-Tower models.
- Real-time Evaluation: Computing metrics on the validation set after every epoch.
- Visualization: Generating plots for Loss curves and Metric comparisons (Validation vs. Test).
- Artifact Management: Saving trained models (
.pkl,.pth) and results to Google Drive for deployment.
POST /api/auth/register- Register a new userPOST /api/auth/login- User loginGET /api/v1/recipes- Get all recipesPOST /api/v1/recipes- Create a new recipeGET /api/v1/users/{id}- Get user profile
POST /api/recommendations- Get personalized recommendationsGET /api/health- Check service health
For detailed API documentation, refer to the Swagger UI at http://localhost:8090/swagger-ui.html (when backend is running).
Recipe_Management_System/
βββ docker-compose.yml # Infrastructure orchestration (DB, Kafka, Redis)
βββ docs/ # Project documentation
βββ javaBackend/ # Spring Boot Application (Core Logic)
β βββ src/ # Source code
β βββ pom.xml # Maven configuration
β βββ compose.yaml # Backend-specific docker compose
βββ ML_Backend/ # Python FastAPI Service (AI/ML)
β βββ api/ # API routes and logic
β βββ models/ # ML models
β βββ notebooks/ # Jupyter notebooks for training
β βββ requirements.txt # Python dependencies
βββ Recipe_frontend/ # Frontend Application
βββ recipe_frontend/ # React project source
βββ src/ # Components and pages
βββ package.json # Node dependencies
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.