Goal

Add browser-based persistent storage so conversations survive browser sessions. Students can save their work, close their browser, return later, and continue exactly where they left off.

This stage transforms your basic chat interface into a tool students can actually use over time. Without storage, every browser refresh loses the conversation—not useful for sustained learning. With storage, students build a library of conversations they can revisit and continue.

You'll implement IndexedDB storage (via the LocalForage library), conversation save/load functionality, and a basic conversation list interface.

Before You Begin

Pre-flight checklist:

  1. Stage 1 is complete and working
  2. Review architecture.md sections on "Storage Layer" and conversation object structure
  3. Review testing.md for production testing strategies
  4. Update your TODO list with Stage 2 tasks

Components to Build

1. Storage Manager

A JavaScript module that handles all interactions with browser storage (IndexedDB). This abstracts the complexity of IndexedDB behind simple functions like saveConversation() and loadConversation().

Why it exists: IndexedDB is powerful but complex. A storage manager provides a clean interface for the rest of your code. It also centralizes storage logic—when you add path namespacing in Stage 4, you'll only update this one component.

Key capabilities needed:

2. Conversation Object Structure

A standardized data structure that represents a complete conversation with all necessary metadata.

Why it exists: Consistent structure makes storage, retrieval, and display predictable. As defined in architecture.md, each conversation needs: unique ID, title, timestamps, message array, and metadata.

What it must include:

3. Conversation Management UI

Interface elements that let users save, load, and manage their conversations.

Why it exists: Students need to see what conversations they have, open the ones they want, and delete old ones to make room for new work.

What it must provide:

4. Enhanced Chat Interface

Extend your Stage 1 interface to work with the storage system.

Why it exists: The chat interface needs to know whether it's working with a new conversation or a saved one, and handle both cases appropriately.

What needs to change:

5. Initial AI Greeting

Automatically trigger an AI greeting when a new conversation starts.

Why it exists: Students shouldn't face a blank interface. The AI should initiate the conversation with a welcoming message.

How it works:

Implementation approach:

Implementation Tasks

Update your TODO list with these tasks and track progress as you work.

Set Up Storage Infrastructure

Define Conversation Data Structure

Implement Core Storage Functions

Build Conversation Management UI

Integrate Storage with Chat Interface

Handle Edge Cases

Test the Complete Flow

Success Indicators

When Stage 2 is complete, you should observe these behaviors:

Basic Storage Working

Multiple Conversations

Conversation Management

Data Persistence

User Experience

Testing and Verification

Before proceeding to Stage 3:

  1. Test persistence: Create conversations, close the browser completely, reopen, and verify everything is still there
  2. Test multiple conversations: Create at least 3-5 different conversations and verify they remain independent
  3. Test editing: Load a conversation, add messages, save again, reload, and verify updates persisted
  4. Test deletion: Delete conversations and confirm they're removed from storage
  5. Check browser DevTools: Open Application/Storage tab and inspect IndexedDB to see your conversation data
  6. Test storage limits: Verify behavior if you create many conversations (does your code handle limits gracefully?)

Consult TESTING.md for additional verification strategies and troubleshooting guidance.

What You've Accomplished

With Stage 2 complete, you have:

Students can now use this tool over weeks or months, building up a library of learning conversations they can revisit. This is the point where the application becomes genuinely valuable for educational use.

STOP: Before Proceeding to Stage 3

Do not move forward until:

When Stage 2 is working completely:

  1. Update your TODO list - mark Stage 2 tasks complete, add any notes or learnings
  2. Create a git commit with your working Stage 2 code
  3. Update any other contextual documents you're maintaining
  4. Proceed to stage-3-context.md