Skip to Content
πŸ“š MyStoryFlow Docs β€” Your guide to preserving family stories
System ArchitectureCampaign to Book MergeOverview

Campaign-to-Book Merge: Comprehensive Architecture Plan

Status: APPROVED - Ready for Implementation Author: Architecture Team Date: 2025-01-30 Last Updated: 2025-01-30


Design Decisions (Confirmed)

QuestionDecisionRationale
UI terminology”Book”Simple and intuitive
Template change after storiesAllowed with warningPreserve content, suggest re-mapping
Gift recipient auto-add giverYes, as contributorNatural collaboration
Stories shared between booksNo - duplicate insteadSimpler to manage, story becomes starting point
Default family sharingON for updates (weekly)Keep family engaged
Placeholder stories from templateYes, auto-createdGive users a head start
Recording/AI scopeBook-specific (MVP)Enables RAG context for better AI suggestions

Executive Summary

This document outlines a complete plan to merge the campaigns concept into books, simplifying the data model from two related entities (Campaign β†’ Book) into a single unified entity (Book as Project). This change aligns with the v1.1 architecture goal of Story = Chapter and creates a more intuitive user experience.

Key Changes

  • Book becomes the top-level project (replaces Campaign)
  • Stories belong directly to Books from creation
  • Template-first approach - chosen at book creation to inform prompts
  • Placeholder stories auto-created from template structure
  • Storyteller info moves to Book - who the book is about
  • Story duplication - copy stories between books (no sharing/linking)
  • Family sharing ON by default - weekly update notifications
  • Recording & AI are book-scoped - enables RAG context for better suggestions
  • Simplified URL structure - /books/[id]/stories/new instead of /campaigns/[id]/stories/new

Table of Contents

  1. Current State Analysis
  2. Proposed Architecture
  3. Database Schema Changes
  4. Frontend Route Changes
  5. Component Migration
  6. Family Access Model
  7. Onboarding Flow Design
  8. User Journey Scenarios
  9. API Changes
  10. Data Migration Strategy
  11. Risk Analysis
  12. Implementation Phases

1. Current State Analysis

1.1 Current Data Model

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ campaigns │────▢│ books │────▢│ stories β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ storyteller_* β”‚ β”‚ story_ids[] β”‚ β”‚ campaign_id β”‚ β”‚ template_id β”‚ β”‚ template_id β”‚ β”‚ (redundant) β”‚ β”‚ family_group_id β”‚ β”‚ family_group_id β”‚ β”‚ family_group_id β”‚ β”‚ is_gift β”‚ β”‚ (redundant?) β”‚ β”‚ (redundant?) β”‚ β”‚ status β”‚ β”‚ status β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1.2 Current campaigns Table Fields

FieldPurposeMove To
storyteller_nameWho the book is aboutbooks.storyteller_name
storyteller_emailContact for storytellerbooks.storyteller_email
storyteller_phoneContact for storytellerbooks.storyteller_phone
storyteller_notesNotes about storytellerbooks.storyteller_notes
storyteller_user_idIf storyteller has accountbooks.storyteller_user_id
template_idBook templateAlready in books
is_giftGift purchase flagbooks.is_gift
gift_messagePersonal messagebooks.gift_message
gift_recipient_*Gift recipient infobooks.gift_recipient_*
gift_statusDelivery statusbooks.gift_status
goal_storiesTarget story countbooks.goal_stories
prompt_frequencyHow often to promptbooks.prompt_settings
communication_methodEmail/SMS preferencebooks.notification_settings
user_roleCreator’s relationshipbooks.creator_relationship
family_group_idFamily ownershipAlready in books
is_family_sharedSharing flagUse family_book_permissions
statusCampaign statusbooks.project_status
setup_stepWizard progressbooks.setup_step
setup_progressWizard databooks.setup_progress

1.3 Current Route Structure

Campaigns (27 files):

/campaigns β†’ List all campaigns /campaigns/create β†’ Multi-step wizard (7 steps) /campaigns/[id] β†’ Campaign dashboard /campaigns/[id]/stories β†’ Stories list /campaigns/[id]/stories/new β†’ Create story /campaigns/[id]/stories/[id] β†’ Story view /campaigns/[id]/stories/[id]/edit β†’ Edit story /campaigns/[id]/ai/voice β†’ AI voice recording /campaigns/[id]/ai/photo β†’ AI photo features /campaigns/[id]/import/voice β†’ Voice import

Books (23 files):

/books β†’ List all books /books/new β†’ Book creation wizard /books/[id] β†’ Book detail /books/[id]/edit β†’ Edit book /books/[id]/design β†’ Design customization /books/[id]/chapters β†’ Chapter management /books/[id]/chapters/[id]/edit β†’ Edit chapter /books/analytics β†’ Analytics dashboard

