How priyanshur1234/hotel-negotiation-gemini-api works
Project Type and Purpose
• This is a Node.js–based AI negotiation microservice, intended to run as serverless functions (e.g., on Vercel) or as an Express server.
• Its sole purpose is to expose HTTP endpoints that accept user messages, negotiate hotel rates and benefits via Google’s Gemini API, and return AI‑generated replies.
File Structure Analysis
• Top level:
• index.js – bootstraps an Express server (for local or non‑serverless deployment)
• .env – holds GEMINI_API_KEY
• README.md, package.json / lock
• api/ folder: contains serverless route handlers:
• negotiate.js – POST /negotiate
• clear-history.js – POST /clear-history
• health.js – GET /health
• index.js – shared routing / helper for serverless environment
• services/ folder:
• geminiService.js – encapsulates all calls to Google Gemini API and conversation‑history management (in‑memory)
Key README Insights
• Two main REST endpoints: /negotiate and /clear-history
• In‑memory conversation history (ephemeral across invocations)
• Deployed on Vercel as serverless functions, but also runnable locally via Express
Main Components
a. Client (UI or other HTTP consumer)
b. API Layer (Express on localhost or Vercel serverless functions under api/)
c. Service Layer (geminiService.js)
d. External System (Google Gemini API)
e. Environment / Configuration (GEMINI_API_KEY)
f. In‑Memory Store (ephemeral conversation history)
Relationships & Data Flow
• Client → HTTP POST /negotiate → API Layer (negotiate.js)
• API Layer → geminiService.processMessage() → (reads/writes) In‑Memory Store
• geminiService → HTTP Request to Google Gemini API → Gemini returns AI decision
• geminiService → returns response to API Layer → API Layer → HTTP Response to Client
• Client can → HTTP POST /clear-history → API Layer (clear-history.js) → In‑Memory Store clears data
• API Layer exposes GET /health for readiness checks
Architectural Patterns & Principles
• Separation of Concerns:
• Routing / HTTP layer (api/*.js)
• Business logic & external‑API integration (services/geminiService.js)
• Serverless Micro‑Functions: each file in api/ acts as an independent endpoint
• Environment‑Driven Configuration: secrets in .env or Vercel env vars
• Statelessness: ephemeral in‑memory history per function invocation (note for production: swap to persistent DB)
Technologies / Frameworks
• Node.js 18+
• Express (for local development)
• Vercel Serverless Functions (api folder)
• Google Gemini API
• dotenv (environment variable loading)
Checklist
• All components are labeled clearly
• Configuration points (e.g., GEMINI_API_KEY via .env or platform env vars)