# toutchenv587/openai-gemini architecture

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

- Interactive diagram: https://gitdiagram.com/toutchenv587/openai-gemini
- Repository: https://github.com/toutchenv587/openai-gemini

## Overview

##### Overall project type and purpose
- This is a serverless API proxy that translates OpenAI-style API requests to the Gemini API.
- Its purpose is to provide a free endpoint for clients originally meant for the OpenAI API, meaning the focus is on routing and handling requests in a serverless environment with different deployment targets.

##### Main components
a. Client/Application Layer:
- External clients that send API requests (e.g., command-line tools, apps, or integrated software expecting an OpenAI API endpoint).

b. API Gateway / Ingress Points:
- That requests are routed to a serverless backend. Although the project has no separate “gateway” service, the serverless functions (such as those in the "api", "netlify/functions", "netlify/edge-functions", "node.mjs", and "src/worker.mjs") act as entry points.
- Vercel (using vercel.json and node.mjs).
- Netlify (with separate endpoints for `/v1` and `/edge/v1` as indicated in the README and respective handler files).
- Cloudflare Workers (with the file in src/worker.mjs and configuration in wrangler.toml).
- Local development variants (Node, Deno, Bun from package.json scripts).

c. Request Handler / Processing Components:
- That the core logic is contained within the handler files (e.g., api/handler.mjs, netlify/edge-functions/handler.mjs, netlify/functions/handler.mjs) which process incoming requests.
- That this processing includes mapping OpenAI API-style requests to Gemini API calls, handling parameters like chat/completion, embeddings, and others as described in the README.

d. External Dependency:
- Integration of a personal Google API key that is needed for authenticating against Gemini.

e. Configuration & Deployment:
- Various configuration files and CI/CD elements:
- GitHub workflows (inside the .github/workflows folder).
- Deployment configuration files for Vercel (vercel.json), Netlify (netlify.toml), Cloudflare (wrangler.toml), and platform-specific scripts (bun.mjs, deno.mjs, node.mjs).
- This layer shows that while the core application logic is shared, the deployment configuration adapts it to multiple serverless providers.

##### Relationships and interactions
- That each ingress point (Vercel, Netlify, Cloudflare) routes to its corresponding handler component.
- That the handler components invoke the external Gemini API.

##### Architectural patterns and design principles
- Serverless architecture that eliminates the need for server maintenance.
- That the design supports multiple deployment environments using the same core business logic.
- That the code structure is modular—different provider folders indicate pattern separation based on deployment targets.

##### Technologies and frameworks
- Call out usage of JavaScript modules (.mjs) deployed in serverless environments.
- Mention Node.js, Deno, and Bun as supported runtime environments.
- Google Gemini API as an external service.
- CI/CD integration with GitHub Actions and deployment buttons for Vercel, Netlify, and Cloudflare Workers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client/Application"):::client

    subgraph "Vercel Environment"
        VercelConfig("Vercel Config"):::config
        VercelHandler("Vercel Handler (node.mjs)"):::handler
        VercelAPI("Vercel API Handler (api/handler.mjs)"):::handler
        VercelConfig -->|"routes"| VercelHandler
        VercelHandler -->|"processes"| VercelAPI
    end

    subgraph "Netlify Environment"
        NetlifyConfig("Netlify Config"):::config
        NetlifyFunc("Netlify Function Handler"):::handler
        NetlifyEdge("Netlify Edge Handler"):::handler
        NetlifyConfig -->|"routes"| NetlifyFunc
        NetlifyConfig -->|"routes"| NetlifyEdge
    end

    subgraph "Cloudflare Environment"
        CloudflareConfig("Cloudflare Worker Config"):::config
        CloudflareWorker("Cloudflare Worker (src/worker.mjs)"):::handler
        CloudflareConfig -->|"routes"| CloudflareWorker
    end

    subgraph "Local Development"
        LocalNode("Local Node (node.mjs)"):::handler
        LocalDeno("Local Deno (deno.mjs)"):::handler
        LocalBun("Local Bun (bun.mjs)"):::handler
    end

    Gemini("External Gemini API"):::external
    CICD("CI/CD & Deployment (GitHub Actions)"):::cicd

    %% Client sending requests to each deployment gateway
    Client -->|"sendsRequest"| VercelConfig
    Client -->|"sendsRequest"| NetlifyConfig
    Client -->|"sendsRequest"| CloudflareConfig
    Client -->|"sendsRequest"| LocalNode

    %% Handlers call the external Gemini API
    VercelAPI -->|"calls"| Gemini
    NetlifyFunc -->|"calls"| Gemini
    NetlifyEdge -->|"calls"| Gemini
    CloudflareWorker -->|"calls"| Gemini
    LocalNode -->|"calls"| Gemini
    LocalDeno -->|"calls"| Gemini
    LocalBun -->|"calls"| Gemini

    %% Response flows back from Gemini to Client
    Gemini -->|"returns"| Client

    %% CI/CD integration triggers deployment configurations
    CICD ---|"updates"| VercelConfig
    CICD ---|"updates"| NetlifyConfig
    CICD ---|"updates"| CloudflareConfig

    %% Click Events
    click VercelConfig "https://github.com/toutchenv587/openai-gemini/blob/main/vercel.json"
    click VercelHandler "https://github.com/toutchenv587/openai-gemini/blob/main/node.mjs"
    click VercelAPI "https://github.com/toutchenv587/openai-gemini/blob/main/api/handler.mjs"
    click NetlifyConfig "https://github.com/toutchenv587/openai-gemini/blob/main/netlify.toml"
    click NetlifyFunc "https://github.com/toutchenv587/openai-gemini/blob/main/netlify/functions/handler.mjs"
    click NetlifyEdge "https://github.com/toutchenv587/openai-gemini/blob/main/netlify/edge-functions/handler.mjs"
    click CloudflareConfig "https://github.com/toutchenv587/openai-gemini/blob/main/wrangler.toml"
    click CloudflareWorker "https://github.com/toutchenv587/openai-gemini/blob/main/src/worker.mjs"
    click LocalNode "https://github.com/toutchenv587/openai-gemini/blob/main/node.mjs"
    click LocalDeno "https://github.com/toutchenv587/openai-gemini/blob/main/deno.mjs"
    click LocalBun "https://github.com/toutchenv587/openai-gemini/blob/main/bun.mjs"
    click CICD "https://github.com/toutchenv587/openai-gemini/tree/main/.github/workflows"

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef config fill:#fff0cc,stroke:#333,stroke-width:2px;
    classDef handler fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef cicd fill:#e2d6f7,stroke:#333,stroke-width:2px;
```