2. Proposed Architecture

2.1 New Data Model

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ books β”‚ β”‚ (Book Project - The single top-level entity) β”‚ β”‚ β”‚ β”‚ Core Info: β”‚ β”‚ title, subtitle, description β”‚ β”‚ author_name, contributor_names[] β”‚ β”‚ β”‚ β”‚ Storyteller (NEW - from campaigns): β”‚ β”‚ storyteller_name β”‚ β”‚ storyteller_relationship (replaces user_role) β”‚ β”‚ storyteller_user_id β”‚ β”‚ storyteller_email, storyteller_phone β”‚ β”‚ β”‚ β”‚ Template & Content: β”‚ β”‚ template_id (chosen UPFRONT) β”‚ β”‚ story_ids[] (chapters) β”‚ β”‚ goal_stories, completed_stories β”‚ β”‚ β”‚ β”‚ Project Status: β”‚ β”‚ project_status: 'setup'|'collecting'|'editing'| β”‚ β”‚ 'designing'|'ready'|'published' β”‚ β”‚ setup_step, setup_progress β”‚ β”‚ β”‚ β”‚ Notifications (NEW): β”‚ β”‚ prompt_frequency β”‚ β”‚ notification_preferences (jsonb) β”‚ β”‚ β”‚ β”‚ Gift (NEW - from campaigns): β”‚ β”‚ is_gift, gift_message β”‚ β”‚ gift_recipient_name, gift_recipient_email β”‚ β”‚ gift_status, gift_delivery_date β”‚ β”‚ β”‚ β”‚ Family: β”‚ β”‚ family_group_id β”‚ β”‚ (permissions via family_book_permissions) β”‚ β”‚ β”‚ β”‚ Publishing: β”‚ β”‚ kdp_*, isbn_*, cover_*, design_settings β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ book_id β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ stories β”‚ β”‚ β”‚ β”‚ book_id (NEW - replaces campaign_id) β”‚ β”‚ title, content β”‚ β”‚ chapter_number (derived from books.story_ids index) β”‚ β”‚ prompt (which template prompt was used) β”‚ β”‚ status, word_count, etc. β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

2.2 New Route Structure

# Books (primary entity - all content is book-scoped) /books β†’ Dashboard: All book projects /books/new β†’ Create book wizard (template-first) /books/[id] β†’ Book project dashboard /books/[id]/stories β†’ Stories/chapters in this book /books/[id]/stories/new β†’ Create story IN this book (with template prompts) /books/[id]/stories/[sid] β†’ View story in book context /books/[id]/stories/[sid]/edit β†’ Edit story (uses EnhancedEditorShell) /books/[id]/record β†’ Voice recording hub for this book /books/[id]/conversations β†’ AI conversation hub for this book /books/[id]/design β†’ Design customization /books/[id]/preview β†’ Preview book /books/[id]/publish β†’ Publishing flow /books/[id]/settings β†’ Book settings /books/[id]/share β†’ Sharing & permissions # Stories (for browsing/search across all books) /stories β†’ Browse all user's stories across books /stories/[id] β†’ Redirect to /books/[book_id]/stories/[id]

Key insight (MVP): All content is book-scoped for better RAG context:

  • Recordings belong to a specific book β†’ context stays consistent
  • AI conversations belong to a specific book β†’ RAG uses book’s stories as context
  • Users must choose a book before recording/AI conversations
  • This enables the AI to provide more relevant, book-specific suggestions

2.3 Terminology Changes

Old TermNew TermRationale
CampaignBook ProjectMore intuitive
Story Project(removed)Redundant
Create CampaignStart a BookSimpler language
Campaign StatusBook ProgressClearer meaning
StorytellerAuthor/SubjectDepends on context

3. Database Schema Changes

3.1 New Columns for books Table

