You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# qToggleServer – Copilot Instructions
2
2
3
+
## Environment
4
+
5
+
The Python virtualenv lives at `.venv` in the repo root. Activate it with `source .venv/bin/activate` before running any Python commands. If the virtualenv exists, do not attempt to install `uv`, `pip`, or other tools globally — they are already available inside `.venv`.
6
+
3
7
## Commands
4
8
5
9
```bash
@@ -12,9 +16,16 @@ ruff format qtoggleserver # format
12
16
13
17
Pre-commit hooks run `ruff check` and `ruff format` automatically.
14
18
19
+
Frontend (run from `qtoggleserver/frontend/`):
20
+
```bash
21
+
npx webpack --mode production # build — output goes to dist/
22
+
npx eslint js/ # lint JS
23
+
QUI_PATH=/path/to/qui npx webpack --mode development # dev build with local QUI checkout
24
+
```
25
+
15
26
## Architecture
16
27
17
-
qToggleServer is a [qToggle protocol](https://github.com/qtoggle/docs) server. The main concepts:
28
+
qToggleServer is a [qToggle protocol](https://github.com/qtoggle/docs) server. The HTTP API implementation derives largely from the [qToggle API 1.3 spec](https://github.com/qtoggle/docs/wiki/The-qToggle-API-1.3). The main concepts:
18
29
19
30
-**Ports** (`qtoggleserver/core/ports.py`) — the central abstraction. A port has a boolean or number value and a set of attributes. `BasePort` is the base class; hardware drivers subclass it.
20
31
-**Peripherals** (`qtoggleserver/peripherals/`) — hardware devices that own one or more ports. Subclass `Peripheral` and implement `make_port_args()` to declare ports. Peripherals may run blocking I/O in a `ThreadedRunner`.
**Input validation** — use `core_api_schema.validate(data, json_schema, ...)` (wraps `jsonschema`). Pass `unexpected_field_code` to customise the error code for unrecognised fields.
157
+
158
+
## Frontend
159
+
160
+
The frontend lives at `qtoggleserver/frontend/` and is a single-page application built with vanilla ES2018 modules, webpack 4, and LESS.
161
+
162
+
**UI framework** — [`@qtoggle/qui`](https://github.com/qtoggle/qui) (QUI). Imported via the `$qui/` path alias. The webpack config delegates to `qui/webpack/webpack-common.js`; set `QUI_PATH` env var to use a local checkout instead of the npm package.
163
+
164
+
**Path aliases:**
165
+
-`$qui/` → QUI framework (`node_modules/@qtoggle/qui/js/`)
166
+
-`$app/` → the app's own `js/` directory
167
+
-`$node/` → `node_modules/`
168
+
169
+
**Directory layout (`js/`):**
170
+
-`api/` — thin wrappers around every HTTP endpoint (`ports.js`, `devices.js`, `notifications.js`, etc.). `base.js` handles request signing, time-skew, and error normalisation into `APIError`.
171
+
-`cache.js` — loads and caches device attributes and port list; exposes `Cache.load()`, `Cache.reload()`, `Cache.getMainDevice()`, etc.
172
+
-`events.js` — subscribes to the server notifications (listen) stream and dispatches events to registered listeners.
173
+
-`auth.js` — manages the current access level; exposes `Auth.init()` and access-level-change signals.
174
+
-`dashboard/`, `ports/`, `devices/`, `peripherals/`, `settings/`, `login/` — one QUI *section* per area of the UI.
175
+
-`common/` — shared form mixins and page components (backup/restore, firmware update, reboot, etc.).
176
+
-`widgets/` — reusable QUI widgets specific to this app.
177
+
178
+
**Key conventions:**
179
+
- 4-space indent, single quotes, no semicolons, 120-char line limit (enforced by ESLint via `eslint.config.mjs`).
180
+
- Sections are registered with `Sections.register(SectionClass)` in `index.js`; each section class lives in its own subdirectory and is a QUI `Section` subclass.
181
+
- Server-side frontend events (`DashboardUpdateEvent`, etc.) are defined in `qtoggleserver/frontend/events.py` and extend `core_events.Event`; the frontend's `events.js` handles them via the notifications API.
0 commit comments