# priyanshur1234/hotel-negotiation-gemini-api architecture

> Architecture diagram of the GitHub repository priyanshur1234/hotel-negotiation-gemini-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/priyanshur1234/hotel-negotiation-gemini-api
- Repository: https://github.com/priyanshur1234/hotel-negotiation-gemini-api

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (UI / HTTP Consumer)"]:::client

    %% Serverless Functions
    subgraph "Serverless Functions"
        direction TB
        Negotiate["POST /negotiate"]:::api
        ClearHistory["POST /clear-history"]:::api
        Health["GET /health"]:::api
        SharedIndex["Shared Router / Helper"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        GeminiService["Gemini Service"]:::service
        InMemoryStore["In-Memory Store"]:::service
    end

    %% External Systems & Config
    ExternalGemini["Google Gemini API"]:::external
    EnvConfig["Env Vars (GEMINI_API_KEY)"]:::config
    Metadata["Project Metadata"]:::config

    %% Data Flows
    Client -->|"POST /negotiate {message, userId}"| Negotiate
    Negotiate -->|"use Shared Router"| SharedIndex
    Negotiate -->|"processMessage()"| GeminiService
    GeminiService -->|"read/write history"| InMemoryStore
    GeminiService -->|"HTTP Request"| ExternalGemini
    ExternalGemini -->|"AI Response"| GeminiService
    GeminiService -->|"return reply"| Negotiate
    Negotiate -->|"HTTP Response {reply}"| Client

    Client -->|"POST /clear-history"| ClearHistory
    ClearHistory -->|"use Shared Router"| SharedIndex
    ClearHistory -->|"clearStore()"| InMemoryStore
    ClearHistory -->|"HTTP Response {status}"| Client

    Client -->|"GET /health"| Health
    Health -->|"HTTP 200 OK"| Client

    %% Config & Metadata
    EnvConfig -.->|used by| GeminiService
    Metadata -.->|defines| ServerlessFunctions

    %% Click Events
    click Negotiate "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/api/negotiate.js"
    click ClearHistory "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/api/clear-history.js"
    click Health "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/api/health.js"
    click SharedIndex "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/api/index.js"
    click Client "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/index.js"
    click GeminiService "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/services/geminiService.js"
    click EnvConfig "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/.env"
    click Metadata "https://github.com/priyanshur1234/hotel-negotiation-gemini-api/blob/main/package.json"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef api fill:#87CEFA,stroke:#000,stroke-width:1px
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
    classDef config fill:#FFD700,stroke:#000,stroke-width:1px
```