-- Add storyteller fields (from campaigns) ALTER TABLE books ADD COLUMN storyteller_name VARCHAR(255); ALTER TABLE books ADD COLUMN storyteller_relationship VARCHAR(100); -- Values: 'self', 'parent', 'grandparent', 'spouse', 'child', 'sibling', 'friend', 'other' ALTER TABLE books ADD COLUMN storyteller_user_id UUID REFERENCES auth.users(id); ALTER TABLE books ADD COLUMN storyteller_email VARCHAR(255); ALTER TABLE books ADD COLUMN storyteller_phone VARCHAR(50); ALTER TABLE books ADD COLUMN storyteller_notes TEXT; -- Add gift fields (from campaigns) ALTER TABLE books ADD COLUMN is_gift BOOLEAN DEFAULT FALSE; ALTER TABLE books ADD COLUMN gift_message TEXT; ALTER TABLE books ADD COLUMN gift_recipient_name VARCHAR(255); ALTER TABLE books ADD COLUMN gift_recipient_email VARCHAR(255); ALTER TABLE books ADD COLUMN gift_status VARCHAR(50) DEFAULT 'pending'; -- Values: 'pending', 'sent', 'delivered', 'accepted', 'declined' ALTER TABLE books ADD COLUMN gift_delivery_date TIMESTAMP; -- Add project management fields ALTER TABLE books ADD COLUMN project_status VARCHAR(50) DEFAULT 'setup'; -- Values: 'setup', 'collecting', 'editing', 'designing', 'ready', 'published' ALTER TABLE books ADD COLUMN setup_step VARCHAR(50) DEFAULT 'template'; ALTER TABLE books ADD COLUMN setup_progress JSONB DEFAULT '{}'; ALTER TABLE books ADD COLUMN goal_stories INTEGER DEFAULT 10; ALTER TABLE books ADD COLUMN completed_stories INTEGER DEFAULT 0; -- Add notification settings ALTER TABLE books ADD COLUMN prompt_frequency VARCHAR(50) DEFAULT 'weekly'; -- Values: 'daily', 'weekly', 'biweekly', 'monthly', 'manual' ALTER TABLE books ADD COLUMN notification_settings JSONB DEFAULT '{ "email_enabled": true, "sms_enabled": false, "push_enabled": false, "reminder_day": "sunday", "reminder_time": "10:00" }'; -- Add creator relationship ALTER TABLE books ADD COLUMN creator_relationship VARCHAR(100); -- Values: 'self', 'family_member', 'gift_giver', 'collaborator'

3.2 Update stories Table

-- Add book_id column (will replace campaign_id) ALTER TABLE stories ADD COLUMN book_id UUID REFERENCES books(id); -- Create index for performance CREATE INDEX idx_stories_book_id ON stories(book_id); -- Update check constraint to require one of book_id or campaign_id (transition) -- Eventually remove campaign_id requirement

3.3 Deprecation Plan for campaigns Table

Phase 1: Add new columns to books, support both Phase 2: Migrate existing data (if any production data exists) Phase 3: Update all code to use books Phase 4: Drop campaigns table

Since this is a new app, we can skip phases 1-2 and go directly to the new schema.

3.4 RLS Policy Updates

-- Books: Users can see their own books or family-shared books CREATE POLICY "Users can view own and family books" ON books FOR SELECT USING ( user_id = auth.uid() OR family_group_id IN ( SELECT family_group_id FROM family_members WHERE user_id = auth.uid() ) ); -- Stories: Users can see stories in books they can access CREATE POLICY "Users can view stories in accessible books" ON stories FOR SELECT USING ( user_id = auth.uid() OR book_id IN ( SELECT id FROM books WHERE user_id = auth.uid() OR family_group_id IN ( SELECT family_group_id FROM family_members WHERE user_id = auth.uid() ) ) ); -- Family members can edit based on permissions CREATE POLICY "Family members can edit with permission" ON stories FOR UPDATE USING ( user_id = auth.uid() OR book_id IN ( SELECT book_id FROM family_book_permissions WHERE family_group_id IN ( SELECT family_group_id FROM family_members WHERE user_id = auth.uid() ) AND auth.uid() = ANY(can_edit_members) ) );

4. Frontend Route Changes

4.1 Route Removal (campaigns β†’ books)

Old RouteNew RouteAction
/campaigns/booksRedirect
/campaigns/create/books/newMerge wizard
/campaigns/[id]/books/[id]Enhance book dashboard
/campaigns/[id]/stories/books/[id]/storiesMove
/campaigns/[id]/stories/new/books/[id]/stories/newMove
/campaigns/[id]/stories/[id]/books/[id]/stories/[id]Move
/campaigns/[id]/stories/[id]/edit/books/[id]/stories/[id]/editMove
/campaigns/[id]/ai/voice/books/[id]/recordVoice recording hub (book-scoped)
/campaigns/[id]/ai/photo/books/[id]/conversationsAI conversation hub (book-scoped)
/campaigns/[id]/import/voice/books/[id]/importContent import

4.2 New Required Routes

/books/[id]/stories β†’ Stories list (chapters) /books/[id]/stories/new β†’ Create story with template prompts /books/[id]/stories/[sid] β†’ View story in book context /books/[id]/stories/[sid]/edit β†’ Edit story (uses EnhancedEditorShell) /books/[id]/record β†’ Voice recording hub (book-scoped for RAG) /books/[id]/conversations β†’ AI conversation hub (book-scoped for RAG) /books/[id]/import β†’ Import content /books/[id]/settings β†’ Project settings /books/[id]/share β†’ Sharing & family permissions

Why book-scoped? Recording and AI conversations are scoped to a specific book so the RAG system can use the book’s existing stories as context. This provides more relevant AI suggestions and maintains conversational continuity.


