Skip to content

Latest commit

 

History

History
83 lines (59 loc) · 5.21 KB

File metadata and controls

83 lines (59 loc) · 5.21 KB

🔌 API Documentation: Snippet Bubble Manager

This document outlines the primary API interactions within the Snippet Bubble Manager application, focusing on its communication with Firebase services and the Google GenAI API.

☁️ Firebase Firestore API

The application primarily interacts with Google Cloud Firestore for data persistence. All data access is secured by Firestore Rules, ensuring users can only read and write their own data.

Collections

Collection Name Description
snippets Stores individual code snippets, each owned by a specific user.
folders Stores folders for organizing snippets, also owned by specific users.

Data Models

Snippet

Field Type Description
id string Unique identifier for the snippet (auto-generated by Firestore).
title string Title of the snippet.
code string The actual code snippet content.
language string Programming language of the snippet (e.g., javascript, python).
description string Optional description of the snippet.
tags string[] Optional array of tags for categorization.
isFavorite boolean Flag indicating if the snippet is marked as a favorite.
isPinned boolean Flag indicating if the snippet is pinned for quick access.
ownerId string User ID of the snippet's owner. Automatically set on creation.
lastCopiedAt string Timestamp of when the snippet was last copied (ISO 8601 format).
createdAt string Timestamp of when the snippet was created (ISO 8601 format).
updatedAt string Timestamp of when the snippet was last updated (ISO 8601 format).
folderId string Optional ID of the folder the snippet belongs to.

Folder

Field Type Description
id string Unique identifier for the folder (auto-generated by Firestore).
name string Name of the folder.
ownerId string User ID of the folder's owner. Automatically set on creation.
createdAt string Timestamp of when the folder was created (ISO 8601 format).
updatedAt string Timestamp of when the folder was last updated (ISO 8601 format).

Operations

The App.tsx component handles all interactions with Firestore. The core operations are:

  • addDoc(collection(db, 'snippets'), data): Creates a new snippet or folder.
    • data must include title, code (for snippets), name (for folders), and ownerId.
    • createdAt and updatedAt are set to the current timestamp.
  • updateDoc(doc(db, 'snippets', id), data): Updates an existing snippet or folder.
    • data contains the fields to be updated.
    • updatedAt is set to the current timestamp.
  • deleteDoc(doc(db, 'snippets', id)): Deletes a snippet or folder by its ID.
  • onSnapshot(query(collection(db, 'snippets'), ...)): Establishes a real-time listener for snippets or folders owned by the current user. This provides live updates to the UI.
  • signInWithPopup(auth, GoogleAuthProvider()): Initiates Google OAuth for user authentication.
  • signOut(auth): Signs out the current user.

Error Handling

Firestore operations are wrapped in try-catch blocks, and errors are handled by the handleFirestoreError function, which logs detailed error information including the operation type, path, and current user's authentication details.

🤖 Google GenAI API

The application integrates with the Google GenAI API to provide AI-powered code completion within the Monaco Editor.

Endpoint

The GoogleGenAI client (@google/genai) is used to interact with the gemini-3-flash-preview model.

Request

When a user types in the Monaco Editor, a request is sent to the GenAI API with the following parameters:

  • model: gemini-3-flash-preview
  • contents: A prompt instructing the model to act as a code completion assistant, including the current code context and selected language.
  • config: Configuration for the model, including temperature (set to 0.2 for less randomness) and maxOutputTokens (set to 100).

Response

The API returns a text field containing the suggested code completion as a string. This completion is then integrated into the Monaco Editor's suggestion list.