|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build and Development Commands |
| 6 | + |
| 7 | +### Frontend (UI) |
| 8 | + |
| 9 | +- `npm run dev` - Start development server on port 8092 with hot reloading |
| 10 | +- `npm run build:ui` - Build the Vue.js frontend application |
| 11 | +- `npm run dev-https` - Start development server with HTTPS enabled |
| 12 | + |
| 13 | +### Backend (API/Server) |
| 14 | + |
| 15 | +- `npm run dev:server` - Start backend server in development mode with nodemon |
| 16 | +- `npm run server` - Start production server using compiled TypeScript |
| 17 | +- `npm run build:server` - Compile TypeScript API code to JavaScript |
| 18 | +- `npm run start` - Start production server from compiled code |
| 19 | + |
| 20 | +### Full Stack |
| 21 | + |
| 22 | +- `npm run build` - Build both frontend and backend |
| 23 | +- `npm run bundle` - Bundle the application using esbuild |
| 24 | + |
| 25 | +### Testing and Quality |
| 26 | + |
| 27 | +- `npm run test` - Run all tests (both server and UI) |
| 28 | +- `npm run test:server` - Run backend tests with Mocha |
| 29 | +- `npm run test:ui` - Run frontend tests |
| 30 | +- `npm run lint` - Run ESLint and markdownlint |
| 31 | +- `npm run lint-fix` - Auto-fix linting issues |
| 32 | +- `npm run coverage` - Run tests with coverage reporting |
| 33 | + |
| 34 | +### Development Tools |
| 35 | + |
| 36 | +- `npm run fake-stick` - Start mock Z-Wave controller for testing |
| 37 | +- `npm run docs` - Serve documentation with Docsify |
| 38 | +- `npm run pkg` - Create binary packages |
| 39 | +- `npm run docker:build` - Build Docker image |
| 40 | + |
| 41 | +## Project Architecture |
| 42 | + |
| 43 | +### Technology Stack |
| 44 | + |
| 45 | +- **Backend**: Node.js, Express, TypeScript, Socket.IO, MQTT, Z-Wave JS |
| 46 | +- **Frontend**: Vue 2.7, Vuetify, Pinia (state management) |
| 47 | +- **Build Tools**: Vite (frontend), esbuild (backend), TypeScript |
| 48 | + |
| 49 | +### Core Components |
| 50 | + |
| 51 | +#### Backend Architecture (`api/`) |
| 52 | + |
| 53 | +- **app.ts**: Main Express application with middleware, routing, and Socket.IO setup |
| 54 | +- **lib/ZwaveClient.ts**: Z-Wave JS driver integration and device management |
| 55 | +- **lib/Gateway.ts**: Core gateway logic connecting Z-Wave to MQTT |
| 56 | +- **lib/MqttClient.ts**: MQTT broker communication |
| 57 | +- **lib/SocketManager.ts**: WebSocket management for real-time UI updates |
| 58 | +- **lib/BackupManager.ts**: Handles NVM and configuration backups |
| 59 | +- **lib/ZnifferManager.ts**: Z-Wave network sniffing functionality |
| 60 | + |
| 61 | +#### Frontend Architecture (`src/`) |
| 62 | + |
| 63 | +- **main.js**: Vue application entry point |
| 64 | +- **App.vue**: Root component |
| 65 | +- **views/**: Page components (ControlPanel, Settings, Mesh, etc.) |
| 66 | +- **components/**: Reusable UI components |
| 67 | +- **stores/**: Pinia state management |
| 68 | +- **router/**: Vue Router configuration |
| 69 | + |
| 70 | +#### Key Directories |
| 71 | + |
| 72 | +- **api/**: TypeScript backend code |
| 73 | +- **src/**: Vue frontend code |
| 74 | +- **server/**: Compiled JavaScript backend (build output) |
| 75 | +- **dist/**: Built frontend assets |
| 76 | +- **store/**: Runtime data (logs, backups, sessions, Z-Wave data) |
| 77 | +- **docs/**: Documentation with Docsify |
| 78 | + |
| 79 | +### Development Patterns |
| 80 | + |
| 81 | +#### API Structure |
| 82 | + |
| 83 | +- RESTful APIs under `/api/` prefix |
| 84 | +- Socket.IO events for real-time communication |
| 85 | +- JWT authentication when enabled |
| 86 | +- Rate limiting on sensitive endpoints |
| 87 | + |
| 88 | +#### Z-Wave Integration |
| 89 | + |
| 90 | +- Uses Z-Wave JS library for device communication |
| 91 | +- Gateway pattern translates Z-Wave events to MQTT |
| 92 | +- Supports both named and value ID based topics |
| 93 | +- Home Assistant MQTT discovery integration |
| 94 | + |
| 95 | +#### State Management |
| 96 | + |
| 97 | +- Backend state managed through Z-Wave JS and custom stores |
| 98 | +- Frontend uses Pinia for reactive state |
| 99 | +- Real-time updates via Socket.IO events |
| 100 | + |
| 101 | +### Configuration and Settings |
| 102 | + |
| 103 | +- Settings stored in `store/settings.json` |
| 104 | +- Runtime configuration through environment variables |
| 105 | +- Custom device configurations in `store/customDevices.json` |
| 106 | +- Backup configurations in `store/backups/` |
| 107 | + |
| 108 | +### Testing Strategy |
| 109 | + |
| 110 | +- Backend tests use Mocha with TypeScript support |
| 111 | +- Frontend tests use Mocha with Babel |
| 112 | +- Test files use `.test.ts` or `.test.js` extensions |
| 113 | +- Coverage reporting with c8 |
| 114 | + |
| 115 | +### Build and Deployment |
| 116 | + |
| 117 | +- Backend compiled from TypeScript to JavaScript |
| 118 | +- Frontend bundled with Vite |
| 119 | +- Docker support with multi-stage builds |
| 120 | +- Binary packaging with `@yao-pkg/pkg` |
| 121 | + |
| 122 | +## Development Workflow |
| 123 | + |
| 124 | +1. **Starting Development**: Use `npm run dev` for frontend and `npm run dev:server` for backend |
| 125 | +2. **Code Changes**: Backend changes trigger nodemon restart, frontend has hot reloading |
| 126 | +3. **Testing**: Run `npm run test` before committing changes |
| 127 | +4. **Linting**: Use `npm run lint-fix` to fix code style issues |
| 128 | +5. **Building**: Use `npm run build` for production builds |
| 129 | + |
| 130 | +## Important Notes |
| 131 | + |
| 132 | +- The project is currently on the `vue3-refactor` branch |
| 133 | +- **Migration Status**: Currently migrating from Vue 2.7 + Vuetify 2 to Vue 3 + Vuetify 3 |
| 134 | +- Backend code is in TypeScript, frontend in JavaScript (Vue 3) |
| 135 | +- Z-Wave functionality requires physical hardware or mock server |
| 136 | +- MQTT integration is optional but commonly used |
| 137 | +- Authentication can be enabled/disabled in settings |
| 138 | +- The application serves both as a Z-Wave control panel and MQTT gateway |
| 139 | + |
| 140 | +## Vue 3 Migration Progress |
| 141 | + |
| 142 | +### ✅ Completed |
| 143 | + |
| 144 | +- Updated package.json dependencies: Vue 3, Vuetify 3, Vue Router 4, vuedraggable v4 |
| 145 | +- Replaced `v-snackbars` with `vuetify-sonner` for notifications |
| 146 | +- Updated build tools: `@vitejs/plugin-vue` (replacing vue2 plugin), Vite 6 |
| 147 | +- Added `eslint-plugin-vuetify` for automatic migration assistance |
| 148 | +- Updated ESLint configuration for Vue 3 compatibility |
| 149 | +- Updated Vite configuration to use Vue 3 plugin |
| 150 | +- **Core Framework Migration:** |
| 151 | + - Updated `main.js` to use Vue 3 `createApp()` API |
| 152 | + - Updated Vue Router to use `createRouter()` and `createWebHashHistory()` |
| 153 | + - Updated Vuetify plugin to use `createVuetify()` with V3 theme system |
| 154 | + - Updated Pinia plugin for Vue 3 compatibility |
| 155 | + - Fixed Vue 3 lifecycle hook duplicates |
| 156 | + - Migrated notification system from v-snackbars to vuetify-sonner |
| 157 | +- **Development Server:** Now successfully starts with Vue 3 + Vuetify 3 |
| 158 | + |
| 159 | +### ✅ Additional Completed |
| 160 | + |
| 161 | +- **Systematic Vuetify Component Migration:** |
| 162 | + - Fixed all `v-subheader` → `v-list-subheader` (22 instances across 6 files) |
| 163 | + - Fixed all `v-list-item-icon` → template slots (6 instances) |
| 164 | + - Removed all deprecated `dark` props (50+ instances across 15+ files) |
| 165 | + - Fixed all `fab` → `variant="fab"` (23 instances across 7 files) |
| 166 | + - Fixed `nudge-*` props → `:offset` array (2 instances) |
| 167 | + - Fixed `item-style` → `row-props` (1 instance) |
| 168 | + - Fixed `offset-y` → `location` positioning (2 instances) |
| 169 | + - Updated draggable components to Vue 3 syntax (3 files) |
| 170 | + - Fixed Vue 3 template key placement (1 instance) |
| 171 | + |
| 172 | +### ✅ Recently Completed (Major Cleanup) |
| 173 | + |
| 174 | +- **v-list-item-content** replacement (15+ instances across 3 files) |
| 175 | +- **v-tabs-items/v-tab-item** updates (9 instances across 2 files) |
| 176 | +- **lazy-validation** removal (7 instances across 5 dialog files) |
| 177 | +- **dense** prop removal (10+ instances across 4 files) |
| 178 | +- **app** prop removal (2 instances in App.vue) |
| 179 | +- **v-list-item-avatar** replacement (1 instance) |
| 180 | +- **positioning props** (overlap/fixed/position-x/position-y) (8+ instances) |
| 181 | +- **v-list-item-icon** template slot migration (8+ instances) |
| 182 | +- **v-subheader** final fixes (2 instances) |
| 183 | +- **unused imports** cleanup (1 instance) |
| 184 | + |
| 185 | +### 🔄 Final Remaining Issues (28 → down from 204 - 86% reduction!) |
| 186 | + |
| 187 | +- **hide-mode-switch/flat** props (ValueId.vue - 2 instances) |
| 188 | +- **@change** event updates (ListInput.vue - 1 instance) |
| 189 | +- **v-list-item-content** (DialogHealthCheck.vue - 1 instance) |
| 190 | +- **Vue 3 template key** placement (2 instances) |
| 191 | +- **duplicate attributes** (NodeDetails.vue, NodeScheduler.vue - 8 instances) |
| 192 | +- **deprecated colors** (SmartView.vue - 1 instance) |
| 193 | +- **deprecated .native** modifiers (index.vue - 3 instances) |
| 194 | +- **text-color** prop (index.vue - 1 instance) |
| 195 | +- **remaining dark** props (Settings.vue - 3 instances) |
| 196 | +- **minor parsing errors** (6 instances) |
| 197 | + |
| 198 | +### 📋 Manual Migration Tasks Required |
| 199 | + |
| 200 | +1. Update all Vue components to use Vue 3 Composition API patterns |
| 201 | +2. Replace `v-model` with `v-model:modelValue` where needed |
| 202 | +3. Update all Vuetify components per migration guide |
| 203 | +4. Replace draggable components with Vue 3 compatible syntax |
| 204 | +5. Update router configuration for Vue Router 4 |
| 205 | +6. Test all functionality after migration |
0 commit comments