5. Component Migration

5.1 Campaign Components to Migrate

ComponentActionNotes
Step0RoleSelection.tsxMerge into book wizardCreator relationship
Step1.tsx (Storyteller info)Merge into book wizardStoryteller details
Step2.tsx (Template)Already exists in booksTemplate selection
Step3.tsx (Goals)Merge into book wizardStory goals
Step4.tsx (Schedule)Merge into book wizardNotification settings
Step5.tsx (Review)Merge into book wizardReview step
GiftDetailsStep.tsxMerge into book wizardGift flow
GiftMessageStep.tsxMerge into book wizardGift message
PaymentStep.tsxKeep separatePayment flow
FamilyMembersStep.tsxMerge/enhanceFamily invitation
InfoStep.tsxReview and mergeAdditional info

5.2 Book Wizard Enhancement

The enhanced book creation wizard will have these steps:

Step 1: Choose Your Path - "I'm writing my own story" (self) - "I'm capturing someone else's story" (family member) - "I'm giving this as a gift" (gift) Step 2: About the Storyteller (if not self) - Name - Relationship to you - Contact info (optional) Step 3: Choose a Template - Template gallery - Template preview - Chapter/prompt preview Step 4: Book Details - Title - Description - Cover style preference Step 5: Set Your Goals - Number of stories - Target completion date Step 6: Reminders (optional) - Frequency - Method (email/SMS) Step 7: Review & Start - Summary - Start collecting stories button

5.3 Shared Components

These components work for both books and stories and need no changes:

  • EnhancedEditorShell.tsx - Rich text editor
  • VoiceRecordingInterface.tsx - Voice capture
  • AIAssistant.tsx - AI features
  • ConfirmationModal.tsx - Confirmations
  • Toast.tsx - Notifications

6. Family Access Model

6.1 Access Levels

LevelCan ViewCan CommentCan EditCan DeleteCan Invite
OwnerYesYesYesYesYes
EditorYesYesYesNoNo
ContributorYesYesOwn onlyOwn onlyNo
ViewerYesNoNoNoNo

6.2 Family Book Sharing Flow

1. Owner creates book β†’ Assigned to family_group_id (optional) 2. Owner shares with family: - Click "Share" button - Select family members - Choose permission level (viewer/contributor/editor) - Send invitation 3. Family member receives: - Email notification - In-app notification - Book appears in their "Shared with Me" section 4. Family member can: - View book and stories - Add their own stories (if contributor+) - Edit any story (if editor) - See real-time updates

6.3 Storyteller vs Creator

ScenarioCreatorStorytellerAccess
Writing own memoirUser AUser AFull
Capturing parent’s storyUser AUser A’s parentCreator: Full, Storyteller: View
Storyteller has accountUser AUser BBoth can edit
Gift bookUser A (gift giver)User B (recipient)Recipient becomes owner

6.4 Database Support

-- Family book permissions already exist -- family_book_permissions.can_edit_members[] -- family_book_permissions.can_contribute_members[] -- family_book_permissions.can_comment_members[] -- Add visibility levels ALTER TABLE family_book_permissions ADD CONSTRAINT check_visibility CHECK (visibility IN ('private', 'family', 'public'));

7. Onboarding Flow Design

7.1 First-Time User Journey

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Welcome Screen β”‚ β”‚ β”‚ β”‚ "Ready to preserve your story?" β”‚ β”‚ β”‚ β”‚ [Start My First Book] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Who is this book for? β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Myself β”‚ β”‚ A Family β”‚ β”‚ A Gift β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Member β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ "I want to β”‚ β”‚ "I want to β”‚ β”‚ "I want to β”‚ β”‚ β”‚ β”‚ write my β”‚ β”‚ capture my β”‚ β”‚ give the β”‚ β”‚ β”‚ β”‚ own story" β”‚ β”‚ parent's or β”‚ β”‚ gift of β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ grandparent's β”‚ β”‚ memories" β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ memories" β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Choose Your Template β”‚ β”‚ β”‚ β”‚ Templates provide structure and prompts to guide your β”‚ β”‚ storytelling. Choose one that fits your book's purpose. β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Life β”‚ β”‚ Family β”‚ β”‚ War & β”‚ β”‚ Custom β”‚ β”‚ β”‚ β”‚ Story β”‚ β”‚ History β”‚ β”‚ Service β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ Selected: Life Story Memoir β”‚ β”‚ - 12 chapters covering childhood to present β”‚ β”‚ - 50+ guided prompts β”‚ β”‚ - Photo integration β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Give Your Book a Title β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Mom's Life Story β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ You can always change this later. β”‚ β”‚ β”‚ β”‚ [Continue] β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ You're All Set! β”‚ β”‚ β”‚ β”‚ Your book "Mom's Life Story" is ready. β”‚ β”‚ β”‚ β”‚ What would you like to do first? β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ πŸ“ Write a Story β”‚ β”‚ πŸŽ™οΈ Record a Story β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ Use our guided β”‚ β”‚ Speak your memories β”‚ β”‚ β”‚ β”‚ prompts to write β”‚ β”‚ and we'll transcribe β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ πŸ“š View Prompts β”‚ β”‚ βš™οΈ Book Settings β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ See all the β”‚ β”‚ Customize your β”‚ β”‚ β”‚ β”‚ template prompts β”‚ β”‚ book settings β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

