|
| 1 | +# WARP.md |
| 2 | + |
| 3 | +This file provides guidance to WARP (warp.dev) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Hydrogen is a modern astronomical device communication protocol and framework designed for seamless integration with astronomical equipment. It provides automatic ASCOM/INDI compatibility, multi-protocol communication, and a unified device architecture for professional astronomical applications. |
| 8 | + |
| 9 | +## Common Development Commands |
| 10 | + |
| 11 | +### Build System Commands |
| 12 | + |
| 13 | +**XMake (Recommended for New Projects - 29-68% faster builds):** |
| 14 | +```bash |
| 15 | +# Configure with all features |
| 16 | +xmake config --tests=y --examples=y --ssl=y --compression=y |
| 17 | + |
| 18 | +# Build the project |
| 19 | +xmake |
| 20 | + |
| 21 | +# Run tests |
| 22 | +xmake test |
| 23 | + |
| 24 | +# Run specific application |
| 25 | +xmake run astro_server |
| 26 | + |
| 27 | +# Build specific target |
| 28 | +xmake build hydrogen_core |
| 29 | + |
| 30 | +# Clean build artifacts |
| 31 | +xmake clean |
| 32 | +``` |
| 33 | + |
| 34 | +**CMake (Traditional):** |
| 35 | +```bash |
| 36 | +# Configure with preset (using vcpkg) |
| 37 | +cmake --preset default |
| 38 | + |
| 39 | +# Build all targets |
| 40 | +cmake --build --preset default |
| 41 | + |
| 42 | +# Run tests |
| 43 | +ctest --preset default |
| 44 | + |
| 45 | +# Build specific target |
| 46 | +cmake --build . --target hydrogen_core |
| 47 | + |
| 48 | +# Install to system |
| 49 | +cmake --install . |
| 50 | +``` |
| 51 | + |
| 52 | +### Testing Commands |
| 53 | + |
| 54 | +**Run all tests:** |
| 55 | +```bash |
| 56 | +# XMake |
| 57 | +xmake test |
| 58 | + |
| 59 | +# CMake |
| 60 | +ctest --preset default --parallel 4 |
| 61 | +``` |
| 62 | + |
| 63 | +**Run specific test categories:** |
| 64 | +```bash |
| 65 | +# Run device tests only |
| 66 | +ctest --preset default --label-regex "device" |
| 67 | + |
| 68 | +# Run integration tests |
| 69 | +ctest --preset default --label-regex "integration" |
| 70 | + |
| 71 | +# Run performance tests |
| 72 | +ctest --preset default --label-regex "performance" |
| 73 | +``` |
| 74 | + |
| 75 | +**Run device lifecycle tests (Windows):** |
| 76 | +```bash |
| 77 | +scripts\run_device_lifecycle_tests.bat -s cmake -t Debug -f "StateTransition*" |
| 78 | +scripts\run_device_lifecycle_tests.bat -s xmake -t Release -r 5 -p |
| 79 | +``` |
| 80 | + |
| 81 | +**Single test execution:** |
| 82 | +```bash |
| 83 | +# Run a specific test executable directly |
| 84 | +./build/tests/test_telescope_device |
| 85 | +./build/tests/core_device_lifecycle_tests |
| 86 | +``` |
| 87 | + |
| 88 | +### Development Workflow |
| 89 | + |
| 90 | +**Quick development setup:** |
| 91 | +```bash |
| 92 | +# Fast build for development (CMake) |
| 93 | +cmake --preset debug -DHYDROGEN_BUILD_TESTS=ON -DHYDROGEN_ENABLE_SANITIZERS=ON |
| 94 | +cmake --build --preset debug --parallel |
| 95 | + |
| 96 | +# Fast build for development (XMake) |
| 97 | +xmake config --mode=debug --tests=y --sanitizers=y |
| 98 | +xmake |
| 99 | +``` |
| 100 | + |
| 101 | +**Production build:** |
| 102 | +```bash |
| 103 | +# Optimized release build (CMake) |
| 104 | +cmake --preset release -DHYDROGEN_ENABLE_LTO=ON |
| 105 | +cmake --build --preset release |
| 106 | + |
| 107 | +# Optimized release build (XMake) |
| 108 | +xmake config --mode=release --lto=y |
| 109 | +xmake |
| 110 | +``` |
| 111 | + |
| 112 | +## High-Level Architecture |
| 113 | + |
| 114 | +### Core Framework Architecture |
| 115 | + |
| 116 | +Hydrogen follows a **layered, modular architecture** with clear separation of concerns: |
| 117 | + |
| 118 | +#### 1. **Unified Device Architecture** |
| 119 | +- **Single API**: One interface for all device types and communication protocols |
| 120 | +- **Modular Behaviors**: Composable device behaviors (MovableBehavior, TemperatureControlBehavior) that can be mixed and matched |
| 121 | +- **Component-Based Design**: Reusable components (CommunicationManager, StateManager, ConfigManager) shared across device types |
| 122 | +- **Dynamic Configuration**: Runtime device configuration and behavior modification |
| 123 | + |
| 124 | +#### 2. **Multi-Protocol Communication System** |
| 125 | +- **Protocol Abstraction Layer**: Unified interface for WebSocket, gRPC, MQTT, ZeroMQ, HTTP protocols |
| 126 | +- **Automatic Protocol Bridges**: Zero-code ASCOM COM interface and INDI XML property system integration |
| 127 | +- **Message Transformation**: Automatic message format conversion between protocols |
| 128 | +- **Connection Management**: Advanced connection pooling, circuit breakers, and failover mechanisms |
| 129 | + |
| 130 | +#### 3. **Service-Oriented Server Architecture** |
| 131 | +Located in `src/server/` and `src_new/server/`: |
| 132 | +- **Device Service**: Comprehensive device lifecycle management |
| 133 | +- **Authentication Service**: JWT, API keys, OAuth2, LDAP support |
| 134 | +- **Communication Service**: Intelligent message routing and protocol bridging |
| 135 | +- **Health Service**: System monitoring, metrics, and alerting |
| 136 | + |
| 137 | +#### 4. **Client Architecture** |
| 138 | +Located in `src/client/` and `src_new/client/`: |
| 139 | +- **UnifiedDeviceClient**: Single interface for all device types and protocols |
| 140 | +- **UnifiedConnectionManager**: Centralized connection handling with automatic retry and failover |
| 141 | +- **Device Managers**: Specialized managers for different device categories |
| 142 | + |
| 143 | +### Key Architectural Patterns |
| 144 | + |
| 145 | +#### **Composition over Inheritance** |
| 146 | +The new architecture (in `src_new/`) replaces single inheritance with composition: |
| 147 | +- Devices compose behaviors instead of inheriting them |
| 148 | +- `ModernDeviceBase` + behavior components (MovableBehavior, TemperatureControlBehavior) |
| 149 | +- 90%+ reduction in code duplication |
| 150 | + |
| 151 | +#### **Message-Driven Architecture** |
| 152 | +Located in `src/core/`: |
| 153 | +- **Message Types**: Commands, responses, events, errors, discovery, registration |
| 154 | +- **QoS Support**: AT_MOST_ONCE, AT_LEAST_ONCE, EXACTLY_ONCE |
| 155 | +- **Priority Handling**: LOW, NORMAL, HIGH, CRITICAL message priorities |
| 156 | +- **Error Recovery**: Multiple strategies (IGNORE, RETRY, NOTIFY, RESTART_DEVICE, FAILOVER) |
| 157 | + |
| 158 | +#### **Protocol Agnostic Design** |
| 159 | +- Device implementations are protocol-agnostic |
| 160 | +- Protocol-specific adapters handle communication details |
| 161 | +- Same device accessible through multiple protocols simultaneously |
| 162 | + |
| 163 | +### Device Implementation Strategy |
| 164 | + |
| 165 | +#### **Legacy Architecture** (`src/`) |
| 166 | +- Traditional inheritance-based device hierarchy |
| 167 | +- Device-specific implementations with shared base classes |
| 168 | +- Used for stable, production devices |
| 169 | + |
| 170 | +#### **Modern Architecture** (`src_new/`) |
| 171 | +- Composition-based with behavior components |
| 172 | +- Significantly reduced code duplication |
| 173 | +- Easier testing and maintenance |
| 174 | +- Preferred for new device implementations |
| 175 | + |
| 176 | +### Build System Dual Support |
| 177 | + |
| 178 | +The project maintains **full feature parity** between two build systems: |
| 179 | + |
| 180 | +#### **XMake Features** |
| 181 | +- Built-in package management (no external tools needed) |
| 182 | +- 29-68% faster builds with superior incremental compilation |
| 183 | +- Simpler Lua-based configuration |
| 184 | +- Modern design with better defaults |
| 185 | + |
| 186 | +#### **CMake Features** |
| 187 | +- Mature ecosystem with extensive IDE support |
| 188 | +- External package managers (vcpkg, Conan) |
| 189 | +- Enterprise-grade with widespread adoption |
| 190 | +- Comprehensive preset system in `CMakePresets.json` |
| 191 | + |
| 192 | +## Project Structure Key Areas |
| 193 | + |
| 194 | +### Core Components |
| 195 | +- `src/core/` - Fundamental framework functionality, message system |
| 196 | +- `src_new/core/` - Modern refactored core with enhanced modularity |
| 197 | +- `src/common/` - Shared utilities, logging, JSON handling |
| 198 | + |
| 199 | +### Device Architecture |
| 200 | +- `src/device_component/` - Legacy device implementations |
| 201 | +- `src_new/devices/` - Modern modular device architecture with composition |
| 202 | +- Device types: Telescope, Camera, Focuser, Filter Wheel, Rotator, Dome |
| 203 | + |
| 204 | +### Communication |
| 205 | +- `src/server/` - Server infrastructure and protocol handlers |
| 206 | +- `src_new/server/` - Reorganized layered server architecture |
| 207 | +- `src/client/` & `src_new/client/` - Client-side communication management |
| 208 | + |
| 209 | +### Applications |
| 210 | +- `src/apps/` - Built applications (astro_server, astro_client, device applications) |
| 211 | +- `src_new/applications/` - New application structure |
| 212 | + |
| 213 | +### Language Bindings |
| 214 | +- `src/python/` - Python bindings for full API parity |
| 215 | +- `src_new/bindings/python/` - Enhanced Python bindings |
| 216 | + |
| 217 | +## Development Standards |
| 218 | + |
| 219 | +### Code Organization |
| 220 | +- Use modern C++17/20 standards |
| 221 | +- Follow composition over inheritance pattern for new code |
| 222 | +- Implement proper error handling with the ErrorRecoveryManager |
| 223 | +- Use dependency injection through the service registry pattern |
| 224 | + |
| 225 | +### Testing Requirements |
| 226 | +- Current test coverage: 90% (151/168 tests passing) |
| 227 | +- Add unit tests for all new components |
| 228 | +- Use Google Test framework |
| 229 | +- Include integration tests for protocol communication |
| 230 | +- Add performance benchmarks for critical paths |
| 231 | + |
| 232 | +### Protocol Implementation |
| 233 | +- All devices must support automatic ASCOM/INDI compatibility |
| 234 | +- Implement protocol-agnostic device logic |
| 235 | +- Use the unified message system for communication |
| 236 | +- Support multiple simultaneous protocol connections |
| 237 | + |
| 238 | +### Build Configuration |
| 239 | +- Maintain compatibility with both XMake and CMake build systems |
| 240 | +- Use feature flags for optional components (SSL, compression, Python bindings) |
| 241 | +- Support cross-platform builds (Windows, Linux, macOS) |
| 242 | +- Enable appropriate optimizations (LTO for release, sanitizers for debug) |
| 243 | + |
| 244 | +## Current Status |
| 245 | + |
| 246 | +The project is **production-ready** with: |
| 247 | +- All core applications building and running successfully |
| 248 | +- 90% test pass rate (151/168 tests passing) |
| 249 | +- Both build systems fully functional |
| 250 | +- All major dependencies resolved |
| 251 | +- Professional astronomical device communication capabilities |
| 252 | + |
| 253 | +The remaining 10% of failing tests are primarily edge cases and advanced features that don't impact core functionality. |
0 commit comments