How srinivas26k/ai-cookchef works
Project Type and Purpose
• BakeGenius AI is a full-stack web application combining a static multi-page frontend (HTML/CSS/JS) with a Node.js (Bun) backend.
• Purpose: let users log in/sign up, enter or speak vague recipe measurements, and get precise gram-based conversions via an AI-driven conversion engine.
Top-Level Components
a. Frontend (Presentation Layer)
• Static files (html/, css/, js/, favicon/, assets/) served to the browser
• Pages: index, about, convert, customize, login, signup, scale, recipe
• Modules:
– UI & styling (CSS files)
– Page logic (JS files invoking fetch/Gemini API)
– Voice-input handler (Web Speech API in js/)
– Firebase integration (firebase-config.js for hosting/auth/analytics)
b. Backend (Application Layer)
• Runtime: Bun (bun.lock) or Node.js (package.json)
• Entry point: server/server.js
• MVC sub-structure:
– Models: server/models/User.js
– Routes/Controllers: server/routes/auth.js (auth endpoints), plus conversion endpoints (implicit in server.js)
• Core responsibilities:
– User authentication & session management (signup/login, JWT or sessions)
– Conversion API:
· Receive measurement text
· Lookup ingredient densities (in-code DB or JSON)
· Call external Gemini API for NLP/contextual suggestions
· Compute grams and return JSON response
c. Database (Data Layer)
• MongoDB (URI in .env, .env.example) or another NoSQL store
• Collections: users, optionally conversion_history
d. External Services
• Gemini API (Google) for NLP and smart conversion suggestions
• Firebase Hosting/Analytics (optional)
Relationships & Data Flows
1. User opens a page (e.g., convert.html) → Browser fetches static assets from Firebase or static server.
2. User speaks or types ingredient measurement → Frontend JS module processes voice input or text.
3. Frontend sends POST /api/convert or GET /api/convert with payload → Backend server.js route.
4. Backend:
• Validates JWT/session (via auth.js)
• Queries density DB
• Calls Gemini API → Receives NLP payload
• Calculates precise grams → Responds to frontend.
5. Frontend receives JSON → Renders result + visualization (chart or table).
6. For login/signup: Frontend POST /api/auth/signup or /login → auth.js → User model → Database → JWT/session returned to frontend.
Architectural Patterns & Principles
• Layered Architecture: Presentation → Application → Data → External Services
• MVC on backend (Models, Controllers/Routes, Server as orchestrator)
• RESTful API design for conversion & auth endpoints
• Separation of concerns: static assets vs. dynamic API
• Client-side modular JS for voice, API calls, visualization
Summary
• Don’t over-complicate: separate into Frontend, Backend, DB, External.
• AI conversion flow (Frontend → Backend → Gemini API → Backend → Frontend).
• Auth flow separately.