This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A distributed smart home system with three layers:
devices/) — IoT devices exposing a REST APIserver/) — central backend that manages devices, events, and automation scriptswebclient/) — JavaScript/SCSS frontend bundled with Gulp/esbuildcd webclient npm install # install dependencies (esbuild, sass, gulp, browser-sync, etc.) npm start # runs gulp: compiles SCSS → dist/css/main.css, bundles JS → dist/js/main.js, watches + live-reloads
No build step. PHP is served directly from server/. Entry point is server/index.php. Configure in server/SHServ/config.php (DB credentials, device IP scan range, debug flag).
Compiled via Arduino IDE or PlatformIO. Each device's .ino file #includes <sh_core.h> from devices/sh_core_esp8266/src/. Pre-built binaries live in devices/builds/.
/about is public (no auth).192.168.x.2–254 (range from config), finds devices via /about.POST /setup on the device, pushing: auth token, server address, device name/alias, channel schema.Authorization: Bearer <token>.GET /about — always public, returns device type/firmware infoGET /status — current channel states (auth required)POST /action — control command (auth required)POST /events/new/api/v1/)/devices/scanning/* — scan network for new devices/devices/setup/new-device — register a found device/devices/id/{id}/* — info, status, control per device/devices/action — execute a device action/areas/* — logical groupings of devices/scripts/* — automation scriptsRoutes are defined as PHP traits in server/SHServ/Routes/ and mixed into the app via server/SHServ/App.php. The underlying framework is a custom MVC called Fury (server/Fury/).
PHP classes in server/ControlScripts/Scopes/, extending ControlScripts base class. Each Scope class implements four methods: register_sync_map, register_events_handlers, register_actions_scripts, register_regular_scripts. All Scopes are auto-loaded at startup. See docs/control-scripts-guide.md.
webclient/src/js/index.js — app entry pointwebclient/src/js/sh/SmartHomeApi.js — all server API callswebclient/src/js/components/ — UI components (hud, modals, toasts, etc.)webclient/src/js/routes.js — frontend routingwebclient/proxy.php — CORS proxy for API calls in devdevices/sh_core_esp8266/src/)Shared Arduino library used by all device firmware:
sh_core.h — EEPROM memory layout, constants, channel type definitionssh_core.cpp — WiFi, OTA, EEPROM helpersREST_API.cpp — device HTTP server and endpoint implementationsWebHandlers.cpp / WebPages.cpp — browser-accessible device config UI| Path | Purpose |
|---|---|
server/SHServ/config.php |
DB credentials, device IP scan range, debug mode |
server/SHServ/Routes/ |
API route definitions (trait-based) |
server/SHServ/Controllers/ |
Request handler logic |
server/SHServ/Models/ |
DB query layer |
server/console.php |
CLI entry point for server-side scripts |
webclient/src/js/sh/SmartHomeApi.js |
JS API client (the contract between frontend and backend) |
devices/sh_core_esp8266/src/sh_core.h |
EEPROM layout and all device-side constants |
docs/device-spec.md |
Device REST API contract (endpoints on the device itself) |
docs/server-api.md |
Server REST API — full reference of all implemented endpoints |
docs/architecture.md |
Full architecture: firmware contract, events routing, sync map, Fury framework |
docs/firmware-dev-guide.md |
How to write firmware for a new device type |
docs/control-scripts-guide.md |
How to write automation scripts (Scope classes) |