A Java/Spring Boot backend application that registers food items from the user's "fridge" and uses AI (GPT‑4O) to generate creative and personalized recipes based on the available ingredients.
- 💾 CRUD for food items — Create, read, update, and delete ingredients.
- 🍲 AI-based recipe generation — Sends ingredients to ChatGPT and receives a detailed recipe.
- ☁️ Reactive webhook — Uses Spring WebFlux and
WebClient
for non-blocking calls to OpenAI. - 📦 Persistence layer — H2 database (or PostgreSQL in production) with JPA mapping.
- 🛡️ Schema migration — Managed via Flyway.
- 📄 API documentation — Documented with Swagger/OpenAPI.
- Java 21 + Spring Boot
- Spring Data JPA, H2 / PostgreSQL
- Spring WebFlux
- Jackson, Lombok
- Flyway
- OpenAI API (gpt‑4o)
- Swagger
-
Clone the repository:
git clone https://github.com/viniciusferreira7/magic-fridge-ai.git cd magic-fridge-ai
-
Set environment variables:
export OPENAI_API_KEY=your_openai_key_here # Optional: PostgreSQL DB export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/your_db
-
Run the application:
./mvnw spring-boot:run
-
Access API and Swagger docs:
- Base URL:
http://localhost:8080
- Swagger UI:
http://localhost:8080/swagger-ui.html
- Base URL:
Method | Route | Description |
---|---|---|
POST | /food/save |
Add a new food item |
GET | /food/list |
List all food items |
GET | /food/list/{id} |
Get food item by ID |
PUT | /food/update |
Update a food item |
DELETE | /food/delete/{id} |
Delete a food item by ID |
Method | Route | Description |
---|---|---|
GET | /recipe/generate |
Generate a recipe and image using available ingredients |
-
Formats the ingredients like:
- Apple (FRUIT), 5 units, valid until 2025‑07‑15
-
Sends the formatted string as a prompt to the OpenAI API using WebClient.
-
Receives a response like:
{ "choices": [ { "message": { "content": "Recipe steps..." } } ] }
-
Extracts
choices[0].message.content
and returns it as aMono<String>
.
- Complete the DALL·E image generation integration.
- Add a web or mobile frontend.
- Use WebSocket or Server-Sent Events (SSE) for real-time streaming.
- Suggest complementary ingredients for better recipes.
- Improve validation and error handling.
MIT License © 2025 Vinicius Ferreira
This project is inspired by similar open-source AI recipe generators on GitHub, including:
Feel free to open issues, suggest features, or submit pull requests to improve the project.