apps — gemini-chatbox

Module: apps-gemini-chatbox Cohesion: 0.80 Members: 0

apps — gemini-chatbox

This document provides a technical overview of the apps/gemini-chatbox module, detailing its purpose, architecture, key components, and operational flow. It is designed for developers who need to understand, maintain, or extend this application.

1. Introduction

The gemini-chatbox module is a self-contained mini-application designed to demonstrate and test integration with the Google Gemini API under real-world conditions. It features a simple web-based chat interface (frontend) and an Express.js backend that proxies requests to the Gemini API.

Its primary purpose is to serve as a dedicated environment for:

2. Architecture Overview

The gemini-chatbox application follows a client-server architecture:

graph TD
    A[Browser] -->|GET /| B(server.mjs)
    A -- User Input --> C(app.js)
    C -->|POST /api/chat {message, history}| B
    B -->|POST to Gemini API| D(Google Gemini API)
    D -->|Response| B
    B -->|JSON {reply, model}| C
    C -->|Display Message| A

3. Key Components

3.1. Frontend (apps/gemini-chatbox/public/)

The frontend is a standard web application composed of HTML, CSS, and JavaScript.

3.2. Backend (apps/gemini-chatbox/server.mjs)

This is an Express.js server responsible for serving the frontend and handling API interactions with Gemini.

3.3. Smoke Test (apps/gemini-chatbox/smoke-test.mjs)

This script provides an automated way to verify the application's basic functionality.

  1. Waits for the server to start.
  2. Performs a GET request to /health to check server status and API key configuration.
  3. Performs a GET request to / to ensure the main HTML page loads correctly.
  4. Performs a POST request to /api/chat with a specific message, expecting a reply from Gemini.
  5. Logs success or failure and ensures the server process is terminated.

4. Execution Flow: Chat Interaction

  1. Initialization: When http://localhost:3333 is accessed, server.mjs serves index.html and app.js. app.js initializes the chat interface and displays a welcome message.
  2. User Input: The user types a message into the message-input textarea and clicks "Envoyer" (or presses Enter).
  3. Frontend Processing (app.js):

  1. Backend Processing (server.mjs):

  1. Frontend Response Handling (app.js):

5. Configuration

The application relies on environment variables for configuration. These can be set in a .env file at the repository root or in the apps/gemini-chatbox directory.

6. How to Run

From the root of the repository:

node -r dotenv/config apps/gemini-chatbox/server.mjs

Then, open your web browser to http://localhost:3333 (or your configured CHATBOX_PORT).

7. How to Test

To run the automated smoke test:

node -r dotenv/config apps/gemini-chatbox/smoke-test.mjs

This script will launch the server, perform health checks, verify the homepage, and send a test message to the Gemini API via the /api/chat endpoint.

8. Contributing

This module is designed as a dedicated, standalone application within the repository. While it doesn't have direct code dependencies on other internal modules, contributions should focus on:

When making changes, ensure that the smoke-test.mjs continues to pass and that the application functions correctly with a valid Gemini API key.