8e95004022
Mirror to GitHub / mirror (push) Successful in 38s
Test and Lint / backend-test (push) Successful in 1m21s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m24s
Version and Release / version-bump (push) Successful in 1m1s
Version and Release / trigger-drone (push) Successful in 4s
- Fix backend analytics to include both 'download' and 'download_all' actions - Add Analytics tab to Settings page for Umami configuration - Update public settings endpoint to expose Umami config when enabled - Implement dynamic Umami initialization from backend settings - Fix frontend analytics calculations (remove hardcoded estimations) - Add proper download counts and unique visitor tracking - Update CLAUDE.md with production safety guidelines The analytics dashboard now shows accurate data for all metrics, and Umami can be configured through the admin panel instead of environment variables. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
12 KiB
12 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Product Overview
A secure photo sharing platform designed for weddings and events, enabling photographers to share time-limited, password-protected galleries. The platform features automatic expiration, archiving, and a scrappbook.de-inspired modern, minimalist UI.
Architecture Overview
- Backend: Node.js/Express API with SQLite/PostgreSQL, file-based photo storage
- Frontend: React SPA with scrappbook.de-style design (requires implementation)
- Storage: File-based with active/archived separation
- Services: Background workers for email, archiving, file watching, and expiration monitoring
- Analytics: Umami integration for engagement tracking
Essential Commands
Backend Development
cd backend
npm install # Install dependencies
npm run migrate # Initialize database schema
npm run dev # Start with hot-reload (port 3001)
npm test # Run Jest tests
npm run lint # ESLint checks
Running a Single Test
cd backend
npm test -- path/to/test.test.js
npm test -- --testNamePattern="test name"
Production
docker-compose -f docker-compose.prod.yml up -d # Production deployment
pm2 start ecosystem.config.js # Alternative: PM2 deployment
⚠️ CRITICAL PRODUCTION NOTICE:
- Production runs on a SEPARATE SERVER - never assume local changes affect production
- ALWAYS request production server details before any troubleshooting
- NO trial-and-error approaches in production - data loss is unacceptable
- Every change must be thoroughly analyzed and tested locally first
Key Product Requirements (from PRD)
Core Features
- File-Based System: Drop photos in folders → automatic gallery creation
- Automatic Expiration: Default 30 days, with 7-day warning emails
- Password Protection: Secure access with customizable passwords
- Automatic Archiving: ZIP compression and storage after expiration
- Email Notifications: Creation, warning, and expiration notifications
- Analytics: Umami tracking for views, downloads, and engagement
Folder Structure
/events/
├── active/
│ ├── wedding-smith-jones-2024-06-15/
│ │ ├── collages/
│ │ └── individual/
│ └── birthday-emma-2024-07-20/
└── archived/
└── wedding-smith-jones-2024-06-15.zip
Frontend Implementation Requirements
Design Style (scrappbook.de-inspired)
- Color Palette: Primary green (#5C8762), neutral backgrounds
- Typography: Clean, modern sans-serif (Noto Sans or similar)
- Layout: Minimalist, modular sections with grid-based photo displays
- Aesthetic: Professional yet approachable, photographer-focused
Key Frontend Components to Build
- Landing Page: Password entry with event preview
- Gallery View:
- Responsive photo grid with lazy loading
- Toggle between collages/individual photos
- Prominent expiration banner
- Download urgency indicators
- Photo Lightbox: Full-screen viewing with zoom
- Mobile-First: Responsive design with touch gestures
- Personalization: Dynamic theming per event type
User Experience Priorities
- Clear expiration warnings (sticky banner)
- One-click "Download All" for urgent galleries
- Smooth image loading with skeleton screens
- Intuitive navigation between photo categories
- Professional presentation matching photographer branding
Key Architecture Patterns
Authentication Flow
- JWT-based with separate tokens for admin and gallery access
- Gallery tokens include event-specific claims
- Auth middleware:
backend/src/middleware/auth.jsadminAuth- Admin panel protectionphotoAuth- Protected photo accessverifyGalleryAccess- Gallery-specific validation
Database Schema (Knex/SQLite)
Main tables:
events- Gallery metadata with expiration, custom messages, themesphotos- Photo records linked to eventsaccess_logs- IP-based usage trackingemail_queue- Async email processingadmin_users- Admin authentication
Service Architecture
Background services run as separate processes:
- emailService: Processes email queue with retry logic
- archiveService: Creates ZIP archives of expired events
- expirationChecker: Cron job for expiration warnings
- fileWatcher: Monitors for new photo uploads
API Structure
/api/admin/*- Admin panel endpoints (requires adminAuth)/api/gallery/*- Public gallery endpoints/api/auth/*- Authentication endpoints- Rate limiting: 100 req/15min (general), 5 req/15min (auth)
Critical Implementation Notes
- Security: All gallery access requires valid JWT with event-specific claims
- Expiration: Events auto-expire based on
expires_at, with 7-day email warnings - Email Queue: Async processing with retry logic, check
email_queuetable - File Processing: Sharp library for thumbnail generation (300x300)
- Frontend Status: Only skeleton exists - requires full implementation based on PRD
- Umami Analytics: Track password entries, downloads, views, expiration warnings
Troubleshooting Guidelines
Before ANY Production Troubleshooting:
-
ALWAYS request specific details:
- Production server URL/IP
- Current error messages/logs
- Recent changes or deployments
- Affected users/galleries
- Time of issue occurrence
-
Thorough Analysis Required:
- Use detailed thinking/analysis for EVERY troubleshooting task
- Review all related code before suggesting changes
- Consider all potential side effects
- Never make assumptions about production environment
-
Safe Troubleshooting Steps:
- First, reproduce issue in local/dev environment
- Analyze logs without modifying production
- Create detailed action plan before any changes
- Always have rollback strategy ready
- Document every step taken
Common Issues & Safe Approaches:
- Email not sending: Check email_queue table, SMTP settings, service status
- Photos not loading: Verify file permissions, storage paths, nginx config
- Gallery access issues: Check JWT tokens, expiration dates, access_logs
- Performance problems: Analyze with monitoring tools first, never experiment
Data Safety Rules:
- NEVER delete or modify production data without explicit backup confirmation
- ALWAYS verify backups exist before any data operations
- NO direct database modifications without transaction safety
- Log all actions for audit trail
Environment Variables
Backend (.env)
JWT_SECRET- Token signingADMIN_URL,FRONTEND_URL- CORS originsSMTP_*- Email configurationDB_*- PostgreSQL credentials (production)UMAMI_URL- Umami instance URL (for server-side tracking)UMAMI_WEBSITE_ID- Website ID from Umami
Frontend (.env)
VITE_API_URL- Backend API URLVITE_UMAMI_URL- Umami analytics URLVITE_UMAMI_WEBSITE_ID- Website ID from UmamiVITE_UMAMI_SHARE_URL- (Optional) Public share URL for embedded dashboard
Testing Approach
- Jest with Supertest for API testing
- Test files in
__tests__directories - Database migrations run before tests
- Mock email sending in tests
Umami Analytics Integration
The frontend includes comprehensive Umami analytics integration for tracking user behavior and gallery performance.
Tracked Events:
- Gallery Events:
gallery_password_entry- Password attempts (success/failure)gallery_photo_view- Individual photo viewsgallery_photo_download- Single photo downloadsgallery_bulk_download- Bulk/all photo downloadsgallery_expired- Expired gallery access attempts
- Admin Events:
admin_login- Admin authenticationadmin_event_created- New event creationadmin_event_archived- Event archivingadmin_event_deleted- Event deletionadmin_settings_updated- Settings changes
- User Behavior:
- Search queries (with debouncing)
- Expiration warning views
- Page views with automatic tracking
Setup:
- Install Umami (self-hosted or cloud)
- Create a website in Umami dashboard
- Set environment variables:
VITE_UMAMI_URL=https://your-umami-instance.com VITE_UMAMI_WEBSITE_ID=your-website-id VITE_UMAMI_SHARE_URL=https://your-umami-instance.com/share/...
Analytics Dashboard:
- Admin panel includes analytics page at
/admin/analytics - Summary view with key metrics
- Option to embed full Umami dashboard
- Real-time event tracking
Accessibility & Performance Features
Accessibility (WCAG 2.1 AA Compliance)
- Error Boundaries: Graceful error handling with recovery options
- Skip Links: Skip to main content for keyboard navigation
- ARIA Labels: Proper labeling for screen readers
- Focus Management: Focus trap in modals, visible focus indicators
- Keyboard Navigation: Full keyboard support in gallery lightbox (arrows, escape, +/-, d for download)
- Loading States: Skeleton screens instead of spinners for better UX
- Offline Support: Visual indicator when offline
- Form Validation: Accessible error messages with aria-describedby
Performance Optimizations
- Lazy Loading: Images load on scroll with Intersection Observer
- Skeleton Screens: Instant visual feedback during loading
- Error Recovery: Component-level error boundaries prevent full page crashes
- Optimistic Updates: Immediate UI updates with background sync
- Debounced Search: Prevents excessive API calls
- Analytics: Non-blocking Umami integration
Component Library Enhancements
<ErrorBoundary>- Catches and displays errors gracefully<PageErrorBoundary>- Full-page error recovery<Skeleton>- Flexible skeleton loader with variants<OfflineIndicator>- Network status monitoring<SkipLink>- Accessibility navigationuseFocusTrap- Modal focus management hookuseOnlineStatus- Network status hook
Theme System & Branding
Theme Features
- Dynamic Theming: CSS variables for runtime theme switching
- Preset Themes: Default, Wedding, Birthday, Corporate, Minimal
- Customization Options:
- Primary/Accent/Background/Text colors
- Font family selection
- Border radius (none, sm, md, lg)
- Custom logo upload
- Custom CSS injection
- Event-Specific Themes: Override global theme per gallery
- Live Preview: Real-time theme changes in admin panel
Theme Context API
const { theme, setTheme, setThemeByName } = useTheme();
Branding Settings
- Company name, tagline, and support email
- Custom footer text
- Optional watermarking on downloads
- Logo upload for gallery header
CSS Variables
--color-primary: #5C8762;
--color-primary-light: #7aa583;
--color-primary-dark: #4a6f4f;
--color-accent: #22c55e;
--color-background: #fafafa;
--color-text: #171717;
--font-family: 'Inter', sans-serif;
--border-radius: 0.5rem;
Success Metrics (from PRD)
- Time to generate gallery: <2 minutes
- Guest satisfaction: >90%
- System uptime: 99.9%
- Email delivery rate: >98%
- Successful archiving: 100%
Documentation & Development Practices
Documentation Guidelines:
- NEVER create new documentation files for simple tasks
- ALWAYS update existing documentation (like this CLAUDE.md)
- Only create new .md files when explicitly requested
- Avoid creating temporary scripts for one-off tasks
Development Best Practices:
- Test all changes thoroughly in local environment first
- Use version control for all changes
- Keep commits atomic and well-described
- Review impact on all integrated services
- Consider backward compatibility
- Update tests when changing functionality
Production Deployment Checklist:
- All tests passing locally
- Linting and type checks pass
- Database migrations tested with rollback plan
- Environment variables documented
- Backup strategy confirmed
- Monitoring alerts configured
- Rollback procedure documented
- Stakeholders notified of maintenance window