7.2 Template-Informed Prompts

When user creates a new story, the template provides relevant prompts:

Template: "Life Story Memoir" Chapter: "Early Childhood" Suggested Prompts: 1. "What is your earliest memory?" 2. "Where did you grow up? Describe your childhood home." 3. "Who were the most important people in your early life?" 4. "What games did you play as a child?" 5. "What was your neighborhood like?" [Choose a prompt] or [Write freely]

8. User Journey Scenarios

8.1 Scenario A: Solo Memoir Writer

User: Sarah, 68, writing her own life story

1. Creates account 2. Starts first book: "I'm writing my own story" 3. Chooses "Life Story Memoir" template 4. Titles it "My Journey" 5. Sees template prompts organized by life stage 6. Writes first story: "My Childhood Home" 7. Story automatically becomes Chapter 1 8. Continues adding stories over weeks 9. When ready, designs cover and publishes

Key Points:

  • storyteller_user_id = user_id (same person)
  • creator_relationship = β€˜self’
  • Template prompts guide her writing

8.2 Scenario B: Family Historian

User: Mike, 45, capturing his mom’s stories

1. Creates account 2. Starts first book: "I'm capturing someone else's story" 3. Enters mom's info: "Helen", relationship: "parent" 4. Chooses "Family History" template 5. Invites mom to view/contribute (optional) 6. Records voice interviews with mom 7. Transcriptions become stories/chapters 8. Mike edits and organizes 9. Shares with siblings for contributions 10. Publishes as family keepsake

Key Points:

  • user_id = Mike
  • storyteller_name = β€œHelen”
  • storyteller_relationship = β€˜parent’
  • storyteller_user_id = Mom’s user ID (if she joins)
  • Family sharing enables sibling contributions

8.3 Scenario C: Gift Giver

User: Lisa, giving a memory book to her dad

1. Creates account 2. Starts first book: "I'm giving this as a gift" 3. Enters dad's info as recipient 4. Chooses "Life Story" template 5. Optionally pre-seeds with a few prompts/stories 6. Adds gift message 7. Purchases at checkout 8. Dad receives gift, creates account 9. Ownership transfers to dad 10. Dad continues adding stories 11. Lisa becomes a "contributor" if dad allows

Key Points:

  • is_gift = true
  • gift_recipient_name, gift_recipient_email
  • gift_status tracks delivery
  • Ownership transfer on acceptance

8.4 Scenario D: Collaborative Family Project

User: The Johnson family creating a multi-generational book

1. Grandma starts book: "Johnson Family History" 2. Shares with children and grandchildren 3. Each family member: - Adds their own stories - Comments on others' stories - Uploads photos 4. Grandma (owner) organizes chapters 5. Family votes on cover design 6. Published as family heirloom

Key Points:

  • family_group_id links all members
  • family_book_permissions controls access
  • Multiple contributors, one owner
  • Version history tracks changes

8.5 Scenario E: Switching Templates Mid-Project

User: John started with β€œQuick Memoir” but wants more structure

1. John has 5 stories written 2. Goes to Book Settings 3. Clicks "Change Template" 4. Sees warning: "Your existing stories will be preserved" 5. Selects "Life Story Memoir" 6. System suggests: "These existing stories might fit these chapters..." 7. John confirms mapping 8. New prompts become available 9. Existing content preserved, just reorganized

Key Points:

  • Template change doesn’t delete content
  • AI suggests story-to-chapter mapping
  • User confirms changes

9. API Changes

9.1 New/Modified Endpoints

// Book CRUD (enhanced) POST /api/books // Create book with all new fields GET /api/books // List user's books + family shared GET /api/books/:id // Get book with storyteller info PATCH /api/books/:id // Update book DELETE /api/books/:id // Delete book // Stories now under books POST /api/books/:id/stories // Create story for book GET /api/books/:id/stories // List book's stories GET /api/books/:id/stories/:sid // Get story PATCH /api/books/:id/stories/:sid // Update story DELETE /api/books/:id/stories/:sid // Delete story // Template prompts GET /api/books/:id/prompts // Get template prompts for book GET /api/books/:id/prompts/:pid // Get specific prompt // Family sharing POST /api/books/:id/share // Share book with family GET /api/books/:id/permissions // Get sharing permissions PATCH /api/books/:id/permissions // Update permissions // Gift flow POST /api/books/:id/gift/send // Send gift POST /api/books/:id/gift/accept // Accept gift GET /api/gifts/received // List received gifts // Voice recording (moved) POST /api/books/:id/recordings // Upload recording GET /api/books/:id/recordings // List recordings // Story duplication (NEW) POST /api/stories/:id/duplicate // Duplicate story to another book // Body: { target_book_id: string } // Creates a copy with new ID, linked to target book

