How michniks2001/ingredibud works
Project Type and Purpose
• Full-stack web application built with Next.js (App Router) and TypeScript.
• Purpose: AI-powered recipe generator (“Ingredibud”) that leverages Google Search + Gemini AI to fetch grounding sources and synthesize beginner-friendly recipes.
• Includes user authentication, recipe browsing, and a responsive, animated UI.
High-Level Components
• Frontend (UI)
– Next.js App Router pages in app/ (e.g., /, /recipes, /about, /faq, /login, /signup, /dashboard)
– Reusable React components in components/ (navbar, recipe-form)
– Global CSS (Tailwind) in app/globals.css
– Auth state management via React Context in contexts/auth-context.tsx
• API Layer (Backend Routes)
– Next.js API routes under app/api/:
· auth (login, logout, signup, me)
· generate-recipe (calls Google Search + Gemini AI)
· recipes (list & single recipe endpoints)
– Each route implements server-side logic, calls helper functions in lib/, and interacts with the database.
• Services & Libraries
– lib/googleSearch (built-in in lib/auth.ts, lib/markdown.ts, lib/mongodb.ts)
– MongoDB driver & connection logic in lib/mongodb.ts
– Markdown sanitization & rendering in lib/markdown.ts
– Auth helper functions (token creation, cookie handling) in lib/auth.ts
• External Systems
– Google Search API or scraping layer for grounding sources
– Google Generative AI (Gemini) via GEMINI_API_KEY
– MongoDB Atlas (or self-hosted) for user and recipe storage
– Vercel (deployment platform)
Interactions and Data Flow
1. User (Browser)
• Sends HTTP(S) request to Next.js server (page load, navigation)
• Interacts with client-side React UI
• Triggers API calls (e.g., form submission for login/signup, recipe generation)
2. Next.js Server / API Routes
• SSR/SSG for pages; client-side JS hydration
• API route receives request → validates/authenticates (via cookies/context) → calls relevant lib/ functions
• For recipe generation:
a. Call Google Search to fetch URLs → normalize URLs → fetch content
b. Pass grounding sources + user inputs to Gemini AI → receive recipe in Markdown
c. Sanitize + convert to HTML → return JSON payload
• For auth: create JWT or session cookie → store user record in MongoDB → return user data
• For recipes CRUD: read/write from MongoDB
3. Client-Side State
• auth-context stores current user, provides login/logout/signup wrappers
• UI components render based on auth state and API responses
Architectural Patterns & Principles
• Separation of Concerns: UI ↔ API ↔ Data
• React Context for cross-cutting auth state
• Next.js App Router for file-based routing (pages & API)
• Layered Helpers in lib/ for DB, auth, markdown
• External service integration abstracted behind API routes
• Responsive design (mobile-first with Tailwind)
Putting It All Together
• Every critical component (pages, components, context, routes, lib, external services, DB) appears.