` **Visual:** - ⚠️ Muted text might not meet WCAG AA contrast - ❌ No prefers-reduced-motion support - ❌ Focus indicators inconsistent **RTL Support:** - ❌ Noted in TODO as partially implemented - ❌ Inline elements conflict with RTL alignment ### I18n Gaps - ⚠️ Timestamps use locale from state but inconsistently - ❌ Number formatting hardcoded to "en" (zap amounts) - ❌ Kind names are English-only strings - ❌ Error messages hardcoded English - ❌ No language detection for content ### Solutions **Semantic HTML:** ```tsx export function BaseEventContainer({ event, children }) { return ( {relativeTime} {children} ); } ``` **Keyboard Navigation:** ```tsx // Arrow keys to navigate events // Enter to open detail // Escape to close // Tab to focus actions useKeyboardNavigation({ onUp: () => focusPrevEvent(), onDown: () => focusNextEvent(), onEnter: () => openEventDetail(), }); ``` **I18n:** ```tsx import { useTranslation } from 'react-i18next'; export function EventMenu({ event }) { const { t } = useTranslation(); return ( {t('event.actions.copy_id')} ); } ``` --- ## Part 10: Developer Experience ### Current DX **Good:** - ✅ Clear file structure (`src/components/nostr/kinds/`) - ✅ TypeScript types (`BaseEventProps`) - ✅ README documenting pattern - ✅ Consistent naming (`KindXRenderer`) **Friction:** - ❌ Can't hot-reload new renderer without modifying `index.tsx` - ❌ No component gallery (Storybook) - ❌ Hard to test renderers in isolation - ❌ Manual registration in multiple places - ❌ No development tooling (event inspector) - ❌ No renderer generator CLI ### Ideal DX **1. Convention-Based Registration** ```bash # Just create the file, auto-discovered src/components/nostr/kinds/Kind1111Renderer.tsx # No need to modify index.tsx ``` **2. Component Gallery** ```tsx // Visit /dev/renderers in dev mode // Browse all renderers with sample events // Test with different contexts (feed/detail/embed) // Inspect props, performance ``` **3. Testing Utilities** ```tsx import { renderKind, mockEvent } from '@/test/utils'; test('Kind1Renderer displays content', () => { const event = mockEvent({ kind: 1, content: 'Hello' }); const { getByText } = renderKind(1, event); expect(getByText('Hello')).toBeInTheDocument(); }); ``` **4. Generator CLI** ```bash npm run generate:renderer -- --kind 1111 --nip 22 # Scaffolds: # - Kind1111Renderer.tsx with boilerplate # - Kind1111Renderer.test.tsx # - Updates registry # - Adds to documentation ``` **5. Dev Tools** ```tsx // Browser extension or dev panel // Shows: props, state, performance, helper calls, errors ``` --- ## Part 11: What's Working Well (To Preserve) These patterns are **strengths** to maintain and enhance: 1. ✅ **Registry Pattern**: Centralized kind → renderer mapping 2. ✅ **BaseEventContainer**: Consistent header/footer 3. ✅ **Applesauce Integration**: Using library helpers 4. ✅ **Type Safety**: TypeScript interfaces 5. ✅ **Separation of Concerns**: Rendering separate from data fetching 6. ✅ **Recursive Rendering**: KindRenderer can nest 7. ✅ **Universal Actions**: EventMenu available everywhere 8. ✅ **Event Identity**: Good handling of regular vs addressable 9. ✅ **Default Fallback**: Unknown kinds still display 10. ✅ **Component Reuse**: EmbeddedEvent, MediaEmbed, RichText **Don't throw away these foundations - build on them!** --- ## Part 12: Comprehensive Improvement Roadmap ### Phase 1: Foundation Fixes (1-2 weeks) **Goal:** Fix critical architectural issues and quick wins **1.1 Unified Detail Renderer Registry** - Remove hardcoded switch in EventDetailViewer - Create `detailRenderers` map parallel to `kindRenderers` - Fallback logic: detail → feed → default - Files: `src/components/nostr/kinds/index.tsx`, `EventDetailViewer.tsx` - **Impact:** HIGH | **Effort:** LOW **1.2 Systematic Depth Tracking** - Add `MAX_EMBED_DEPTH` constant - Update `BaseEventProps` to require depth - Audit all renderers using `EmbeddedEvent` - Implement `CollapsedPreview` for max depth - Files: All `*Renderer.tsx` files - **Impact:** HIGH | **Effort:** MEDIUM **1.3 Error Boundaries** - Create `EventErrorBoundary` component - Wrap all events in feeds - Add diagnostic error cards - File: `src/components/EventErrorBoundary.tsx` - **Impact:** HIGH | **Effort:** LOW **1.4 Fix JSON Viewer Scrolling** - From TODO: "JSON viewer scrolling" - Add `overflow-auto` and `max-height` to JSON container - File: `src/components/JsonViewer.tsx` - **Impact:** MEDIUM | **Effort:** TRIVIAL **1.5 Renderer Memoization** - Wrap all renderer components with `React.memo` - Add `useMemo` for expensive computations - Add `useCallback` for handlers - Files: All `*Renderer.tsx` files - **Impact:** MEDIUM | **Effort:** LOW **Deliverables:** - [ ] Detail renderer registry implemented - [ ] All renderers honor depth (with tests) - [ ] Error boundaries deployed - [ ] JSON viewer scrolls properly - [ ] All renderers memoized --- ### Phase 2: Component Library (2-3 weeks) **Goal:** Build reusable abstractions for common patterns **2.1 Generic Threading Components** - `getThreadReferences()` helper supporting NIP-10, NIP-22, NIP-28 - `` component - `` for parent preview - `` for detail view reply chains - Files: `src/lib/threading.ts`, `src/components/Thread/` - **Impact:** HIGH | **Effort:** HIGH **2.2 NIP-22 Comment Support** - Implement `Kind1111Renderer` (from TODO) - NIP-22 tag parsing helpers (K/k, E/e, A/a, I/i, P/p) - External identifier display (I tags) - Nested comment threading - Files: `src/lib/helpers/nip22.ts`, `src/components/nostr/kinds/Kind1111Renderer.tsx` - **Impact:** HIGH | **Effort:** HIGH **2.3 Relationship Panels** - `` - Show replies to event - `` - Show zaps with total/list - `` - Group reactions by emoji - `` - Universal engagement indicators - Use in detail renderers - Files: `src/components/nostr/Relationships/` - **Impact:** MEDIUM | **Effort:** MEDIUM **2.4 Enhanced Media Components** - Multi-stage rendering (placeholder → thumbnail → full → error) - Lazy loading with IntersectionObserver - NSFW blur with content-warning tag support - Quality selection for videos - Accessibility improvements (alt text, captions) - Files: Enhance `src/components/nostr/MediaEmbed.tsx` - **Impact:** MEDIUM | **Effort:** MEDIUM **2.5 Context-Aware Rendering** - Add `context` prop to BaseEventProps - Renderers adapt to feed vs detail vs embed - Update all existing renderers - Files: `src/components/nostr/kinds/index.tsx`, all renderers - **Impact:** MEDIUM | **Effort:** LOW **Deliverables:** - [ ] Threading works across NIP-10, NIP-22, NIP-28 - [ ] Kind 1111 (comments) fully functional - [ ] Detail views show relationships - [ ] Media rendering has all stages - [ ] Context awareness implemented --- ### Phase 3: Architecture Evolution (3-4 weeks) **Goal:** Transform into production-grade framework **3.1 Performance Optimization** - Virtual scrolling with react-virtuoso - Code splitting for detail renderers - Batch profile fetching - Suspense boundaries - Performance monitoring - Files: `src/components/ReqViewer.tsx`, `EventDetailViewer.tsx` - **Impact:** HIGH | **Effort:** MEDIUM **3.2 Helper Library Expansion** - Audit all renderers for manual tag parsing - Create helpers for all missing NIPs: - File metadata (1063) - Media events (20, 21, 22) - Lists (30000+) - Reposts (6, 16, 18) - Highlights (9802) - Calendar (31922-31925) - Polls (1068) - Submit generic ones to applesauce-core - Files: `src/lib/helpers/` directory structure - **Impact:** HIGH | **Effort:** HIGH **3.3 Accessibility Improvements** - Semantic HTML (``, ``, proper headings) - ARIA labels and roles - Keyboard navigation system - Focus management - Screen reader testing and fixes - WCAG AA compliance audit - Files: All renderers, BaseEventContainer - **Impact:** MEDIUM | **Effort:** MEDIUM **3.4 Internationalization** - i18next integration - Extract all hardcoded strings - Locale-aware number/date formatting - Kind name translations - RTL support improvements - Files: Setup i18n infrastructure, translate all components - **Impact:** MEDIUM | **Effort:** MEDIUM **3.5 Composable Renderer System** - Break renderers into smaller components: - Content components (primary payload) - Metadata components (structured data) - Relationship components (connections) - Action components (interactions) - Enable mix-and-match composition - Files: Refactor all complex renderers - **Impact:** MEDIUM | **Effort:** HIGH **Deliverables:** - [ ] Smooth 60fps scroll with 10K events - [ ] All NIPs have helper functions - [ ] WCAG AA compliant - [ ] Multi-language support - [ ] Composable renderer architecture --- ### Phase 4: Developer Experience (2-3 weeks) **Goal:** Make development delightful and efficient **4.1 Component Gallery (Storybook)** - Setup Storybook - Create stories for all renderers - Mock event generator - Interactive playground - Visual regression testing - Files: `.storybook/`, `src/components/nostr/kinds/*.stories.tsx` - **Impact:** HIGH | **Effort:** MEDIUM **4.2 Testing Infrastructure** - Test utilities: `renderKind()`, `mockEvent()` - Unit tests for all helpers - Integration tests for renderers - E2E tests for common flows - Coverage targets (>80%) - Files: `src/test/`, `*.test.tsx` for all renderers - **Impact:** HIGH | **Effort:** HIGH **4.3 Generator CLI** - `generate:renderer` command - Scaffolds: renderer, tests, types - Auto-updates registry - Generates documentation stub - Files: `scripts/generate-renderer.ts` - **Impact:** MEDIUM | **Effort:** LOW **4.4 Development Tools** - Event inspector dev panel - Performance profiler - Helper call tracer - Error diagnostic viewer - Files: `src/dev-tools/` - **Impact:** MEDIUM | **Effort:** MEDIUM **4.5 Documentation** - Architecture guide (this document as living docs) - Renderer patterns guide - Helper function reference - Contribution guide - API documentation (TypeDoc) - Files: `docs/` directory - **Impact:** HIGH | **Effort:** MEDIUM **Deliverables:** - [ ] Storybook with all renderers - [ ] >80% test coverage - [ ] Renderer generator working - [ ] Dev tools panel functional - [ ] Comprehensive documentation --- ## Part 13: Success Metrics **Phase 1 Success:** - Zero infinite loop bugs - <1% event rendering errors in production - Detail renderers added without modifying router **Phase 2 Success:** - NIP-22 comments working end-to-end - Detail views show full relationship context - All threading models supported **Phase 3 Success:** - 10K event feed scrolls at 60fps - Zero manual tag parsing in renderers - WCAG AA accessibility audit passes **Phase 4 Success:** - New renderer takes <30min to scaffold - >80% test coverage maintained - Storybook has 100% renderer coverage **Overall Success:** - Contributors can add renderers without asking questions - Users report high quality, responsive UI - Grimoire becomes reference implementation for Nostr clients --- ## Part 14: Priority Decision Matrix **Immediate (Week 1-2):** 1. Detail renderer registry fix 2. Depth tracking safety 3. Error boundaries 4. JSON viewer scroll fix **Short-term (Week 3-6):** 1. NIP-22 comment support (user request in TODO) 2. Threading abstraction 3. Memoization & performance basics 4. Relationship panels **Medium-term (Week 7-12):** 1. Virtual scrolling 2. Helper library expansion 3. Accessibility improvements 4. Component gallery **Long-term (Month 4+):** 1. Plugin architecture 2. Advanced dev tools 3. Full i18n 4. Composable system evolution --- ## Part 15: Risk Assessment **Technical Risks:** - 🟡 **Breaking changes**: Depth prop changes might break existing renderers - *Mitigation:* Make depth optional with default 0, gradual rollout - 🟡 **Performance regression**: Memoization might increase memory - *Mitigation:* Monitor metrics, iterate based on data - 🟢 **Compatibility**: Changes to BaseEventProps might affect community code - *Mitigation:* Keep backward compatibility, deprecate gradually **Resource Risks:** - 🟡 **Time**: 10-12 weeks of focused work - *Mitigation:* Phased approach, can ship incrementally - 🟢 **Expertise**: Some NIPs are complex (NIP-22, NIP-29) - *Mitigation:* Study specifications, prototype early **User Impact:** - 🟢 **Disruption**: Most changes are internal improvements - 🟢 **Testing**: Can test thoroughly in staging before production - 🟢 **Rollback**: Registry pattern makes rollback easy (swap renderers) --- ## Conclusion The Grimoire event rendering system has **excellent foundations** but needs **systematic improvements** to scale from prototype to production. **The path forward:** 1. ✅ **Preserve** what works (registry, base components, type safety) 2. 🔧 **Fix** critical issues (detail registry, depth tracking, error handling) 3. 🏗️ **Build** missing abstractions (threading, relationships, helpers) 4. ⚡ **Optimize** performance (virtualization, memoization, lazy loading) 5. 🎨 **Polish** UX (accessibility, i18n, media rendering) 6. 🛠️ **Empower** developers (tooling, testing, documentation) **This roadmap transforms the system from "working" to "world-class" in ~3 months** with measurable success criteria and manageable risk. The result will be a **reference implementation** that other Nostr clients can learn from and contribute to. --- **Next Steps:** 1. Review this analysis with team/community 2. Prioritize phases based on user feedback 3. Create GitHub issues/project board from roadmap 4. Begin Phase 1 implementation 5. Update TODO.md with prioritized items **Questions for Discussion:** - Which Phase 1 items are most critical? - Should we tackle NIP-22 (comments) in Phase 1 given TODO mention? - What's the community appetite for contributing to applesauce helpers? - Performance targets: 10K events reasonable or aim higher/lower? - Should we build plugin architecture in Phase 3 or defer?
`, ``, proper headings) - ARIA labels and roles - Keyboard navigation system - Focus management - Screen reader testing and fixes - WCAG AA compliance audit - Files: All renderers, BaseEventContainer - **Impact:** MEDIUM | **Effort:** MEDIUM **3.4 Internationalization** - i18next integration - Extract all hardcoded strings - Locale-aware number/date formatting - Kind name translations - RTL support improvements - Files: Setup i18n infrastructure, translate all components - **Impact:** MEDIUM | **Effort:** MEDIUM **3.5 Composable Renderer System** - Break renderers into smaller components: - Content components (primary payload) - Metadata components (structured data) - Relationship components (connections) - Action components (interactions) - Enable mix-and-match composition - Files: Refactor all complex renderers - **Impact:** MEDIUM | **Effort:** HIGH **Deliverables:** - [ ] Smooth 60fps scroll with 10K events - [ ] All NIPs have helper functions - [ ] WCAG AA compliant - [ ] Multi-language support - [ ] Composable renderer architecture --- ### Phase 4: Developer Experience (2-3 weeks) **Goal:** Make development delightful and efficient **4.1 Component Gallery (Storybook)** - Setup Storybook - Create stories for all renderers - Mock event generator - Interactive playground - Visual regression testing - Files: `.storybook/`, `src/components/nostr/kinds/*.stories.tsx` - **Impact:** HIGH | **Effort:** MEDIUM **4.2 Testing Infrastructure** - Test utilities: `renderKind()`, `mockEvent()` - Unit tests for all helpers - Integration tests for renderers - E2E tests for common flows - Coverage targets (>80%) - Files: `src/test/`, `*.test.tsx` for all renderers - **Impact:** HIGH | **Effort:** HIGH **4.3 Generator CLI** - `generate:renderer` command - Scaffolds: renderer, tests, types - Auto-updates registry - Generates documentation stub - Files: `scripts/generate-renderer.ts` - **Impact:** MEDIUM | **Effort:** LOW **4.4 Development Tools** - Event inspector dev panel - Performance profiler - Helper call tracer - Error diagnostic viewer - Files: `src/dev-tools/` - **Impact:** MEDIUM | **Effort:** MEDIUM **4.5 Documentation** - Architecture guide (this document as living docs) - Renderer patterns guide - Helper function reference - Contribution guide - API documentation (TypeDoc) - Files: `docs/` directory - **Impact:** HIGH | **Effort:** MEDIUM **Deliverables:** - [ ] Storybook with all renderers - [ ] >80% test coverage - [ ] Renderer generator working - [ ] Dev tools panel functional - [ ] Comprehensive documentation --- ## Part 13: Success Metrics **Phase 1 Success:** - Zero infinite loop bugs - <1% event rendering errors in production - Detail renderers added without modifying router **Phase 2 Success:** - NIP-22 comments working end-to-end - Detail views show full relationship context - All threading models supported **Phase 3 Success:** - 10K event feed scrolls at 60fps - Zero manual tag parsing in renderers - WCAG AA accessibility audit passes **Phase 4 Success:** - New renderer takes <30min to scaffold - >80% test coverage maintained - Storybook has 100% renderer coverage **Overall Success:** - Contributors can add renderers without asking questions - Users report high quality, responsive UI - Grimoire becomes reference implementation for Nostr clients --- ## Part 14: Priority Decision Matrix **Immediate (Week 1-2):** 1. Detail renderer registry fix 2. Depth tracking safety 3. Error boundaries 4. JSON viewer scroll fix **Short-term (Week 3-6):** 1. NIP-22 comment support (user request in TODO) 2. Threading abstraction 3. Memoization & performance basics 4. Relationship panels **Medium-term (Week 7-12):** 1. Virtual scrolling 2. Helper library expansion 3. Accessibility improvements 4. Component gallery **Long-term (Month 4+):** 1. Plugin architecture 2. Advanced dev tools 3. Full i18n 4. Composable system evolution --- ## Part 15: Risk Assessment **Technical Risks:** - 🟡 **Breaking changes**: Depth prop changes might break existing renderers - *Mitigation:* Make depth optional with default 0, gradual rollout - 🟡 **Performance regression**: Memoization might increase memory - *Mitigation:* Monitor metrics, iterate based on data - 🟢 **Compatibility**: Changes to BaseEventProps might affect community code - *Mitigation:* Keep backward compatibility, deprecate gradually **Resource Risks:** - 🟡 **Time**: 10-12 weeks of focused work - *Mitigation:* Phased approach, can ship incrementally - 🟢 **Expertise**: Some NIPs are complex (NIP-22, NIP-29) - *Mitigation:* Study specifications, prototype early **User Impact:** - 🟢 **Disruption**: Most changes are internal improvements - 🟢 **Testing**: Can test thoroughly in staging before production - 🟢 **Rollback**: Registry pattern makes rollback easy (swap renderers) --- ## Conclusion The Grimoire event rendering system has **excellent foundations** but needs **systematic improvements** to scale from prototype to production. **The path forward:** 1. ✅ **Preserve** what works (registry, base components, type safety) 2. 🔧 **Fix** critical issues (detail registry, depth tracking, error handling) 3. 🏗️ **Build** missing abstractions (threading, relationships, helpers) 4. ⚡ **Optimize** performance (virtualization, memoization, lazy loading) 5. 🎨 **Polish** UX (accessibility, i18n, media rendering) 6. 🛠️ **Empower** developers (tooling, testing, documentation) **This roadmap transforms the system from "working" to "world-class" in ~3 months** with measurable success criteria and manageable risk. The result will be a **reference implementation** that other Nostr clients can learn from and contribute to. --- **Next Steps:** 1. Review this analysis with team/community 2. Prioritize phases based on user feedback 3. Create GitHub issues/project board from roadmap 4. Begin Phase 1 implementation 5. Update TODO.md with prioritized items **Questions for Discussion:** - Which Phase 1 items are most critical? - Should we tackle NIP-22 (comments) in Phase 1 given TODO mention? - What's the community appetite for contributing to applesauce helpers? - Performance targets: 10K events reasonable or aim higher/lower? - Should we build plugin architecture in Phase 3 or defer?