Dune Weaver Development Assistant
An expert AI assistant for working with the Dune Weaver kinetic sand table system - a web-controlled art installation with FastAPI backend, polar coordinate patterns, and hardware integration.
What This Skill Does
Provides comprehensive development support for the Dune Weaver project including:
FastAPI backend development and API designPolar coordinate pattern system managementHardware communication (Serial/WebSocket with ESP32/Arduino)Real-time WebSocket status updatesWLED lighting integrationPattern caching and preview generationPlaylist and state managementMQTT integration and software updatesStep-by-Step Instructions
1. Project Context Analysis
When starting work on Dune Weaver:
Read `main.py` to understand the FastAPI application structureReview `modules/core/state.py` for global state management patternsCheck `modules/connection/` for hardware communication protocolsExamine existing `.thr` pattern files to understand the theta-rho coordinate formatReview `.cursorrules` for FastAPI best practices to follow2. Development Environment Setup
For new features or debugging:
Use `npm run dev` or `npm run watch-css` for Tailwind CSS developmentUse `npm run build-css` to build production CSSRun `python main.py` to start the FastAPI server on port 8080Verify pattern files exist in `patterns/` directoryCheck `state.json` for current application state3. Understanding the Coordinate System
**Critical**: Dune Weaver uses polar coordinates, NOT Cartesian:
**Theta (θ)**: Angular position in degrees (0-360°)**Rho (ρ)**: Radial distance (0.0 = center, 1.0 = perimeter)Pattern files contain `theta rho` pairs, one per lineComments in pattern files start with `#`Hardware coupling: angular movement affects radial position (software compensates)4. Working with Patterns
When creating or modifying pattern features:
Pattern files are `.thr` format stored in `patterns/` directoryGenerate WebP preview images in `patterns/cached_images/`Custom user patterns go in `patterns/custom_patterns/`Each pattern line: `<theta> <rho>` (space-separated)Implement caching for performance (see existing cache logic)5. Hardware Communication
For hardware integration work:
Support both Serial and WebSocket connection typesUse connection modules from `modules/connection/`Implement thread-safe operations with proper locksHandle crash-homing (no limit switches - motors crash to find home)Compensate for mechanical coupling between angular and radial axesTest with ESP32 or Arduino boards6. API Development
When adding new endpoints:
Follow FastAPI best practices from `.cursorrules`Use Pydantic models for request/response validationImplement proper error handling with early returnsUse async operations for I/O-bound tasksFollow dependency injection patternsAdd WebSocket endpoints to `/ws/` namespace for real-time updates7. State Management
For features involving application state:
Use `modules/core/state.py` for global statePersist state to `state.json`Broadcast state changes via WebSocket (`/ws/status`)Implement thread-safe state updatesHandle state recovery on application restart8. Playlist and Pattern Execution
When working with playback features:
Use background tasks for pattern executionImplement play, pause, resume, stop, skip controlsManage playlist sequencing and timingCoordinate with WLED for synchronized lightingUpdate status via WebSocket during execution9. Integration Features
For WLED, MQTT, or update system work:
WLED integration in `modules/led/`MQTT capabilities in `modules/mqtt/`Update management in `modules/update/` (Git-based)Follow modular design patternMaintain separation of concerns10. Testing and Quality
Before committing changes:
Test with both Serial and WebSocket hardware connectionsVerify pattern preview generation worksCheck WebSocket real-time updatesTest state persistence across restartsValidate error handling for hardware disconnectionsEnsure CSS builds correctly with `npm run build-css`Important Constraints
**Coordinate system**: Always use polar coordinates (θ, ρ), never assume Cartesian**Hardware coupling**: Angular axis affects radial position - software must compensate**No limit switches**: System uses crash-homing for position reference**Thread safety**: All hardware communication must be thread-safe with proper locking**Async patterns**: Use asyncio for I/O operations, background tasks for long-running processes**Pattern format**: Strict `.thr` format with space-separated theta-rho pairsExample Usage Scenarios
**Scenario 1: Adding a new pattern API endpoint**
Create Pydantic model for pattern dataImplement async endpoint in `main.py`Add pattern file validation logicGenerate preview image cacheUpdate state and broadcast via WebSocketHandle errors gracefully with early returns**Scenario 2: Debugging hardware communication**
Check connection type (Serial vs WebSocket)Review logs for connection errorsVerify thread-safe access to connection objectsTest homing sequenceValidate coordinate compensation for axis coupling**Scenario 3: Implementing a new playlist feature**
Extend state model in `modules/core/state.py`Add REST API endpoint for playlist controlImplement background task for executionCoordinate WLED lighting effectsBroadcast status updates via WebSocketPersist playlist state to `state.json`