9.2 Type Definitions

// Enhanced Book type interface Book { id: string; user_id: string; // Basic info title: string; subtitle?: string; description?: string; // Storyteller info (NEW) storyteller_name?: string; storyteller_relationship?: 'self' | 'parent' | 'grandparent' | 'spouse' | 'child' | 'sibling' | 'friend' | 'other'; storyteller_user_id?: string; storyteller_email?: string; storyteller_phone?: string; storyteller_notes?: string; // Creator info (NEW) creator_relationship: 'self' | 'family_member' | 'gift_giver' | 'collaborator'; // Template & Content template_id?: string; story_ids: string[]; goal_stories: number; completed_stories: number; // Project status (NEW) project_status: 'setup' | 'collecting' | 'editing' | 'designing' | 'ready' | 'published'; setup_step?: string; setup_progress?: Record<string, any>; // Notifications (NEW) prompt_frequency: 'daily' | 'weekly' | 'biweekly' | 'monthly' | 'manual'; notification_settings?: { email_enabled: boolean; sms_enabled: boolean; push_enabled: boolean; reminder_day?: string; reminder_time?: string; }; // Gift (NEW) is_gift: boolean; gift_message?: string; gift_recipient_name?: string; gift_recipient_email?: string; gift_status?: 'pending' | 'sent' | 'delivered' | 'accepted' | 'declined'; gift_delivery_date?: string; // Family family_group_id?: string; // Publishing author_name: string; contributor_names: string[]; // ... existing publishing fields created_at: string; updated_at: string; } // Updated Story type interface Story { id: string; book_id: string; // NEW - replaces campaign_id user_id: string; title: string; content: string; prompt?: string; // Which template prompt was used // Derived from books.story_ids index chapter_number?: number; word_count: number; status: 'draft' | 'reviewed' | 'approved' | 'published'; // ... existing fields }

9.5 Placeholder Stories Feature (NEW)

When a user selects a template, the system automatically creates placeholder stories based on the template structure. This gives users a head start and shows them what the finished book could look like.

How It Works

User selects "Life Story Memoir" template ↓ System creates book with: - title: "[Storyteller's Name]'s Life Story" - template_id: "life-story-memoir" - story_ids: [] (initially empty) ↓ System creates placeholder stories: - "Early Childhood" (placeholder, status: 'placeholder') - "Growing Up" (placeholder) - "School Years" (placeholder) - "First Job" (placeholder) - ... (based on template chapters) ↓ User sees book with placeholder chapters Can click any to start writing/recording

Placeholder Story Schema

interface Story { // ... existing fields // NEW: Placeholder support is_placeholder: boolean; // True for auto-created placeholders placeholder_prompt?: string; // The template prompt for this placeholder template_chapter_index?: number; // Position in template }

Database Changes

-- Add placeholder fields to stories ALTER TABLE stories ADD COLUMN is_placeholder BOOLEAN DEFAULT FALSE; ALTER TABLE stories ADD COLUMN placeholder_prompt TEXT; ALTER TABLE stories ADD COLUMN template_chapter_index INTEGER;

Placeholder Story Behavior

StateDisplayActions
is_placeholder = true, empty contentShows as β€œStart this chapter” cardClick to edit, auto-removes placeholder flag
is_placeholder = true, has contentShows as draftContinue editing
is_placeholder = falseNormal storyFull editing

User Can:

  • Keep placeholder and fill it in
  • Remove unwanted placeholders
  • Reorder placeholders
  • Add custom stories between placeholders

9.6 Story Duplication Feature (NEW)

Stories can be duplicated to other books. This is simpler than sharing/linking and gives users full control.

Use Cases

