1773ed5f95
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m11s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m28s
Version and Release / version-bump (push) Successful in 32s
Version and Release / trigger-drone (push) Has been skipped
Original: feat: enhance security logging and ensure rate limit blocks are properly tracked - Add comprehensive logging for rate limit blocks with full request details - IP address (with proper proxy detection), user agent, headers, timestamps - Rate limit info (current count, limit, remaining, reset time) - Separate tracking for auth vs general endpoints - Enhance authentication failure logging - JWT validation failures with detailed error info - Admin auth attempts without token - Failed token validation with user context - All events include IP, path, method, user agent - Improve Winston logger configuration for production - Add automatic log rotation (10MB errors, 50MB combined) - Create separate security.log for auth/rate limit events - Ensure logs directory exists automatically - Add structured JSON format for log aggregation - Support container logging with LOG_TO_CONSOLE env var - Create comprehensive documentation - Security logging guide with examples - Monitoring recommendations - Configuration reference - Add test script to verify logging functionality All rate limit settings remain configurable via admin panel: - Window duration, max requests, auth limits - Skip authenticated requests option - Public endpoints only option 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
9.4 KiB
9.4 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
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
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%