Skip to content

Commit 949fc01

Browse files
committed
Add more details to copilot-instructions.md
1 parent e9d7d1e commit 949fc01

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

.github/copilot-instructions.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# qToggleServer – Copilot Instructions
22

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+
37
## Commands
48

59
```bash
@@ -12,9 +16,16 @@ ruff format qtoggleserver # format
1216

1317
Pre-commit hooks run `ruff check` and `ruff format` automatically.
1418

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+
1526
## Architecture
1627

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:
1829

1930
- **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.
2031
- **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`.
@@ -143,3 +154,28 @@ async def get_something(request: core_api.APIRequest) -> dict:
143154
**Access levels:** `ACCESS_LEVEL_NONE=0`, `ACCESS_LEVEL_VIEWONLY=10`, `ACCESS_LEVEL_NORMAL=20`, `ACCESS_LEVEL_ADMIN=30`.
144155

145156
**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

Comments
 (0)