Schema Document #

Schema v1.0 · ronilprasad8.tech · Data Architecture & Persistence

1. Database Overview #

The application uses Google Cloud Firestore as its primary database. Firestore is a NoSQL document-oriented database. There is no formal ORM (like Prisma or SQLAlchemy) used in this project; instead, the schema is implicitly defined by the JavaScript object payloads sent via the Firebase Client SDK (setDoc, addDoc) found in login.html and chatbot.js.


2. Entity-Relationship Diagram #

Although Firestore is NoSQL, conceptual relationships exist based on document IDs (the uid generated by Firebase Authentication).

erDiagram FIREBASE_AUTH { string uid PK "Generated by Firebase" string email } users { string documentId PK "Matches Auth UID" string firstName string lastName string email } knowledge { string documentId PK "Matches Auth UID (or 'ronil_global')" array facts } messages { string documentId PK "Auto-generated by Firestore" string username string text timestamp timestamp } FIREBASE_AUTH ||--o| users : "Creates" users ||--o| knowledge : "1-to-1 Mapping (Logical)"

3. Collection Definitions #

The following collections are actively written to and read from in the codebase.

Collection: users

Created during the signup flow in login.html (both Email/Password and Google OAuth routes).

Field Type Constraints / Notes Description
documentId String Primary Key (Explicit) Must exactly match the Firebase Authentication user.uid.
firstName String Required Extracted from form input or split from Google displayName.
lastName String Optional Extracted from form input or split from Google displayName.
nickname String Optional Custom form input (Email registration) or fallback to displayName (Google).
organization String Optional Only present for users registering via the custom Email form.
username String Optional Derived from email prefix (e.g., split('@')[0]). Found only in the Google OAuth creation flow.
email String Required, Unique (by Auth) The user's registered email address.
createdAt String (ISO) Auto-generated Generated via JavaScript new Date().toISOString().

Collection: knowledge

Managed by chatbot.js. Used to persist facts learned by the AI Assistant during conversations.

Field Type Constraints / Notes Description
documentId String Primary Key (Explicit) Matches the user.uid for normal users, or strictly "ronil_global" for the owner's master account.
facts Array[String] Appended via arrayUnion A list of facts extracted from the LLM outputs via the [LEARN_RONIL: ...] or [LEARN_USER: ...] tags.

Collection: messages

Managed by chatbot.js. Triggered conditionally when the LLM outputs a [SAVE_TRIGGER: ...] tag to log specific events.

Field Type Constraints / Notes Description
documentId String Auto-generated Generated by Firestore's addDoc() method.
username String Required The identifier of the user who triggered the save event.
text String Required The payload/message content to log.
timestamp Firestore Timestamp Server-side generated Generated via serverTimestamp() from the Firebase SDK.

4. Relationships #

As a NoSQL store, relationships are not enforced by foreign key constraints. Instead, they are logically maintained by the application code:


5. Indexes & Constraints #