# Phase 3: Design System & Advanced Features - Detailplanung ## 🎯 Überblick Phase 3 Phase 3 baut auf der soliden Architektur-Basis von Phase 1+2 auf und verwandelt Worldream in eine professionelle, skalierbare Anwendung mit Enterprise-QualitΓ€t. **Zeitrahmen:** 2-3 Wochen **Fokus:** Design System, Performance, Developer Experience, QualitΓ€t ## πŸ— Teilphasen im Detail ### Phase 3.1: Design System Foundation (Woche 1) #### 3.1.1 Core UI Components (2-3 Tage) **Ziel:** Wiederverwendbare, konsistente UI-Bibliothek **Neue Dateien erstellen:** ``` src/lib/ui/ β”œβ”€β”€ Button/ β”‚ β”œβ”€β”€ Button.svelte # Universal Button Component β”‚ β”œβ”€β”€ Button.types.ts # Button Props Interface β”‚ └── Button.stories.ts # Storybook Stories β”œβ”€β”€ Input/ β”‚ β”œβ”€β”€ Input.svelte # Text Input β”‚ β”œβ”€β”€ Textarea.svelte # Textarea Input β”‚ β”œβ”€β”€ Select.svelte # Select Dropdown β”‚ └── Input.types.ts # Input Props β”œβ”€β”€ Form/ β”‚ β”œβ”€β”€ FormField.svelte # Label + Input + Error β”‚ β”œβ”€β”€ FormSection.svelte # Section mit Titel β”‚ └── Form.svelte # Form Container β”œβ”€β”€ Layout/ β”‚ β”œβ”€β”€ Card.svelte # Content Cards β”‚ β”œβ”€β”€ Modal.svelte # Overlay Modals β”‚ └── Tabs.svelte # Tab Navigation └── index.ts # Barrel Exports ``` **Button.svelte Beispiel:** ```svelte ``` **Migrations-Impact:** - Alle ` {/if} {:else} {@render children?.()} {/if} ``` **Toast Notification System:** ```typescript // src/lib/stores/notifications.ts interface Notification { id: string; type: 'success' | 'error' | 'warning' | 'info'; title: string; message?: string; duration?: number; actions?: { label: string; action: () => void }[]; } export const notifications = (() => { let items = $state([]); return { get items() { return items; }, add(notification: Omit): string { const id = Math.random().toString(36).substring(7); const item = { ...notification, id }; items = [...items, item]; if (notification.duration !== 0) { setTimeout(() => { items = items.filter(n => n.id !== id); }, notification.duration || 5000); } return id; }, remove(id: string): void { items = items.filter(n => n.id !== id); }, clear(): void { items = []; }, // Convenience methods success(title: string, message?: string) { return this.add({ type: 'success', title, message }); }, error(title: string, message?: string) { return this.add({ type: 'error', title, message, duration: 0 }); } }; })(); ``` #### 3.3.2 Advanced State Management (1-2 Tage) **Global State Store Pattern:** ```typescript // src/lib/stores/appStore.ts interface AppState { user: User | null; currentWorld: ContentNode | null; isLoading: boolean; notifications: Notification[]; modals: Modal[]; } export const createAppStore = () => { let state = $state({ user: null, currentWorld: null, isLoading: false, notifications: [], modals: [] }); return { get state() { return state; }, // Actions setUser(user: User | null) { state.user = user; }, setCurrentWorld(world: ContentNode | null) { state.currentWorld = world; if (browser && world) { localStorage.setItem('worldream-current-world', JSON.stringify(world)); } }, setLoading(loading: boolean) { state.isLoading = loading; }, addNotification(notification: Notification) { state.notifications = [...state.notifications, notification]; }, // Derived get isAuthenticated() { return state.user !== null; }, get hasWorldContext() { return state.currentWorld !== null; } }; }; export const appStore = createAppStore(); ``` #### 3.3.3 Testing Infrastructure (2-3 Tage) **Vitest Setup:** ```typescript // vitest.config.ts import { defineConfig } from 'vitest/config'; import { sveltekit } from '@sveltejs/kit/vite'; export default defineConfig({ plugins: [sveltekit()], test: { include: ['src/**/*.{test,spec}.{js,ts}'], environment: 'jsdom', setupFiles: ['src/tests/setup.ts'] } }); ``` **NodeService Tests:** ```typescript // src/lib/services/nodeService.test.ts import { describe, it, expect, vi, beforeEach } from 'vitest'; import { NodeService } from './nodeService'; // Mock fetch global.fetch = vi.fn(); describe('NodeService', () => { beforeEach(() => { vi.resetAllMocks(); }); describe('create', () => { it('should create a new node successfully', async () => { const mockNode = { id: '1', title: 'Test', kind: 'character' }; (fetch as any).mockResolvedValue({ ok: true, json: () => Promise.resolve(mockNode) }); const result = await NodeService.create({ kind: 'character', slug: 'test', title: 'Test', visibility: 'private', tags: [], content: {} }); expect(result).toEqual(mockNode); expect(fetch).toHaveBeenCalledWith('/api/nodes', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ kind: 'character', slug: 'test', title: 'Test', visibility: 'private', tags: [], content: {} }) }); }); it('should throw error on failed request', async () => { (fetch as any).mockResolvedValue({ ok: false, json: () => Promise.resolve({ error: 'Failed to create' }) }); await expect(NodeService.create({} as any)).rejects.toThrow('Failed to create'); }); }); }); ``` **Component Tests:** ```typescript // src/lib/ui/Button/Button.test.ts import { render, fireEvent } from '@testing-library/svelte'; import { describe, it, expect, vi } from 'vitest'; import Button from './Button.svelte'; describe('Button', () => { it('renders with correct text', () => { const { getByText } = render(Button, { props: { children: () => 'Click me' } }); expect(getByText('Click me')).toBeInTheDocument(); }); it('calls onclick handler when clicked', async () => { const handleClick = vi.fn(); const { getByRole } = render(Button, { props: { onclick: handleClick, children: () => 'Click me' } }); await fireEvent.click(getByRole('button')); expect(handleClick).toHaveBeenCalledOnce(); }); it('shows loading state', () => { const { getByText } = render(Button, { props: { loading: true, children: () => 'Submit' } }); expect(getByText('Submit')).toBeInTheDocument(); // Check for spinner expect(document.querySelector('.animate-spin')).toBeInTheDocument(); }); }); ``` ### Phase 3.4: Advanced Features (Woche 3) #### 3.4.1 Advanced Search & Filtering (2-3 Tage) **Smart Search Component:** ```svelte
{#if loading}
{/if}
{#if results.length > 0}
{#each results as result, index} {/each}
{/if}
``` #### 3.4.2 Keyboard Shortcuts System (1-2 Tage) **Global Shortcuts:** ```typescript // src/lib/utils/shortcuts.ts interface Shortcut { key: string; ctrl?: boolean; alt?: boolean; shift?: boolean; action: () => void; description: string; } export const shortcuts = (() => { let registeredShortcuts = new Map(); function getShortcutKey(shortcut: Shortcut): string { const parts = []; if (shortcut.ctrl) parts.push('ctrl'); if (shortcut.alt) parts.push('alt'); if (shortcut.shift) parts.push('shift'); parts.push(shortcut.key.toLowerCase()); return parts.join('+'); } function handleKeydown(e: KeyboardEvent) { const key = getShortcutKey({ key: e.key, ctrl: e.ctrlKey || e.metaKey, alt: e.altKey, shift: e.shiftKey } as Shortcut); const shortcut = registeredShortcuts.get(key); if (shortcut) { e.preventDefault(); shortcut.action(); } } return { register(shortcut: Shortcut): () => void { const key = getShortcutKey(shortcut); registeredShortcuts.set(key, shortcut); if (registeredShortcuts.size === 1) { window.addEventListener('keydown', handleKeydown); } return () => { registeredShortcuts.delete(key); if (registeredShortcuts.size === 0) { window.removeEventListener('keydown', handleKeydown); } }; }, getAll(): Shortcut[] { return Array.from(registeredShortcuts.values()); } }; })(); ``` **Shortcuts Helper Component:** ```svelte {#if showHelp}

Keyboard Shortcuts

{#each allShortcuts as shortcut}
{shortcut.description}
{#if shortcut.ctrl} Ctrl {/if} {#if shortcut.alt} Alt {/if} {#if shortcut.shift} Shift {/if} {shortcut.key}
{/each}
{/if} ``` ## πŸ“Š Phase 3 Erwartete Ergebnisse ### Quantifizierbare Verbesserungen - **Performance:** 40-60% schnellere Ladezeiten - **Bundle Size:** 20-30% kleiner durch Tree-shaking - **Development Speed:** 50% weniger Zeit fΓΌr neue Features - **Bug Rate:** 70% weniger UI-bugs durch Design System - **Accessibility Score:** 95+ Lighthouse Score ### Qualitative Verbesserungen - **User Experience:** Professionelle, konsistente UI - **Developer Experience:** Moderne Tooling & Testing - **Maintainability:** Klare Component-Bibliothek - **Scalability:** Solide Basis fΓΌr komplexe Features ## 🎯 Definition of Done - Phase 3 ### Must Have (Minimal) - [ ] 8+ wiederverwendbare UI Components - [ ] Theme System mit Custom Properties - [ ] NodeForm aufgeteilt in 5+ Sections - [ ] Client-side Caching implementiert - [ ] Error Boundary System - [ ] 80% Test Coverage fΓΌr Services ### Should Have (Optimal) - [ ] Virtual Scrolling fΓΌr alle Listen - [ ] Lazy Image Loading - [ ] Toast Notification System - [ ] Advanced Search mit Keyboard Navigation - [ ] Storybook fΓΌr Component Library - [ ] 90% Test Coverage ### Could Have (Nice-to-have) - [ ] Global Keyboard Shortcuts - [ ] Performance Monitoring - [ ] Advanced Animation System - [ ] Accessibility Features (Screen Reader, etc.) - [ ] Advanced Caching mit Background Sync ## πŸ’° ROI Erwartung Phase 3 ### Entwicklungszeit-Einsparungen - **Neue UI Features:** 70% schneller durch Component Library - **Bug-Fixes:** 60% weniger Zeit durch bessere Testing - **Performance Issues:** 80% weniger durch professionelle Architektur ### Langfristige Vorteile - **Skalierbarkeit:** Enterprise-ready Architecture - **User Retention:** Professionelle UX steigert Zufriedenheit - **Team Onboarding:** Neue Entwickler productive in Tagen statt Wochen - **Technical Debt:** Praktisch eliminiert durch solide Basis --- **Phase 3 verwandelt Worldream von einem funktionalen MVP in eine professionelle, skalierbare Enterprise-Anwendung mit weltklasse Developer Experience.**