Skip to content

Database Schema & Diagram

Navigation: README | Architecture & Diagrams | How It Works | Database Schema | Hackathon Requirements | Deployment

The KidStory (ai.kidstory.app) application uses Google Cloud Firestore (NoSQL) for storing user data, story metadata, and quiz results.

We use a hierarchical structure where stories are stored as a sub-collection under each user. This ensures data isolation and efficient querying for individual users.

1. Entity Relationship Diagram (ERD)


2. Collection Reference

users (Collection)

Root collection for user profiles.

  • Document ID: uid (from Firebase Authentication)
FieldTypeDescription
uidStringThe unique user ID from Firebase Auth.
emailStringUser's email address.
displayNameStringUser's full name.
photoURLStringURL to user's Google profile picture.
createdAtTimestampWhen the account was first created.
totalStoriesNumberCounter for total stories generated.

users/{uid}/stories (Sub-Collection)

Stores all stories generated by a specific user.

  • Document ID: Auto-generated or UUID
FieldTypeDescription
idStringUnique identifier for the story.
titleStringThe AI-generated title of the story.
promptStringThe original prompt provided by the child.
coverImageUrlStringGCS URL to the first page's illustration.
statusStringGeneration status (generating, complete, error).
voiceStringSelected narrator voice (Aoede or Callirrhoe).
createdAtTimestampWhen the story was generated.
pagesArray<Object>An ordered array of page content (see below).
lastQuizScoreNumberScore of the most recent quiz (e.g., 4).
lastQuizTotalNumberTotal questions in the quiz (e.g., 5).
lastQuizDateTimestampWhen the last quiz was completed.

pages Array Object Structure

Each object in the pages array represents a single page of the book. These are populated either by the interleaved multimodal stream or by parallel generation fallback:

json
{
  "pageNumber": 1,
  "text": "Once upon a time, in a land of sparkling rivers...",
  "imageUrl": "https://storage.googleapis.com/bucket/images/storyId/page-1.png",
  "audioUrl": "https://storage.googleapis.com/bucket/audio/storyId/page-1.mp3",
  "imagePrompt": "Watercolor illustration of a magical forest with sparkling rivers..."
}
FieldTypeDescription
pageNumberNumberPage order (1-indexed).
textStringThe story text for this page (3-4 sentences).
imageUrlStringGCS signed URL to the watercolor illustration.
audioUrlStringGCS signed URL to the narration audio (WAV).
imagePromptStringThe prompt used to generate the illustration.

3. Storage Structure (Google Cloud Storage)

Media assets are stored in a GCS bucket (default: storybook-for-kids-media) with 7-day signed URLs.

gs://storybook-for-kids-media/
  images/
    {storyId}/
      page-1.png
      page-2.png
      ...
  audio/
    {storyId}/
      page-1.mp3
      page-2.mp3
      ...
Path PatternFormatDescription
images/{storyId}/page-{N}.pngPNGWatercolor illustration for page N
audio/{storyId}/page-{N}.mp3MP3/WAVNarration audio for page N

Released under the MIT License.