  1. Reuse content: User has a great story in Book A, wants it in Book B too
  2. Templates: Create a β€œmaster” story and duplicate as starting point
  3. Family sharing: Duplicate a story to include in a relative’s book

Duplication Flow

User viewing Story A in Book X ↓ Clicks "Duplicate to another book" ↓ Modal shows list of user's other books ↓ User selects Book Y ↓ System creates Story A' in Book Y: - New UUID - Same title (with " (Copy)" suffix, optional) - Same content - Links to Book Y - user_id = current user - is_duplicate = true - source_story_id = Story A's ID ↓ User can now edit Story A' independently

API Endpoint

// POST /api/stories/:id/duplicate interface DuplicateStoryRequest { target_book_id: string; include_copy_suffix?: boolean; // Default: true copy_images?: boolean; // Default: true } interface DuplicateStoryResponse { success: boolean; new_story: Story; message: string; }

Database Changes

-- Track story duplications ALTER TABLE stories ADD COLUMN is_duplicate BOOLEAN DEFAULT FALSE; ALTER TABLE stories ADD COLUMN source_story_id UUID REFERENCES stories(id); -- Index for finding duplicates CREATE INDEX idx_stories_source ON stories(source_story_id) WHERE source_story_id IS NOT NULL;

Duplicate Behavior

  • Independent: Changes to original don’t affect copy
  • Attribution: Source story ID tracked for reference
  • Images: Optionally copy associated images
  • Permissions: Duplicate inherits permissions from target book

10. Data Migration Strategy

Note: All database migrations will be executed using Supabase MCP tools (apply_migration, execute_sql). No raw SQL files needed.

10.1 For New App (Clean Slate)

Since this is a new app without production data:

  1. Drop campaigns table via Supabase MCP (after ensuring no dependencies)
  2. Enhance books table with new columns via apply_migration
  3. Update stories table to use book_id via apply_migration
  4. Remove campaign_id from all tables
  5. Update all RLS policies via apply_migration

All schema changes will be applied directly to production using the MCP tools rather than creating local migration files.

10.2 If Migration Needed (Future Reference)

-- Step 1: Add new columns to books -- (SQL from section 3.1) -- Step 2: Copy data from campaigns to books INSERT INTO books ( id, user_id, title, description, storyteller_name, storyteller_relationship, storyteller_user_id, storyteller_email, storyteller_phone, storyteller_notes, template_id, goal_stories, is_gift, gift_message, gift_recipient_name, gift_recipient_email, gift_status, gift_delivery_date, project_status, setup_step, setup_progress, prompt_frequency, notification_settings, family_group_id ) SELECT gen_random_uuid(), creator_id, title, description, storyteller_name, user_role, storyteller_user_id, storyteller_email, storyteller_phone, storyteller_notes, template_id, goal_stories, is_gift, gift_message, gift_recipient_name, gift_recipient_email, gift_status, gift_delivery_date, status, setup_step, setup_progress, prompt_frequency, '{"email_enabled": true}'::jsonb, family_group_id FROM campaigns; -- Step 3: Update stories to reference new books UPDATE stories s SET book_id = ( SELECT b.id FROM books b JOIN campaigns c ON b.title = c.title AND b.user_id = c.creator_id WHERE c.id = s.campaign_id ) WHERE s.campaign_id IS NOT NULL; -- Step 4: Drop campaign_id from stories ALTER TABLE stories DROP COLUMN campaign_id; -- Step 5: Drop campaigns table DROP TABLE campaigns CASCADE;

11. Risk Analysis

11.1 Technical Risks

RiskImpactLikelihoodMitigation
Breaking existing featuresHighMediumComprehensive testing
RLS policy errorsHighMediumTest each scenario
Missing edge casesMediumMediumUser journey testing
Performance degradationMediumLowIndex optimization

11.2 UX Risks

RiskImpactLikelihoodMitigation
Confusion with new termsMediumMediumClear onboarding
Lost user mental modelMediumLowGradual transition
Feature discovery issuesLowMediumGuided tours

11.3 Business Risks

RiskImpactLikelihoodMitigation
Longer onboardingLowMediumStreamlined wizard
Gift flow complexityMediumLowDedicated flow

12. Implementation Phases

Phase 1: Database Schema (Week 1)

  • Add new columns to books table
  • Add book_id to stories table
  • Create new indexes
  • Update RLS policies
  • Drop campaigns table (if no data)

Phase 2: Core API (Week 1-2)

  • Update book CRUD endpoints
  • Update story endpoints for book_id
  • Add template prompt endpoints
  • Add sharing/permission endpoints
  • Deprecate campaign endpoints

Phase 3: Book Creation Wizard (Week 2-3)

  • Create new wizard steps
  • Merge campaign wizard logic
  • Implement template-first flow
  • Add storyteller info capture
  • Add gift flow integration
  • Implement placeholder stories auto-creation

Phase 4: Story Management (Week 3)

  • Move /campaigns/[id]/stories to /books/[id]/stories
  • Update story creation with book context
  • Add template prompt integration
  • Update EnhancedEditorShell for book context
  • Add story duplication feature
  • Add placeholder story UI (empty state cards)

Phase 5: Family Features (Week 4)

  • Implement sharing UI
  • Add permission management
  • Create β€œShared with Me” view
  • Add family activity feed

Phase 6: Polish & Testing (Week 4-5)

