# eriksonssilva/gemini-web-wrapper architecture

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

- Interactive diagram: https://gitdiagram.com/eriksonssilva/gemini-web-wrapper
- Repository: https://github.com/eriksonssilva/gemini-web-wrapper

## Overview

##### Project type and main objectives
- This is essentially a full-stack API tool acting as a middleware service. It exposes a /v1/chat/completions endpoint that accepts client requests (such as from Roo Code) and internally calls gemini-webapi to interact with Google Gemini Web.
- It focuses on a single, global chat instance per server run; hence state is maintained; and all incoming requests share the same conversation context.

##### File structure
- README.md – Provides the overall project description, usage notes, configuration, authentication details, and known limitations.
- gemini_api.py – Core entry point for the application. This file likely sets up the FastAPI server, initializes the global chat instance, and defines the REST endpoint (/v1/chat/completions).
- models/models.py – Contains the model definitions or helper functions that abstract parts of the chat or possibly request/response schemas.
- requirements.txt – Lists all dependencies, like FastAPI, gemini-webapi, browser-cookie3, etc.

##### Main components
a. API Layer (FastAPI):
- Represented by the gemini_api.py file. This is the entry point for incoming client HTTP requests.
- Exposed endpoint: /v1/chat/completions.
b. Global Chat Instance:
- A single, shared chat session used for handling conversation history. Emphasize that every incoming request touches this central state.
c. Gemini-WebAPI Integration:
- This component shows the connection between your API layer and the gemini-webapi library.
- It interacts with Google Gemini Web through browser cookies for authentication and session management.
d. Models and Data Processing:
e. External Components & Dependencies:
- External Service: Google Gemini Web. Illustrate how the gemini-webapi library connects to it.
- Authentication Mechanism: Browser cookies, which the gemini-webapi library uses to authenticate with Google Gemini.
- Clients: Tools like Roo Code that send requests to this API.

##### Architectural patterns and design principles
- Separation of concerns: the API layer (handling HTTP requests) is separate from the business logic (managed by gemini-webapi and the Global Chat Instance).
- Common design principles like modularity (via splitting out models and API endpoints), stateless HTTP endpoints (with a caveat that the single global chat has shared state), and dependency injection if used in FastAPI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        client["Client (Roo Code)"]:::client
    end

    subgraph "API Layer"
        api["FastAPI Server (gemini_api.py)"]:::api
        models["Models (Validation/DTOs)"]:::models
    end

    subgraph "Business Logic"
        chat["Global Chat Instance"]:::internal
        gemini["Gemini-WebAPI Integration"]:::internal
    end

    subgraph "External Services"
        google["Google Gemini Web"]:::external
    end

    client -->|"sendsRequest"| api
    api -->|"validates"| models
    api -->|"uses"| chat
    api -->|"forwards"| gemini
    gemini -->|"calls"| google
    google -->|"returns"| gemini

    click api "https://github.com/eriksonssilva/gemini-web-wrapper/blob/master/gemini_api.py"
    click chat "https://github.com/eriksonssilva/gemini-web-wrapper/blob/master/gemini_api.py"
    click gemini "https://github.com/eriksonssilva/gemini-web-wrapper/blob/master/gemini_api.py"
    click models "https://github.com/eriksonssilva/gemini-web-wrapper/blob/master/models/models.py"

    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef internal fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef models fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#000,stroke-width:2px;
```
