|
| 1 | +<div align="center"> |
| 2 | + <img alt="JetKVM logo" src="https://jetkvm.com/logo-blue.png" height="28"> |
| 3 | + |
| 4 | +### Development Guide |
| 5 | + |
| 6 | +[Discord](https://jetkvm.com/discord) | [Website](https://jetkvm.com) | [Issues](https://github.com/jetkvm/cloud-api/issues) | [Docs](https://jetkvm.com/docs) |
| 7 | + |
| 8 | +[](https://twitter.com/jetkvm) |
| 9 | + |
| 10 | +[](https://goreportcard.com/report/github.com/jetkvm/kvm) |
| 11 | + |
| 12 | +</div> |
| 13 | + |
| 14 | +# JetKVM Development Guide |
| 15 | + |
| 16 | +Welcome to JetKVM development! This guide will help you get started quickly, whether you're fixing bugs, adding features, or just exploring the codebase. |
| 17 | + |
| 18 | +## Get Started |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | +- **A JetKVM device** (for full development) |
| 22 | +- **[Go 1.24.4+](https://go.dev/doc/install)** and **[Node.js 22.15.0](https://nodejs.org/en/download/)** |
| 23 | +- **[Git](https://git-scm.com/downloads)** for version control |
| 24 | +- **[SSH access](https://jetkvm.com/docs/advanced-usage/developing#developer-mode)** to your JetKVM device |
| 25 | + |
| 26 | +### Development Environment |
| 27 | + |
| 28 | +**Recommended:** Development is best done on **Linux** or **macOS**. |
| 29 | + |
| 30 | +If you're using Windows, we strongly recommend using **WSL (Windows Subsystem for Linux)** for the best development experience: |
| 31 | +- [Install WSL on Windows](https://docs.microsoft.com/en-us/windows/wsl/install) |
| 32 | +- [WSL Setup Guide](https://docs.microsoft.com/en-us/windows/wsl/setup/environment) |
| 33 | + |
| 34 | +This ensures compatibility with shell scripts and build tools used in the project. |
| 35 | + |
| 36 | +### Project Setup |
| 37 | + |
| 38 | +1. **Clone the repository:** |
| 39 | + ```bash |
| 40 | + git clone https://github.com/jetkvm/kvm.git |
| 41 | + cd kvm |
| 42 | + ``` |
| 43 | + |
| 44 | +2. **Check your tools:** |
| 45 | + ```bash |
| 46 | + go version && node --version |
| 47 | + ``` |
| 48 | + |
| 49 | +3. **Find your JetKVM IP address** (check your router or device screen) |
| 50 | + |
| 51 | +4. **Deploy and test:** |
| 52 | + ```bash |
| 53 | + ./dev_deploy.sh -r 192.168.1.100 # Replace with your device IP |
| 54 | + ``` |
| 55 | + |
| 56 | +5. **Open in browser:** `http://192.168.1.100` |
| 57 | + |
| 58 | +That's it! You're now running your own development version of JetKVM. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## Common Tasks |
| 63 | + |
| 64 | +### Modify the UI |
| 65 | + |
| 66 | +```bash |
| 67 | +cd ui |
| 68 | +npm install |
| 69 | +./dev_device.sh 192.168.1.100 # Replace with your device IP |
| 70 | +``` |
| 71 | + |
| 72 | +Now edit files in `ui/src/` and see changes live in your browser! |
| 73 | + |
| 74 | +### Modify the backend |
| 75 | + |
| 76 | +```bash |
| 77 | +# Edit Go files (config.go, web.go, etc.) |
| 78 | +./dev_deploy.sh -r 192.168.1.100 --skip-ui-build |
| 79 | +``` |
| 80 | + |
| 81 | +### Run tests |
| 82 | + |
| 83 | +```bash |
| 84 | +./dev_deploy.sh -r 192.168.1.100 --run-go-tests |
| 85 | +``` |
| 86 | + |
| 87 | +### View logs |
| 88 | + |
| 89 | +```bash |
| 90 | + |
| 91 | +tail -f /var/log/jetkvm.log |
| 92 | +``` |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Project Layout |
| 97 | + |
| 98 | +``` |
| 99 | +/kvm/ |
| 100 | +├── main.go # App entry point |
| 101 | +├── config.go # Settings & configuration |
| 102 | +├── web.go # API endpoints |
| 103 | +├── ui/ # React frontend |
| 104 | +│ ├── src/routes/ # Pages (login, settings, etc.) |
| 105 | +│ └── src/components/ # UI components |
| 106 | +└── internal/ # Internal Go packages |
| 107 | +``` |
| 108 | + |
| 109 | +**Key files for beginners:** |
| 110 | + |
| 111 | +- `web.go` - Add new API endpoints here |
| 112 | +- `config.go` - Add new settings here |
| 113 | +- `ui/src/routes/` - Add new pages here |
| 114 | +- `ui/src/components/` - Add new UI components here |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## Development Modes |
| 119 | + |
| 120 | +### Full Development (Recommended) |
| 121 | + |
| 122 | +*Best for: Complete feature development* |
| 123 | + |
| 124 | +```bash |
| 125 | +# Deploy everything to your JetKVM device |
| 126 | +./dev_deploy.sh -r <YOUR_DEVICE_IP> |
| 127 | +``` |
| 128 | + |
| 129 | +### Frontend Only |
| 130 | + |
| 131 | +*Best for: UI changes without device* |
| 132 | + |
| 133 | +```bash |
| 134 | +cd ui |
| 135 | +npm install |
| 136 | +./dev_device.sh <YOUR_DEVICE_IP> |
| 137 | +``` |
| 138 | + |
| 139 | +### Quick Backend Changes |
| 140 | + |
| 141 | +*Best for: API or backend logic changes* |
| 142 | + |
| 143 | +```bash |
| 144 | +# Skip frontend build for faster deployment |
| 145 | +./dev_deploy.sh -r <YOUR_DEVICE_IP> --skip-ui-build |
| 146 | +``` |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## Debugging Made Easy |
| 151 | + |
| 152 | +### Check if everything is working |
| 153 | + |
| 154 | +```bash |
| 155 | +# Test connection to device |
| 156 | +ping 192.168.1.100 |
| 157 | + |
| 158 | +# Check if JetKVM is running |
| 159 | +ssh [email protected] ps aux | grep jetkvm |
| 160 | +``` |
| 161 | + |
| 162 | +### View live logs |
| 163 | + |
| 164 | +```bash |
| 165 | + |
| 166 | +tail -f /var/log/jetkvm.log |
| 167 | +``` |
| 168 | + |
| 169 | +### Reset everything (if stuck) |
| 170 | + |
| 171 | +```bash |
| 172 | + |
| 173 | +rm /userdata/kvm_config.json |
| 174 | +systemctl restart jetkvm |
| 175 | +``` |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +## Testing Your Changes |
| 180 | + |
| 181 | +### Manual Testing |
| 182 | + |
| 183 | +1. Deploy your changes: `./dev_deploy.sh -r <IP>` |
| 184 | +2. Open browser: `http://<IP>` |
| 185 | +3. Test your feature |
| 186 | +4. Check logs: `ssh root@<IP> tail -f /var/log/jetkvm.log` |
| 187 | + |
| 188 | +### Automated Testing |
| 189 | + |
| 190 | +```bash |
| 191 | +# Run all tests |
| 192 | +./dev_deploy.sh -r <IP> --run-go-tests |
| 193 | + |
| 194 | +# Frontend linting |
| 195 | +cd ui && npm run lint |
| 196 | +``` |
| 197 | + |
| 198 | +### API Testing |
| 199 | + |
| 200 | +```bash |
| 201 | +# Test login endpoint |
| 202 | +curl -X POST http://<IP>/auth/password-local \ |
| 203 | + -H "Content-Type: application/json" \ |
| 204 | + -d '{"password": "test123"}' |
| 205 | +``` |
| 206 | + |
| 207 | +--- |
| 208 | + |
| 209 | +## Common Issues & Solutions |
| 210 | + |
| 211 | +### "Build failed" or "Permission denied" |
| 212 | + |
| 213 | +```bash |
| 214 | +# Fix permissions |
| 215 | +ssh root@<IP> chmod +x /userdata/jetkvm/bin/jetkvm_app_debug |
| 216 | + |
| 217 | +# Clean and rebuild |
| 218 | +go clean -modcache |
| 219 | +go mod tidy |
| 220 | +make build_dev |
| 221 | +``` |
| 222 | + |
| 223 | +### "Can't connect to device" |
| 224 | + |
| 225 | +```bash |
| 226 | +# Check network |
| 227 | +ping <IP> |
| 228 | + |
| 229 | +# Check SSH |
| 230 | +ssh root@<IP> echo "Connection OK" |
| 231 | +``` |
| 232 | + |
| 233 | +### "Frontend not updating" |
| 234 | + |
| 235 | +```bash |
| 236 | +# Clear cache and rebuild |
| 237 | +cd ui |
| 238 | +npm cache clean --force |
| 239 | +rm -rf node_modules |
| 240 | +npm install |
| 241 | +``` |
| 242 | + |
| 243 | +--- |
| 244 | + |
| 245 | +## Next Steps |
| 246 | + |
| 247 | +### Adding a New Feature |
| 248 | + |
| 249 | +1. **Backend:** Add API endpoint in `web.go` |
| 250 | +2. **Config:** Add settings in `config.go` |
| 251 | +3. **Frontend:** Add UI in `ui/src/routes/` |
| 252 | +4. **Test:** Deploy and test with `./dev_deploy.sh` |
| 253 | + |
| 254 | +### Code Style |
| 255 | + |
| 256 | +- **Go:** Follow standard Go conventions |
| 257 | +- **TypeScript:** Use TypeScript for type safety |
| 258 | +- **React:** Keep components small and reusable |
| 259 | + |
| 260 | +### Environment Variables |
| 261 | + |
| 262 | +```bash |
| 263 | +# Enable debug logging |
| 264 | +export LOG_TRACE_SCOPES="jetkvm,cloud,websocket,native,jsonrpc" |
| 265 | + |
| 266 | +# Frontend development |
| 267 | +export JETKVM_PROXY_URL="ws://<IP>" |
| 268 | +``` |
| 269 | + |
| 270 | +--- |
| 271 | + |
| 272 | +## Need Help? |
| 273 | + |
| 274 | +1. **Check logs first:** `ssh root@<IP> tail -f /var/log/jetkvm.log` |
| 275 | +2. **Search issues:** [GitHub Issues](https://github.com/jetkvm/kvm/issues) |
| 276 | +3. **Ask on Discord:** [JetKVM Discord](https://jetkvm.com/discord) |
| 277 | +4. **Read docs:** [JetKVM Documentation](https://jetkvm.com/docs) |
| 278 | + |
| 279 | +--- |
| 280 | + |
| 281 | +## Contributing |
| 282 | + |
| 283 | +### Ready to contribute? |
| 284 | + |
| 285 | +1. Fork the repository |
| 286 | +2. Create a feature branch |
| 287 | +3. Make your changes |
| 288 | +4. Test thoroughly |
| 289 | +5. Submit a pull request |
| 290 | + |
| 291 | +### Before submitting: |
| 292 | + |
| 293 | +- [ ] Code works on device |
| 294 | +- [ ] Tests pass |
| 295 | +- [ ] Code follows style guidelines |
| 296 | +- [ ] Documentation updated (if needed) |
| 297 | + |
| 298 | +--- |
| 299 | + |
| 300 | +## Advanced Topics |
| 301 | + |
| 302 | +### Performance Profiling |
| 303 | + |
| 304 | +```bash |
| 305 | +# Enable profiling |
| 306 | +go build -o bin/jetkvm_app -ldflags="-X main.enableProfiling=true" cmd/main.go |
| 307 | + |
| 308 | +# Access profiling |
| 309 | +curl http://<IP>:6060/debug/pprof/ |
| 310 | +``` |
| 311 | +### Advanced Environment Variables |
| 312 | + |
| 313 | +```bash |
| 314 | +# Enable trace logging (useful for debugging) |
| 315 | +export LOG_TRACE_SCOPES="jetkvm,cloud,websocket,native,jsonrpc" |
| 316 | + |
| 317 | +# For frontend development |
| 318 | +export JETKVM_PROXY_URL="ws://<JETKVM_IP>" |
| 319 | + |
| 320 | +# Enable SSL in development |
| 321 | +export USE_SSL=true |
| 322 | +``` |
| 323 | + |
| 324 | +### Configuration Management |
| 325 | + |
| 326 | +The application uses a JSON configuration file stored at `/userdata/kvm_config.json`. |
| 327 | + |
| 328 | +#### Adding New Configuration Options |
| 329 | + |
| 330 | +1. **Update the Config struct in `config.go`:** |
| 331 | + |
| 332 | + ```go |
| 333 | + type Config struct { |
| 334 | + // ... existing fields |
| 335 | + NewFeatureEnabled bool `json:"new_feature_enabled"` |
| 336 | + } |
| 337 | + ``` |
| 338 | + |
| 339 | +2. **Update the default configuration:** |
| 340 | + |
| 341 | + ```go |
| 342 | + var defaultConfig = &Config{ |
| 343 | + // ... existing defaults |
| 344 | + NewFeatureEnabled: false, |
| 345 | + } |
| 346 | + ``` |
| 347 | + |
| 348 | +3. **Add migration logic if needed for existing installations** |
| 349 | + |
| 350 | + |
| 351 | +--- |
| 352 | + |
| 353 | +**Happy coding!** |
| 354 | + |
| 355 | +For more information, visit the [JetKVM Documentation](https://jetkvm.com/docs) or join our [Discord Server](https://jetkvm.com/discord). |
0 commit comments