  • Add route redirects
  • Comprehensive testing
  • Performance optimization
  • Documentation update

Appendix A: Design Decisions (RESOLVED)

All key decisions have been made. See β€œDesign Decisions” table at the top of this document.

#QuestionDecisionImplementation Notes
1UI TerminologyBookSimple, intuitive. No β€œProject” suffix needed.
2Template ChangeAllowedPreserve content, show warning, suggest story→chapter mapping
3Gift Auto-AddYesGiver becomes contributor when recipient accepts
4Voice RecordingBook-scopedRecording hub at /books/[id]/record - context for RAG
5AI ConversationsBook-scopedConversations hub at /books/[id]/conversations - RAG context
6AI PromptsTemplate-specificEach template provides its own prompt set
7Story SharingDuplicate onlyNo linking. Stories copied between books. Simpler.
8Storyteller Auto-LinkYesIf storyteller creates account with matching email
9Family DefaultsWeekly updates ONFamily members get weekly digest by default
10Placeholder StoriesAuto-createdTemplate selection creates placeholder chapters

Appendix B: File Changes Summary

Files to Delete

  • /app/campaigns/* (all 27 files - clean slate, app never live)

Files to Create

  • /app/books/[id]/stories/page.tsx - Story list for book
  • /app/books/[id]/stories/new/page.tsx - Create story in book
  • /app/books/[id]/stories/[sid]/page.tsx - View story
  • /app/books/[id]/stories/[sid]/edit/page.tsx - Edit story
  • /app/books/[id]/record/page.tsx - Voice recording hub (book-scoped)
  • /app/books/[id]/conversations/page.tsx - AI conversation hub (book-scoped)
  • /app/books/[id]/share/page.tsx - Sharing permissions
  • /app/books/[id]/settings/page.tsx - Book settings
  • /app/books/[id]/import/page.tsx - Content import

Files to Modify

  • /app/books/new/page.tsx - Enhanced wizard with template-first flow
  • /app/books/page.tsx - Updated dashboard
  • /app/books/[id]/page.tsx - Book project view
  • /types/books.ts - Updated types with storyteller fields
  • /lib/supabase/* - Updated queries for book_id

Appendix C: RAG Context Architecture

Why Book-Scoped Recording & Conversations?

By scoping voice recordings and AI conversations to a specific book, we enable powerful RAG (Retrieval-Augmented Generation) capabilities:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Book: "Mom's Life Story" β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Stories β”‚ β”‚ Recordings β”‚ β”‚ β”‚ β”‚ - Childhood β”‚ β”‚ - Interview 1 β”‚ β”‚ β”‚ β”‚ - School Years β”‚ β”‚ - Interview 2 β”‚ β”‚ β”‚ β”‚ - First Job β”‚ β”‚ - Photo Review β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ RAG Vector DB β”‚ ← Context for AI β”‚ β”‚ β”‚ (Book-scoped) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ AI Conversation β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ "What else do β”‚ β”‚ β”‚ β”‚ you remember β”‚ ← AI knows this is about β”‚ β”‚ β”‚ about your β”‚ Mom, childhood, her school β”‚ β”‚ β”‚ school days?" β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Benefits

BenefitDescription
Contextual PromptsAI suggests prompts based on what’s already been covered
Continuity”Last time you mentioned X, tell me more about that”
Gap DetectionAI identifies missing chapters from template
DeduplicationAI notices when user repeats a story
PersonalizationUses names, places, dates from existing stories
Better TranscriptionVoice recognition improves with known vocabulary

Implementation Notes

  1. Each book has its own vector embeddings in the RAG database
  2. Recordings are transcribed and indexed per book
  3. AI conversations reference book context for better responses
  4. Templates provide structure, but RAG fills in the details

Technical Implementation

For detailed RAG implementation including schema, API design, and performance analysis, see:

Contextual Memory & RAG Architecture Research

Key decisions from research:

  • Supabase pgvector - Already approved, zero additional cost
  • OpenAI text-embedding-3-small - $0.02/1M tokens, 1536 dimensions
  • HNSW indexes - ~25ms latency at 100K vectors
  • Hybrid search - pg_trgm (keyword) + pgvector (semantic)
  • Database foundation - Already implemented (migrations applied Nov 2024)

Integration with Book-Scoped Architecture: The existing RAG implementation searches across all user content. For book-scoped context:

  1. Add book_id filter to search_unified_context() function
  2. Generate embeddings on story save with book context
  3. Scope memory retrieval to current book’s stories/recordings

Appendix D: Checklist Before Implementation

  • Review and approve this document
  • Confirm no production data in campaigns table
  • Confirm voice/AI editor code is preserved
  • Identify any third-party integrations affected
  • Plan for any scheduled jobs/crons using campaigns
  • Prepare user communication (if existing users)