Move inactive projects out of active workspace: - bauntown (community website) - maerchenzauber (AI story generation) - memoro (voice memo app) - news (news aggregation) - nutriphi (nutrition tracking) - reader (reading app) - uload (URL shortener) - wisekeep (AI wisdom extraction) Update CLAUDE.md documentation: - Add presi to active projects - Document archived projects section - Update workspace configuration Archived apps can be re-activated by moving back to apps/ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
6.8 KiB
Cards Feature Analysis Report
Date: December 17, 2024
Author: Claude Code Analysis
Status: Feature causing 500 errors on production
Executive Summary
The Cards feature is a complex, multi-layered system that allows users to create customizable profile cards with three different complexity modes (Beginner, Advanced, Expert). The feature is causing 500 errors on the production profile page due to type import issues and potential database field mismatches.
Architecture Overview
1. Core Components Structure
src/lib/components/cards/
├── modules/ # Individual card modules (Header, Content, Footer, etc.)
├── editor/ # Editing interfaces for different modes
├── BaseCard.svelte # Base card component
├── ModularCard.svelte # Beginner mode implementation
├── TemplateCard.svelte # Advanced mode implementation
├── CustomCard.svelte # Expert mode implementation
├── CardRenderer.svelte # Main rendering component
├── CardEditor.svelte # Unified editing interface
└── types.ts # Type definitions
2. Service Layer
src/lib/services/
├── unifiedCardService.ts # Main service for CRUD operations
├── cardValidator.ts # Validation logic
├── cardSanitizer.ts # Security sanitization
├── cardConverter.ts # Mode conversion utilities
└── cardService.ts # Legacy service
Complexity Analysis
High Complexity Areas
-
Three Rendering Modes
- Beginner Mode: Visual module-based builder
- Advanced Mode: Template with variables
- Expert Mode: Direct HTML/CSS editing
-
Type System Complexity
- Uses discriminated unions for different card configurations
- Complex nested types (CardConfig, Module, Theme, etc.)
- Multiple interface hierarchies
-
Database Schema
Card { id: string user_id: relation type: 'user' | 'template' | 'system' config: JSON (complex nested structure) metadata: JSON constraints: JSON page?: string // Optional field causing issues position?: number visibility: 'private' | 'public' | 'unlisted' variant?: string tags?: JSON usage_count?: number likes_count?: number } -
Rendering Pipeline
- CardRenderer determines which component to use based on mode
- Each mode has its own rendering logic
- Dynamic module loading and composition
- CSS-in-JS and template variable substitution
Root Cause Analysis
Primary Issue: Type Import Problem
The 500 error occurs when importing Card type from the complex types system into the server-side profile page loader:
// This import causes issues in production
import type { Card } from '$lib/components/cards/types';
Contributing Factors
-
Database Field Assumptions
- The
pagefield may not exist in all card records - Filter
page="profile"fails on records without this field - PocketBase throws error instead of ignoring missing fields
- The
-
Complex Type Definitions
- The Card type uses discriminated unions
- Server-side rendering may have issues with complex client-side types
- Build process might not properly handle these types in SSR context
-
Service Layer Coupling
- unifiedCardService is tightly coupled to client-side code
- Uses console.log extensively (not ideal for SSR)
- Assumes browser environment in some cases
Why It's Complex
1. Multiple Abstraction Layers
- Database → Service → Component → Renderer
- Each layer adds complexity and potential failure points
2. Mode Flexibility
- Supporting three different editing modes requires:
- Different data structures
- Different validation rules
- Different rendering pipelines
- Different sanitization strategies
3. Security Considerations
- HTML/CSS sanitization for expert mode
- XSS prevention
- Template variable injection safety
- User-generated content handling
4. State Management
- Cards can be in different states (draft, published, template)
- Position and visibility management
- Cross-mode conversion support
Recommended Solutions
Immediate Fix (Implemented)
// Remove Card type import
// Use simple object structure instead
const cards = { items: [] };
Long-term Solutions
-
Simplify Type System
- Create server-safe type definitions
- Separate client and server types
- Use simpler data structures for SSR
-
Database Schema Update
- Make
pagefield required with default value - Add database migrations for existing records
- Create indexes for common queries
- Make
-
Service Layer Refactoring
- Create separate server-side card service
- Remove console.log statements
- Add proper error boundaries
-
Progressive Enhancement
- Load cards via client-side API call
- Use skeleton loaders during fetch
- Implement proper error states
Performance Impact
- Bundle Size: Card system adds ~56KB to build
- Database Queries: Multiple queries per card (clicks, stats)
- Rendering Cost: Complex component tree per card
- Type Checking: Extensive validation on create/update
Technical Debt
- Legacy cardService.ts still exists alongside unifiedCardService
- No proper testing for card conversion between modes
- Missing documentation for module development
- Inconsistent error handling across services
- No caching strategy for frequently accessed cards
Recommendations
Short Term
- ✅ Disable cards on profile page (completed)
- Fix type imports for SSR compatibility
- Add proper error handling for missing fields
- Implement client-side card loading
Medium Term
- Refactor service layer for SSR compatibility
- Simplify type system
- Add comprehensive testing
- Implement caching strategy
Long Term
- Consider reducing to two modes (Simple/Advanced)
- Migrate to simpler data structure
- Implement proper module plugin system
- Add visual card builder improvements
Conclusion
The Cards feature is a sophisticated but overly complex system that attempts to serve multiple use cases (beginner to expert) in a single implementation. The complexity has led to brittleness, particularly in SSR contexts. The immediate fix of disabling cards on the profile page is appropriate, but the feature needs significant refactoring to be production-ready.
The main lesson: Start simple, add complexity only when proven necessary. The three-mode system might be over-engineered for the actual user needs.
Metrics
- Files involved: 17+ components, 5+ services
- Lines of code: ~3000+ lines
- Type definitions: 20+ interfaces/types
- Database fields: 15+ fields per card
- Complexity score: High (Cyclomatic complexity > 20 in key functions)
End of Report