# Milestone 1.8 — Session Persistence Learning Guide

This directory documents the implementation of **Milestone 1, Step 1.8: Session Persistence using `localStorage`**.

---

## Documents in this folder

- **[01-localstorage-session.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-8-localstorage-session/01-localstorage-session.md)** — Explains `localStorage` persistence, site-scoped storage keys (`chatbot_session_${siteId}`), first visit vs. reload flows, and fallback handling.
- **[02-m1-8-revision.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-8-localstorage-session/02-m1-8-revision.md)** — Short revision summary and top 5 interview Q&As.

---

## How to Verify Milestone 1.8

1. **Build the bundle:**
   ```bash
   cd widget
   npm run build
   ```

2. **Run Backend Server:**
   ```bash
   cd backend
   uvicorn app.main:app --reload --port 8000
   ```

3. **Verify First Visit:**
   Clear browser `localStorage` and open `widget/demo.html` in browser.
   - Console logs: `Widget session initialized & stored: sess_...`.
   - Panel header displays: `Site: site_demo_123 | Session: sess_... (new)`.

4. **Verify Page Reload:**
   Refresh `widget/demo.html`.
   - Console logs: `Widget session restored from localStorage: sess_...`.
   - Panel header displays: `Site: site_demo_123 | Session: sess_... (restored)` with the EXACT same `sessionId`.

---

## What You Should Understand Before Moving to M1.9

- In **Milestone 1.9**, we will wire up the chat message input field and send button to `POST /api/v1/message` to send messages and receive an echo response from the backend!
