4.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
CoolSoup is a React + TypeScript + Vite application that generates visual patterns and converts them to audio through spectral synthesis. The app features multiple image generators (Tixy expressions, geometric tiles, external APIs) and an advanced audio synthesis engine that treats images as spectrograms.
Development Commands
pnpm dev- Start development server with hot reloadpnpm build- Build for production (TypeScript compilation + Vite build)pnpm lint- Run ESLint on the codebasepnpm preview- Preview production build locally
Architecture Overview
Core Application Structure
- State Management: Uses Nanostores for reactive state with persistent atoms
- UI Layout: Two-panel design - main content area (generator + image grid) and collapsible audio panel
- Generator Pattern: Pluggable generator system where each generator implements a common interface
Main Store (src/stores/index.ts)
Central state management with these key atoms:
appSettings- Generator selection, grid size, colorsgeneratedImages- Array of generated images with metadataselectedImage- Current image for audio synthesissynthesisParams- Audio synthesis configurationpanelOpen- Audio panel visibility
Generator System
Four built-in generators located in src/generators/:
- Tixy (
tixy.ts) - Mathematical expressions using t,i,x,y variables - Waveform (
waveform.ts) - Procedural random waveforms with various interpolation curves - Picsum (
picsum.ts) - External random images API - Art Institute (
art-institute.ts) - Art Institute of Chicago API
Each generator returns GeneratedImage[] with:
id- Unique identifiercanvas- HTMLCanvasElementimageData- ImageData for synthesisgenerator- Generator typeparams- Generation parameters
Spectral Synthesis Engine (src/spectral-synthesis/)
Advanced image-to-audio synthesis library:
- Core Logic (
core/synthesizer.ts) - Main ImageToAudioSynthesizer class - Types (
core/types.ts) - SynthesisParams and related interfaces - Audio Export (
audio/export.ts) - WAV file generation and download - Utilities (
core/utils.ts) - Helper functions for frequency mapping and peak detection
Key features:
- Mel-scale frequency mapping for perceptual accuracy
- Spectral peak detection to reduce noise
- Temporal smoothing for coherent audio trajectories
- Auto-detection of image type (spectrogram vs diagram)
- Configurable synthesis parameters (duration, frequency range, resolution)
Audio Export System (src/audio-export/)
Batch audio processing capabilities:
- Single image export with custom parameters
- Batch export of all generated images
- ZIP file generation for batch downloads
- Progress tracking for long operations
Key Implementation Details
Image Generation Flow
- User selects generator and parameters in
GeneratorSelector App.tsxcalls appropriate generator function- Generator returns array of
GeneratedImageobjects - Images displayed in
ImageGridcomponent - User can click image to select for audio synthesis
Audio Synthesis Flow
- User selects image from grid (sets
selectedImage) AudioPanelprovides synthesis parameter controls- Synthesis triggered via spectral-synthesis library
- Audio can be played directly or exported as WAV
- Batch export processes all generated images
Component Architecture
- App.tsx - Main layout and generation orchestration
- GeneratorSelector - Generator picker with settings
- ImageGrid - Grid display of generated images
- AudioPanel - Audio synthesis controls and export
- AudioControls - Playback controls for generated audio
Generator Module Structure
Both tixy-generator and waveform-generator modules are designed as standalone packages:
Tixy Generator:
README.md- Documentation and usage examplescore/types.ts- Type definitionsindex.ts- Main exports- Generator-specific files (evaluator, patterns, etc.)
Waveform Generator:
README.md- Documentation and usage examplescore/types.ts- Interfaces and configurationcore/interpolation.ts- Curve interpolation functions (linear, exponential, logarithmic, cubic)core/generator.ts- Control point generation and randomness strategiesrenderer/canvas.ts- Canvas rendering with smooth anti-aliased curvesindex.ts- Main exports and convenience functions
Development Notes
- Uses Rolldown Vite for improved performance
- Tailwind CSS for styling (no rounded corners per user preference)
- ESLint configured for React + TypeScript
- All generators support time-based animation parameters
- Image synthesis supports real-time parameter adjustment