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.
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.
| 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. |
| 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. |
| 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). |
The App.tsx component handles all interactions with Firestore. The core operations are:
addDoc(collection(db, 'snippets'), data): Creates a new snippet or folder.datamust includetitle,code(for snippets),name(for folders), andownerId.createdAtandupdatedAtare set to the current timestamp.
updateDoc(doc(db, 'snippets', id), data): Updates an existing snippet or folder.datacontains the fields to be updated.updatedAtis 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.
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.
The application integrates with the Google GenAI API to provide AI-powered code completion within the Monaco Editor.
The GoogleGenAI client (@google/genai) is used to interact with the gemini-3-flash-preview model.
When a user types in the Monaco Editor, a request is sent to the GenAI API with the following parameters:
model:gemini-3-flash-previewcontents: 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, includingtemperature(set to 0.2 for less randomness) andmaxOutputTokens(set to 100).
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.