How haigpapa/photon works
Project type and purpose
• photon+ is a client-side, full-feature physics-based generative music tool built with React and TypeScript.
• It simulates optical ray tracing on a 2D grid and translates beam–sensor collisions into Web Audio API events, rendering both canvas visuals and real-time audio.
File structure
• Top-level entrypoints:
• index.html, index.tsx → bootstraps the React app via Vite (vite.config.ts)
• App.tsx → root component, glues together UI, state, and simulation
• components/ → reusable UI (ControlPanel, GridCanvas, PresetModal, ErrorBoundary, Grid)
• services/ → domain logic and side-effects:
• simulation.ts (physics tick, ray tracing, collision detection)
• audioService.ts (Web Audio API wrappers)
• storageService.ts (localStorage/preset save-load)
• shareService.ts (export/share presets)
• geminiService.ts (optional AI integration)
• utils/ → stateless helpers (validation, geometry math)
• tests/ (__tests__, vitest.config.ts) → unit tests for simulation, share, storage, validation
• config/build files (.env.example, tsconfig.json, vite.config.ts, prettier, eslint, husky)
README for additional insights
• Core architecture described under “Architectural Approach” and illustrated in ARCHITECTURE.md.
• System boundary: inputs (user grid layout & beam params), transformation (physics engine), outputs (audio synthesis, visuals, MIDI export).
• Key abstractions: optical ray tracing, event-driven audio, grid as state machine; trade-offs (CPU, determinism) and patterns (recursive propagation).
Detail over minimalism
• Recursive loops in the physics engine to show maxBounce termination