# Technical Specifications - Notebooks & Labels Contextuels **Project:** Keep - Notebooks & Labels Contextuels **Date:** 2026-01-11 **Status:** DRAFT **Author:** Winston (Architect) **Based on:** Architecture Decision Document (validated 2026-01-11) --- ## Table of Contents 1. [Component: NotebooksContext](#1-component-notebooks-context) 2. [Component: NotebooksSidebar](#2-component-notebookssidebar) 3. [Service: ContextualAutoTagService](#3-service-contextualautotagservice) 4. [Service: NotebookSuggestionService](#4-service-notebooksuggestionservice) 5. [Migration: Database Migration Script](#5-migration-database-migration-script) 6. [Server Actions: Notebooks CRUD](#6-server-actions-notebooks-crud) --- ## 1. Component: NotebooksContext **Purpose:** Global state management for notebooks, labels, and current selection **Type:** React Context Provider **Location:** `keep-notes/app/context/notebooks-context.tsx` ### 1.1 TypeScript Interface ```typescript // app/context/notebooks-context.tsx import type { Notebook, Label, Note } from '@/lib/types' /** * Public interface for notebooks context */ export interface NotebooksContextValue { // ===== STATE ===== /** All notebooks for the current user */ notebooks: Notebook[] /** Currently selected notebook (null = Notes générales / Inbox) */ currentNotebook: Notebook | null /** Labels for the currently selected notebook */ currentLabels: Label[] /** Loading state for initial data fetch */ isLoading: boolean /** Error state */ error: string | null // ===== ACTIONS: NOTEBOOKS ===== /** * Create a new notebook with optimistic UI * @param data - Notebook creation data * @returns Promise resolving to created notebook */ createNotebookOptimistic: (data: CreateNotebookInput) => Promise /** * Update an existing notebook * @param notebookId - ID of notebook to update * @param data - Partial update data */ updateNotebook: (notebookId: string, data: UpdateNotebookInput) => Promise /** * Delete a notebook (notes become general) * @param notebookId - ID of notebook to delete */ deleteNotebook: (notebookId: string) => Promise /** * Update the order of notebooks (drag & drop result) * @param notebookIds - Ordered array of notebook IDs */ updateNotebookOrderOptimistic: (notebookIds: string[]) => Promise /** * Set the current notebook (navigation) * @param notebook - Notebook to select (null = general notes) */ setCurrentNotebook: (notebook: Notebook | null) => void // ===== ACTIONS: LABELS ===== /** * Create a label in the current notebook * @param data - Label creation data */ createLabel: (data: CreateLabelInput) => Promise