|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +OpenCut is a free, open-source video editor built with Next.js, focusing on privacy (no server processing), multi-track timeline editing, and real-time preview. The project is a monorepo using Turborepo with multiple apps including a web application, desktop app (Tauri), background remover tools, and transcription services. |
| 8 | + |
| 9 | +## Essential Commands |
| 10 | + |
| 11 | +**Development:** |
| 12 | +```bash |
| 13 | +# Root level development |
| 14 | +bun dev # Start all apps in development mode |
| 15 | +bun build # Build all apps |
| 16 | +bun lint # Lint all code using Ultracite |
| 17 | +bun format # Format all code using Ultracite |
| 18 | + |
| 19 | +# Web app specific (from apps/web/) |
| 20 | +cd apps/web |
| 21 | +bun run dev # Start Next.js development server with Turbopack |
| 22 | +bun run build # Build for production |
| 23 | +bun run lint # Run Biome linting |
| 24 | +bun run lint:fix # Fix linting issues automatically |
| 25 | +bun run format # Format code with Biome |
| 26 | + |
| 27 | +# Database operations (from apps/web/) |
| 28 | +bun run db:generate # Generate Drizzle migrations |
| 29 | +bun run db:migrate # Run migrations |
| 30 | +bun run db:push:local # Push schema to local development database |
| 31 | +bun run db:push:prod # Push schema to production database |
| 32 | +``` |
| 33 | + |
| 34 | +**Testing:** |
| 35 | +- No unified test commands are currently configured |
| 36 | +- Individual apps may have their own test setups |
| 37 | + |
| 38 | +## Architecture & Key Components |
| 39 | + |
| 40 | +### State Management |
| 41 | +The application uses **Zustand** for state management with separate stores for different concerns: |
| 42 | +- **editor-store.ts**: Canvas presets, layout guides, app initialization |
| 43 | +- **timeline-store.ts**: Timeline tracks, elements, playback state |
| 44 | +- **media-store.ts**: Media files and asset management |
| 45 | +- **playback-store.ts**: Video playback controls and timing |
| 46 | +- **project-store.ts**: Project-level data and persistence |
| 47 | +- **panel-store.ts**: UI panel visibility and layout |
| 48 | +- **keybindings-store.ts**: Keyboard shortcut management |
| 49 | +- **sounds-store.ts**: Audio effects and sound management |
| 50 | +- **stickers-store.ts**: Sticker/graphics management |
| 51 | + |
| 52 | +### Storage System |
| 53 | +**Multi-layer storage approach:** |
| 54 | +- **IndexedDB**: Projects, saved sounds, and structured data |
| 55 | +- **OPFS (Origin Private File System)**: Large media files for better performance |
| 56 | +- **Storage Service** (`lib/storage/`): Abstraction layer managing both storage types |
| 57 | + |
| 58 | +### Editor Architecture |
| 59 | +**Core editor components:** |
| 60 | +- **Timeline Canvas**: Custom canvas-based timeline with tracks and elements |
| 61 | +- **Preview Panel**: Real-time video preview (currently DOM-based, planned binary refactor) |
| 62 | +- **Media Panel**: Asset management with drag-and-drop support |
| 63 | +- **Properties Panel**: Context-sensitive element properties |
| 64 | + |
| 65 | +### Media Processing |
| 66 | +- **FFmpeg Integration**: Client-side video processing using @ffmpeg/ffmpeg |
| 67 | +- **Background Removal**: Python-based tools with multiple AI models (U2Net, SAM, Gemini) |
| 68 | +- **Transcription**: Separate service for audio-to-text conversion |
| 69 | + |
| 70 | +## Development Focus Areas |
| 71 | + |
| 72 | +**✅ Recommended contribution areas:** |
| 73 | +- Timeline functionality and UI improvements |
| 74 | +- Project management features |
| 75 | +- Performance optimizations |
| 76 | +- Bug fixes in existing functionality |
| 77 | +- UI/UX improvements outside preview panel |
| 78 | +- Documentation and testing |
| 79 | + |
| 80 | +**⚠️ Areas to avoid (pending refactor):** |
| 81 | +- Preview panel enhancements (fonts, stickers, effects) |
| 82 | +- Export functionality improvements |
| 83 | +- Preview rendering optimizations |
| 84 | + |
| 85 | +**Reason:** The preview system is planned for a major refactor from DOM-based rendering to binary rendering for consistency with export and better performance. |
| 86 | + |
| 87 | +## Code Quality Standards |
| 88 | + |
| 89 | +**Linting & Formatting:** |
| 90 | +- Uses **Biome** for JavaScript/TypeScript linting and formatting |
| 91 | +- Extends **Ultracite** configuration for strict type safety and AI-friendly code |
| 92 | +- Comprehensive accessibility (a11y) rules enforced |
| 93 | +- Zero configuration approach with subsecond performance |
| 94 | + |
| 95 | +**Key coding standards from Ultracite:** |
| 96 | +- Strict TypeScript with no `any` types |
| 97 | +- No React imports (uses automatic JSX runtime) |
| 98 | +- Comprehensive accessibility requirements |
| 99 | +- Use `for...of` instead of `Array.forEach` |
| 100 | +- No TypeScript enums, use const objects |
| 101 | +- Always include error handling with try-catch |
| 102 | + |
| 103 | +## Environment Setup |
| 104 | + |
| 105 | +**Required environment variables (apps/web/.env.local):** |
| 106 | +```bash |
| 107 | +# Database |
| 108 | +DATABASE_URL="postgresql://opencut:opencutthegoat@localhost:5432/opencut" |
| 109 | + |
| 110 | +# Authentication |
| 111 | +BETTER_AUTH_SECRET="your-generated-secret-here" |
| 112 | +BETTER_AUTH_URL="http://localhost:3000" |
| 113 | + |
| 114 | +# Redis |
| 115 | +UPSTASH_REDIS_REST_URL="http://localhost:8079" |
| 116 | +UPSTASH_REDIS_REST_TOKEN="example_token" |
| 117 | + |
| 118 | +# Content Management |
| 119 | +MARBLE_WORKSPACE_KEY="workspace-key" |
| 120 | +NEXT_PUBLIC_MARBLE_API_URL="https://api.marblecms.com" |
| 121 | +``` |
| 122 | + |
| 123 | +**Docker services:** |
| 124 | +```bash |
| 125 | +# Start local database and Redis |
| 126 | +docker-compose up -d |
| 127 | +``` |
| 128 | + |
| 129 | +## Project Structure |
| 130 | + |
| 131 | +**Monorepo layout:** |
| 132 | +- `apps/web/` - Main Next.js application |
| 133 | +- `apps/desktop/` - Tauri desktop application |
| 134 | +- `apps/bg-remover/` - Python background removal tools |
| 135 | +- `apps/transcription/` - Audio transcription service |
| 136 | +- `packages/` - Shared packages (auth, database) |
| 137 | + |
| 138 | +**Web app structure:** |
| 139 | +- `src/components/` - React components organized by feature |
| 140 | +- `src/stores/` - Zustand state management |
| 141 | +- `src/hooks/` - Custom React hooks |
| 142 | +- `src/lib/` - Utility functions and services |
| 143 | +- `src/types/` - TypeScript type definitions |
| 144 | +- `src/app/` - Next.js app router pages and API routes |
| 145 | + |
| 146 | +## Common Patterns |
| 147 | + |
| 148 | +**Error handling:** |
| 149 | +```typescript |
| 150 | +try { |
| 151 | + const result = await processData(); |
| 152 | + return { success: true, data: result }; |
| 153 | +} catch (error) { |
| 154 | + console.error('Operation failed:', error); |
| 155 | + return { success: false, error: error.message }; |
| 156 | +} |
| 157 | +``` |
| 158 | + |
| 159 | +**Store usage:** |
| 160 | +```typescript |
| 161 | +const { tracks, addTrack, updateTrack } = useTimelineStore(); |
| 162 | +``` |
| 163 | + |
| 164 | +**Media processing:** |
| 165 | +```typescript |
| 166 | +import { processVideo } from '@/lib/ffmpeg-utils'; |
| 167 | +const processedVideo = await processVideo(inputFile, options); |
| 168 | +``` |
0 commit comments