From f49c465db48a4dc8519fec910ee05fc69ba458e0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 7 Nov 2026 02:04:45 +0000 Subject: [PATCH] Align the docs with v0.1 as built Cross-check the decisions, plans, install guide, and READMEs against the code merged in PRs #1 to #12, and fix what was stale: - Record decisions 24 to 30, made during the v0.1 build but not yet listed: sync SQLAlchemy with pg8000, the Area and Device UI terms, the Zensical docs site, Load sample data, no data compatibility before v0.3, no guest uploads, and CLI-only restore. - Master plan: replace asyncpg/aiosqlite, httpx, MkDocs Material, and "Room" with what shipped, and add section 12 listing what v0.1 built and which v0.1 items are still to do (scheduled backups and more). - Data storage plan: bring in the v1.4 status from the project copy, correct it now that every PR is merged, and match the BlobStore section to the code. - Front end plan: add the status of its nine steps. - Install guide: replace the "Coming in v0.1" notes with Home Assistant import and search, add the Backups screen, and document the PostgreSQL setting. - README, docs home, AGENTS.md repo map, CONTRIBUTING, sample-home README: small status and wording fixes. Posted by Claude on behalf of @ShaneCurcuru Generated-by: Claude Code Claude-Session: https://claude.ai/code/session_012UmrcmhywhX3LFMkpF4XVh --- AGENTS.md | 4 +- CONTRIBUTING.md | 3 + README.md | 6 +- docs/_prompts/01-decisions.md | 11 ++- docs/_prompts/plan/HomeIOT-Master-Plan.md | 106 ++++++++++++++-------- docs/_prompts/plan/data-storage-backup.md | 71 +++++++++++---- docs/_prompts/plan/frontend-options.md | 16 +++- docs/index.md | 2 +- docs/install-local.md | 71 +++++++++++---- examples/sample-home/README.md | 4 +- 10 files changed, 213 insertions(+), 81 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ccb792d..41f036f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,7 +31,7 @@ say in the PR which way you read it. don't reopen them without a new reason. - **Stop and ask a maintainer first** before you: - add a dependency, a new tool or language, or a GitHub Actions workflow; - - change licensing, the published API shape (`api/`, `openapi/`), or URLs that + - change licensing, the published API shape (`src/domus/api/`, `src/frontend/openapi.json`), or URLs that others may cite; - Make incompatible data structure changes for backup/restore, so that maintainers can decide it a new software version is needed. @@ -49,6 +49,8 @@ say in the PR which way you read it. | `scripts/` | Developer and CI helpers, such as `check_licenses.py` | | `docs/` | Documentation; `docs/_prompts/` holds the design history and plans | | `examples/` | Sample datasets, such as `examples/sample-home/` | +| `deploy/` | Dockerfile, Compose example, Caddy example | +| `mkdocs.yml` | Docs site config, built with Zensical | | `.github/workflows/` | CI: lint, type check, tests, license check | Run the same checks CI runs with `uv run ruff check .`, `uv run ruff format --check .`, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5148d97..d4a0639 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,6 +27,9 @@ uv run pip-licenses --from=mixed --format=json | uv run python scripts/check_lic Tests must not use the network; stub or mock every fetch. +The front end in `src/frontend/` has its own checks (ESLint, Prettier, TypeScript, +Vitest, build, and an npm license check); see [its README](src/frontend/README.md). + ### Testing on PostgreSQL (experimental) SQLite is the default. To run the same suite against a local PostgreSQL 15+ diff --git a/README.md b/README.md index 978eb7c..748d591 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ Holistic home helper: IOT inventory, mapping, control, and Home Assistant integr ## Status -Domus is in early development (v0.1). The design work so far, including the original spec, the decisions made, and the master plan, is in [`docs/_prompts/`](docs/_prompts/README.md). +Domus is in early development. The v0.1 features are merged on `main`; no release is tagged yet. + +What v0.1 does: an inventory of Devices by Property, Building, Floor, and Area; maintenance tasks with due dates, **Mark done**, and an iCal feed; floor plans and wall photos with device pins; import from Home Assistant; search; roles (Admin, Maintainer, Resident, Guest) with access rules and critical items; and backups you can make in the web interface or the CLI, with restore from the CLI. What is still to do from the v0.1 plan, such as scheduled backups, is listed in [section 12 of the master plan](docs/_prompts/plan/HomeIOT-Master-Plan.md#12-v01-status-2026-11-07). + +The design work, including the original spec, the decisions made, and the plans, is in [`docs/_prompts/`](docs/_prompts/README.md). **No data compatibility before v0.3.** During v0.1 and v0.2, database structures, schemas, and backup contents may change in ways that older versions cannot read, and a newer version may not restore an older backup. Don't keep data you care about in Domus yet. diff --git a/docs/_prompts/01-decisions.md b/docs/_prompts/01-decisions.md index ead1d1d..2188931 100644 --- a/docs/_prompts/01-decisions.md +++ b/docs/_prompts/01-decisions.md @@ -1,6 +1,6 @@ # Planning decisions -Decisions made by Shane Curcuru during the initial planning session on 2026-11-06, in the order they were made. The plan documents in [plan/](plan/) reflect all of them. +Decisions made by Shane Curcuru during planning and the v0.1 build (2026-11-06 to 2026-11-07). Numbers are in the order the decisions were recorded here, which is not always the order they were made: decisions 24 to 30 were made during the v0.1 build and recorded in pull requests or project threads before they were added to this list. The plan documents in [plan/](plan/) reflect all of them. ## Kickoff @@ -20,7 +20,7 @@ Decisions made by Shane Curcuru during the initial planning session on 2026-11-0 | 8 | Notifications | iCal feed only for the first version. | | 9 | Buildings | A property can have multiple buildings (house, garage, shed) with basic spatial relationships to each other; a future outdoor map covers landscape lighting and similar. | | 10 | Python version | Python 3.14+ for all work. | -| 11 | Maintainer role | Add a Maintainer role: can add new items and program most IoT/HA items or integrations, but cannot change Admins and cannot edit selected "critical" components. Example: the teenager who adds a game console and TV but is not allowed to access the master bedroom controls. Storage design is proposed in the plan (critical flag + access rules) and awaits confirmation. | +| 11 | Maintainer role | Add a Maintainer role: can add new items and program most IoT/HA items or integrations, but cannot change Admins and cannot edit selected "critical" components. Example: the teenager who adds a game console and TV but is not allowed to access the master bedroom controls. Storage design: a critical flag plus access rules (data-storage-backup.md section 2.3.1), built as written in v0.1 (`src/domus/services/access.py`). | | 12 | Name and repository | The project is named **Domus**; the repository is `punderthings/domus`. | | 13 | Design docs location | Keep the design history in `docs/_prompts/` so all documentation is in one place. | | 14 | AGENTS.md | The plan follows the repository's AGENTS.md (ASF Category A licenses for every dependency, uv, no-network tests, commit trailers, maintainer approval for new dependencies, workflows, and backup-incompatible changes). | @@ -33,3 +33,10 @@ Decisions made by Shane Curcuru during the initial planning session on 2026-11-0 | 21 | Home Assistant client | Add `websockets` (BSD-3-Clause, no dependencies) as a core runtime dependency for the Home Assistant WebSocket API, which is the only API with the device, area, and floor registries (PR #10). | | 22 | Imported device placement | When Home Assistant only knows a device's Area, the import puts it in one general location per Area, of the new location kind `unspecified` ("Somewhere in this area"), so Area filters and access rules cover it; users can move it later (PR #10). | | 23 | Generic BSD license | Packages whose metadata says only "BSD License" are accepted across the board, with no per-package review; "BSD" and "BSD-3-Clause" are both acceptable (Shane, 2026-11-07). | +| 24 | Database layer | Synchronous SQLAlchemy 2 with the standard library `sqlite3` driver. PostgreSQL uses `pg8000>=1.31.5` (BSD-3-Clause, pure Python; 1.31.5 fixes CVE-2025-61385) as the optional `domus[postgres]` extra. This replaces the earlier aiosqlite and asyncpg proposal. Async code is still fine for the Home Assistant WebSocket client (Shane, 2026-11-06). | +| 25 | UI terms | The UI says **Area** (Home Assistant's word, which also covers outdoor spaces) and **Device** (what homeowners say, for a furnace as well as a smart plug). The API and data model keep `area` and `asset`. The display words live in `src/frontend/src/terms.ts` (Shane, 2026-11-06). | +| 26 | Docs site | Build the user docs with Zensical (MIT), configured in `mkdocs.yml`, in its own `docs` dependency group. Its `pathspec` dependency (MPL-2.0) is a build-only tool under decision 20 (Shane, 2026-11-06, PR #9). | +| 27 | Sample data in the UI | An Admin-only **Load sample data** button adds Sample Home as a second property, and the account menu gets a property switcher. The CLI import into a blank instance stays for manual testing (Shane, 2026-11-06, PR #9). | +| 28 | Data compatibility | No database, schema, or backup compatibility is promised during v0.1 and v0.2: schemas may change freely, and a newer version need not open older data or restore older backups. The "migrate forward" rule starts with v0.3 (Shane, 2026-11-06). | +| 29 | Guest uploads | Guests never get upload features: no photos, files, or floor plans. Uploads need Resident or above (Shane, 2026-11-07, PR #8). | +| 30 | Restore in v0.1 | The web UI makes, lists, and downloads backups (Admin of every property only, because a backup holds all of them). Restore stays CLI-only in v0.1, because it replaces the database under the running server (Shane, 2026-11-07, PR #12). | diff --git a/docs/_prompts/plan/HomeIOT-Master-Plan.md b/docs/_prompts/plan/HomeIOT-Master-Plan.md index 9900d78..6a0531e 100644 --- a/docs/_prompts/plan/HomeIOT-Master-Plan.md +++ b/docs/_prompts/plan/HomeIOT-Master-Plan.md @@ -1,6 +1,6 @@ # Home IoT Maintenance App: Master Plan -Status: **Draft v0.3** (2026-11-06). Front end decided (React + Mantine). Backend decided (Python/FastAPI). Name (Domus) and repo (punderthings/domus) decided. Open: confirm the access rule design in section 2. +Status: **v0.4** (2026-11-07). All decisions are recorded in [01-decisions.md](../01-decisions.md). The v0.1 build is merged on `main` (PRs #1 to #12); section 12 lists what is built and what from the v0.1 scope is still to do. No release is tagged yet. Project name: **Domus**. Repository: [punderthings/domus](https://github.com/punderthings/domus). --- @@ -23,8 +23,8 @@ Design principles: | :-- | :-- | | **Admin** | Everything: users, backup/restore, HA connection settings, delete. | | **Maintainer** | Everything a Resident can do, plus adding and configuring devices and integrations: HA connection and import, mapping HA devices to assets, editing rooms and floor plans, and (v0.3+) programming HA items and automations. Cannot manage users or change any Admin, cannot run restore or delete the property, cannot edit critical items, and is limited by any access rules an Admin sets. | -| **Resident** | Create/edit assets, locations, tasks; log maintenance; upload photos; view HA state; trigger HA actions (v2). | -| **Guest** | Sees only items marked public, plus a "house guide" subset (for example, where the water shutoff is). Never sees costs, receipts, serials, or network ids. Can control (v0.2+) only items an access rule allows. | +| **Resident** | Create/edit assets, locations, tasks; log maintenance; upload photos, files, and floor plans; view HA state; trigger HA actions (v0.2+). | +| **Guest** | Sees only items marked public, plus a "house guide" subset (for example, where the water shutoff is). Never sees costs, receipts, serials, or network ids. Never uploads photos, files, or plans (decision 29). Can control (v0.2+) only items an access rule allows. | API tokens (personal access tokens) inherit the owner's role, with an optional read-only scope for integrations. @@ -43,22 +43,23 @@ API tokens (personal access tokens) inherit the owner's role, with an optional r ## 3. Scope by release -**v0.1 MVP** (the schema supports several properties per install, which Shane confirmed; the v0.1 UI shows one property with a switcher added later) +**v0.1 MVP** (the schema supports several properties per install, which Shane confirmed; the v0.1 UI has a property switcher in the account menu, decision 27). Section 12 shows which items are built. - Inventory: assets with name, category, manufacturer, model, serial, MAC, install date, warranty, purchase info, notes, tags, links to manuals. -- Locations: Property > Building > Floor > Room > Location (wall + position, window, ceiling, etc.). A property can have several buildings (house, garage, shed), and outdoor areas (yard, driveway) attach directly to the property. +- Locations: Property > Building > Floor > Area > Location (wall + position, window, ceiling, etc.). A property can have several buildings (house, garage, shed), and outdoor areas (yard, driveway) attach directly to the property. - Maintenance: recurring tasks with intervals ("every 6 months", "every November"), due list, mark done, auto-reschedule, completion log with cost and notes. - Attachments: photos (device label, wall), PDFs (manuals), with thumbnails. - Floor plan viewer: upload an image per floor, drop pins for assets. Wall photo viewer with hotspot pins. - HA import: connect with a long-lived token, preview devices/areas/floors, match existing assets, import selected without duplicates. - Auth: local users with Admin/Maintainer/Resident/Guest. -- Backup/restore: one-click archive (DB + files + manifest), scheduled backups, restore from UI or CLI. +- Backup/restore: one-click archive (DB + files + manifest), scheduled backups, restore from the CLI (restore from the UI was dropped for v0.1, decision 30). - Read-only REST API and iCal feed of upcoming maintenance. +- Search across names, models, serials, MACs, areas, and tags (moved up from v0.2 and built in v0.1). - Example dataset: a small sample property that can be imported in one step, for demos, tests, and trying the app (see section 10, step 11). - Docs: a comprehensive "How To Install Locally" guide, including how to make and restore a backup so maintainers can test upgrades between versions as we build (section 10, step 12). **v0.2** - Live HA context on asset page (state, last seen, IP/network, battery, power source) via WebSocket. -- Search across everything (name, model, serial, MAC, room, tag, circuit). +- Search: add circuits and PDF manual text (basic search shipped in v0.1). - Parts catalog per asset (filter part numbers, purchase links) and procedures (step lists). - Notifications: email (SMTP), HA persistent notification / mobile push via HA, ntfy/webhook. - CSV/JSON export of selected records; printable QR labels for assets. @@ -87,13 +88,13 @@ API tokens (personal access tokens) inherit the owner's role, with an optional r │ ├─ /calendar.ics iCal feed (token in URL, read-only) │ │ ├─ Services: inventory, locations, maintenance, attachments, │ │ │ ha_sync, backup, notifications │ - │ ├─ Scheduler (APScheduler, in-process): due-date checks, backups, │ + │ ├─ Scheduler (APScheduler, in-process, not built yet): backups, │ │ │ HA resync │ - │ └─ HA client (httpx + websockets), optional │ + │ └─ HA client (websockets, sync), optional │ └───────┬──────────────────────────────┬───────────────────────────────┘ ▼ ▼ SQLite (default) or PostgreSQL Files dir (photos, manuals, thumbs, - via SQLAlchemy 2 + Alembic floor plans), content-addressed + via sync SQLAlchemy 2 + Alembic floor plans), content-addressed │ Home Assistant (optional) ◄── REST + WebSocket API ``` @@ -113,8 +114,8 @@ Key decisions: | Building | id, property_id, name, kind (house, garage, shed, barn, pool_house, other), is_primary, notes; site placement (v0.3+): site_x, site_y in meters in a local per-property grid (origin is a user-chosen point, x east, y north), rotation, footprint polygon. No latitude/longitude by default, for privacy. | | SpatialRelation | id, from_type/from_id and to_type/to_id (building or area), kind (attached_to, adjacent_to, detached, connected_by), via (breezeway, buried conduit, ...), distance_m, bearing, notes | | Floor | id, building_id, name, level, floor_plan attachment, ha_floor_id | -| Room (HA "area") | id, floor_id (nullable), property_id, name, kind (room, hallway, attic, yard, driveway, ...), ha_area_id. Outdoor areas have no floor, belong to the property directly, and get site_x, site_y, and a footprint (v0.3+). | -| Location | id, room_id, kind (wall, ceiling, floor, window, door, exterior, inside_asset), wall (N/E/S/W or label), x/y on floor plan, x/y on wall photo, description | +| Area (HA "area"; the UI says Area, decision 25) | id, floor_id (nullable), property_id, name, kind (room, hallway, attic, yard, driveway, ...), ha_area_id. Outdoor areas have no floor, belong to the property directly, and get site_x, site_y, and a footprint (v0.3+). | +| Location | id, area_id, kind (wall, ceiling, floor, window, door, exterior, inside_asset, unspecified for "somewhere in this area", decision 22), wall (N/E/S/W or label), x/y on floor plan, x/y on wall photo, description | | Asset | id (UUIDv7), name, category, manufacturer, model, serial, mac_addresses[], other_ids (JSON), install_date, purchase_date, warranty_until, power_source, network info, location_id, parent_asset_id, status, notes, ha_device_id, ha_entity_ids[] | | Attachment | id, owner (asset/location/floor/task), kind (photo, manual, receipt, label), sha256, mime, filename, url (external link alternative) | | MaintenanceTask | id, asset_id or location_id, title, procedure (markdown), recurrence (RFC 5545 RRULE or "N days after last done"), next_due, lead_time, parts[] | @@ -135,7 +136,7 @@ HA exposes everything we need, without a custom component, through its WebSocket | HA command | Used for | | :-- | :-- | | `config/floor_registry/list` | Floors (HA has no building concept, so on import the user assigns each HA floor to a building, defaulting to the primary building) | -| `config/area_registry/list` | Rooms | +| `config/area_registry/list` | Areas | | `config/device_registry/list` | Devices: manufacturer, model, sw/hw version, serial, `connections` (MAC), `identifiers`, area | | `config/entity_registry/list` | Entities per device | | `config/label_registry/list` | Labels to tags | @@ -154,7 +155,7 @@ Future HA custom integration (v0.3, Python, in a separate repo, HACS-installable ### 4.3 API design -- REST, JSON, `/api/v1`, OpenAPI 3.1 auto-generated, served at `/api/docs`. +- REST, JSON, `/api/v1`, OpenAPI 3.1 auto-generated, served at `/api/v1/docs` (document at `/api/v1/openapi.json`). - Read-only endpoints for every core entity (list with filters + pagination, get by UUID). Write endpoints exist for the UI but are documented as "unstable" until v1.0. - Field naming follows HA where it overlaps (`area_id`, `floor_id`, `device_id`, `manufacturer`, `model`, `sw_version`, `serial_number`, `connections`). - Auth: secure HttpOnly session cookie for the browser (with CSRF token); bearer personal access tokens for integrations. @@ -185,8 +186,8 @@ All front end assets are bundled into the image. No runtime CDN calls, so it wor - Backup = one `.hiotbak` zip containing a consistent DB snapshot, an engine-neutral JSONL export, the referenced files, and a `manifest.json` (app version, schema version, checksums). - Plus a **portable JSON export** of all records so data survives even if the app is abandoned. - Scheduled backups with retention; optional copy to a second path or S3 target. -- Restore runs migrations forward if the backup is from an older schema version. -- Any change that makes older backups incompatible with a new version needs a maintainer decision first, so maintainers can decide whether it needs a new major version (AGENTS.md). +- Restore runs migrations forward if the backup is from an older schema version. This is promised only from v0.3 on: during v0.1 and v0.2, schemas and backups may change with no upgrade path (decision 28). +- From v0.3, any change that makes older backups incompatible with a new version needs a maintainer decision first, so maintainers can decide whether it needs a new major version (AGENTS.md). - CLI `domus backup|restore|export` works with the server stopped and without HA. ## 5. Candidate libraries and licenses (backend) @@ -196,28 +197,29 @@ All front end assets are bundled into the image. No runtime CDN calls, so it wor | Web framework | FastAPI, Starlette, Uvicorn | MIT, BSD-3, BSD-3 | | Models / validation / settings | Pydantic v2, pydantic-settings | MIT | | ORM / migrations | SQLAlchemy 2, Alembic | MIT | -| Postgres driver | asyncpg | Apache-2.0 (**avoid psycopg2/3: LGPL**) | -| SQLite async | aiosqlite | MIT | +| Postgres driver | pg8000 >= 1.31.5, optional `domus[postgres]` extra (decision 24) | BSD-3 (**avoid psycopg2/3: LGPL**) | +| SQLite driver | standard library `sqlite3`, used synchronously | PSF | | Recurrence | python-dateutil (rrule) | Apache-2.0 / BSD dual | | iCal feed | icalendar | BSD-2 | -| Scheduler | APScheduler 3.x | MIT | -| HTTP / WebSocket to HA | httpx, websockets | BSD-3 | +| Scheduler | APScheduler 3.x (not added yet; needs a maintainer's OK) | MIT | +| WebSocket to HA | websockets (decision 21). httpx is not used: it pulls in certifi (MPL-2.0) | BSD-3 | | Password hashing | argon2-cffi | MIT | -| Encryption | cryptography | Apache-2.0 / BSD | +| Encryption | cryptography (not added yet) | Apache-2.0 / BSD | | Images | Pillow | MIT-CMU / HPND (the Python Imaging Library license, ASF Category A) | -| QR labels | segno | BSD-3 | -| Fuzzy match on import | rapidfuzz | MIT | +| QR labels | segno (v0.2, not added yet) | BSD-3 | +| Fuzzy match on import | standard library `difflib` in v0.1; rapidfuzz (MIT) only if it proves too slow | PSF | | CLI | Typer | MIT | | Tests / lint / types | pytest, ruff, pyright (not mypy: it depends on pathspec, MPL-2.0) | MIT | | Search | SQLite FTS5 / Postgres full-text (built in) | Public domain / PostgreSQL | +| Docs site | Zensical (decision 26) | MIT | -A CI step (`pip-licenses` MIT, and `license-checker` for the JS side) fails the build on any dependency that is not ASF Category A in the core install or the Docker image, including transitive ones. Optional extras such as `domus[heic]` (libheif, LGPL) live in a separate dependency group that is excluded from the core image and checked separately. They are off unless the user installs and enables them. +A CI step (`pip-licenses` MIT with `scripts/check_licenses.py`, and `src/frontend/scripts/check-licenses.mjs` for the JS side, which needs no extra package) fails the build on any dependency that is not ASF Category A in the core install or the Docker image, including transitive ones. Optional extras such as `domus[heic]` (libheif, LGPL) live in a separate dependency group that is excluded from the core image and checked separately. They are off unless the user installs and enables them. ## 6. Database and storage Full design: [data-storage-backup.md](data-storage-backup.md). It confirms the stack in section 4 and adds the following. -- **SQLite 3 in WAL mode is the official database.** PostgreSQL 15+ is supported behind the same SQLAlchemy models but is marked experimental in v1. Drivers are aiosqlite and asyncpg. +- **SQLite 3 in WAL mode is the official database.** PostgreSQL 15+ is supported behind the same SQLAlchemy models but is marked experimental in v1. SQLAlchemy is used synchronously, with the standard library `sqlite3` driver and `pg8000` for Postgres (decision 24). - **UUIDv7 for every row**, stored as text so exports stay readable. - **`asset_identifier` table**: MAC addresses, serials, HA device/entity ids, and any other ids live here, one row each. This is what drives HA import dedupe and lookup by any id. - **`asset_relation` graph**: `powered_by`, `networked_via`, `shutoff_for`, and so on. Circuits, breakers, pipes, and valves (v0.3) become ordinary assets with relations, so they need no schema redesign. @@ -254,21 +256,21 @@ Shared across all options: domus/ pyproject.toml, uv.lock one Python project at the repo root (PyPA src layout) src/ - domus/ Python package: api/, services/, models/, ha/, backup/, cli/, - migrations/ (Alembic), static/ (built front end, git-ignored) + domus/ Python package: api/, services/, models/, homeassistant/, backup/, + cli.py, migrations/ (Alembic), static/ (built front end, git-ignored) frontend/ React + Mantine SPA (Vite, TypeScript strict); its build output is copied into src/domus/static/ for the wheel and image tests/ pytest tests for src/domus (outside src/, per PyPA) - docs/ (MkDocs Material, MIT; docs/_prompts/ holds the human + AI design history) + docs/ (Zensical site from mkdocs.yml, MIT; docs/_prompts/ holds the human + AI design history) deploy/ Dockerfile, compose.yaml, Caddyfile example examples/ sample datasets (examples/sample-home/) - .github/ CI: lint, typecheck, test, license check, build image - LICENSE (Apache-2.0), NOTICE, CONTRIBUTING.md, SECURITY.md + .github/ CI: lint, typecheck, test, license check (an image build job is not added yet) + LICENSE (Apache-2.0), NOTICE, CONTRIBUTING.md (SECURITY.md is not written yet) ``` - All source code lives under `src/` (AGENTS.md, PyPA src layout): the importable Python package is `src/domus/`, and the front end source is `src/frontend/`. Alembic migrations live inside the package so they ship in the wheel. - Python 3.14+ everywhere, managed with uv (`requires-python = ">=3.14"`, ruff `target-version = "py314"`), PEP 8. Pre-commit with ruff (lint+format), pyright strict on backend, ESLint + Prettier + TypeScript strict on front end. -- Tests: pytest with a fake HA WebSocket server fixture; Playwright (Apache-2.0) end-to-end for the five core workflows. Tests never use the network; every fetch is stubbed or mocked. +- Tests: pytest with a fake HA WebSocket server fixture (`tests/fake_ha.py`) and Vitest for the front end. Playwright (Apache-2.0) end-to-end tests for the five core workflows are planned but not added yet. Tests never use the network; every fetch is stubbed or mocked. - Conventional commits, semantic versioning, release images to GHCR. - Follow [AGENTS.md](../../../AGENTS.md) for all agent work: branch and PR only (never push to `main`), small diffs, a `Generated-by:` commit trailer for AI-assisted commits, and GitHub Actions pinned to full commit SHAs. Adding a dependency, tool, language, or GitHub Actions workflow, changing the published API, or making a backup-incompatible change needs a maintainer's OK first, so each step below that does one of these starts by asking. - DCO or simple CLA-free Apache-2.0 contributions. @@ -281,8 +283,8 @@ domus/ | Import HA devices | v0.1 | HA connect, registry fetch, match preview, idempotent import | | Troubleshoot a device | v0.1 docs/history, v0.2 live HA state | Asset detail page: docs, HA context, network, power, service history | | Perform maintenance | v0.1 mark done + cost, v0.2 parts/procedures | Task detail, completion form, next-due calculation | -| Find equipment physically | v0.1 room/tag filter + floor plan, v0.2 search, v0.3 circuit | Filters, floor plan pins, search | -| Recover or transfer records | v0.1 | Backup/restore UI + CLI, JSON export | +| Find equipment physically | v0.1 area/tag filter + floor plan + search, v0.3 circuit | Filters, floor plan pins, search | +| Recover or transfer records | v0.1 | Backup UI (make and download) + CLI (backup, verify, restore), JSON export | ## 10. First implementation steps (prioritized) @@ -296,16 +298,16 @@ domus/ 8. **Front end shell** (React + Mantine + TanStack Router/Query, Vite): app layout, login, inventory list/detail, asset form, due-maintenance dashboard. 9. **Floor plan + wall photo pins**: upload plan image per floor, place/drag asset pins, hotspot pins on wall photos. 10. **HA import**: connect screen, registry fetch, matcher, preview, idempotent apply; fake-HA test fixture. -11. **Example dataset import**: make `examples/sample-home/` importable with `domus restore examples/sample-home --merge` (and a "Load sample data" button on an empty install), plus a test that imports it into a fresh database and checks row counts. The dataset is already in the repo: one property, one house, a few rooms, and a handful of different devices with maintenance tasks. +11. **Example dataset import**: make `examples/sample-home/` importable with `domus restore examples/sample-home --merge` (and an Admin-only "Load sample data" button that adds it as a second property, decision 27), plus a test that imports it into a fresh database and checks row counts. The dataset is already in the repo: one property, one house, a few rooms, and a handful of different devices with maintenance tasks. 12. **Docs: "How To Install Locally" guide** (`docs/install-local.md`): prerequisites; install with uv and with Docker; first run and admin setup; loading the sample data; connecting Home Assistant (optional); where data and backups live; **making a backup, restoring it, and verifying it**; and an "upgrade test" checklist so maintainers can back up on one version, upgrade or downgrade, restore, and compare as we build. Kept up to date with each release. -13. **v0.1 release**: Docker image, Compose example, docs site. +13. **v0.1 release**: Docker image, Compose example, docs site. Publishing the image, a CI docs job, docs hosting, and the release tag each need a maintainer's OK. 14. **Future, after v0.3: basic Apple HomeKit integration** (see section 3). Steps 2 to 7 can start immediately. Step 8 uses React + Mantine and follows the 9-step front end list in [frontend-options.md](frontend-options.md). ## 11. Open questions for Shane -- Critical items and access rules: does the design in section 2 fit what you want? It is written out using your master bedroom examples. +None open. The critical-item and access-rule design in section 2 was built as written in v0.1 (decision 11). 1. ~~Backend language?~~ Answered: Python/FastAPI. 2. ~~Multiple properties?~~ Answered: yes, in the schema. @@ -317,3 +319,35 @@ Steps 2 to 7 can start immediately. Step 8 uses React + Mantine and follows the 8. ~~Backup encryption?~~ Answered: optional. 9. ~~HEIC?~~ Answered: optional extra only. LGPL is never allowed in core. 10. ~~Guest limits?~~ Answered: guests are limited in what they see and control, implemented with access rules (section 2). + +## 12. v0.1 status (2026-11-07) + +Everything below is merged on `main`. No release is tagged. + +**Built** (step numbers from section 10) + +| Step | What shipped | PR | +| :-- | :-- | :-- | +| 1 | Repo bootstrap: uv project, pre-commit, CI (ruff, pyright, pytest, Python and npm license checks); a manual dependency security audit script (`scripts/security_audit.py`, not in CI) | #2, #5, #7 | +| 2 to 4 | FastAPI app, settings, sync SQLAlchemy + Alembic, SQLite WAL, health and OpenAPI at `/api/v1/docs`; the full data model; first-run setup, session cookie with CSRF, login rate limit, roles, critical items, access rules (`AccessPolicy`), personal access tokens, guest-safe responses; read and write endpoints | #4 | +| 5 | Local blob store, uploads with type sniffing and size limits, images re-encoded with Pillow to strip EXIF and GPS, external links; Residents and above only (decision 29) | #8 | +| 6 | `compute_next_due` for RRULE and floating tasks, due list, mark done with cost, event log, iCal feed at `/calendar.ics` (token with the `calendar` scope) | #4, #12 | +| 7 | JSONL export, `.hiotbak` backup, verify, restore with `--merge` and `--dry-run`, safety copy before restore; search index (SQLite FTS5, Postgres `tsvector` + `pg_trgm`), with the suite passing on Postgres 16 | #4, #11 | +| 8 | Front end (React + Mantine, generated API types, served by `domus serve`): login, setup, overview with due maintenance, Areas, Devices list and detail, device add and edit, mark done, search, Admin backup screen (make, list, download) | #3, #6, #11, #12 | +| 9 | Floor plan and wall photo pin editor (react-konva, normalized coordinates) | #8 | +| 10 | Home Assistant import: connect with a token used once and never stored, preview, floor-to-building mapping, idempotent apply, fake HA server for tests | #10 | +| 11 | `domus restore examples/sample-home --merge` and the **Load sample data** button | #4, #9 | +| 12 | [Install guide](../../install-local.md) with backup, restore, and the upgrade test checklist | #9 | +| 13 (part) | Dockerfile, Compose example, Caddy example, Zensical docs site config | #9 | + +**v0.1 scope not built yet** + +1. Scheduled backups with 7/4/12 retention, the weekly automatic verify, and the "last backup N days ago" warning. Needs a scheduler (APScheduler, MIT), which needs a maintainer's OK. +2. Restore from the web UI: deferred on purpose (decision 30). +3. Screens for attaching photos and manuals to a device, and for managing members, access rules, critical flags on Areas, personal access tokens, and the calendar feed URL. The API supports all of them; the UI does not yet. +4. Thumbnails for photos and PDFs. +5. The maintenance calendar view (FullCalendar) and the installable PWA. +6. Playwright end-to-end tests. +7. Release work (step 13): set the package version, publish the Docker image, a CI docs job and docs hosting, and the tag. Each needs a maintainer's OK. + +**Designed for later and not in v0.1:** optional backup encryption (`age`), the S3-compatible blob store and off-site upload, unreferenced-blob cleanup, partial export with closure, house handover export, CSV export, HEIC as an opt-in extension, Postgres in CI, and live Home Assistant context and control (v0.2). See data-storage-backup.md section 8. diff --git a/docs/_prompts/plan/data-storage-backup.md b/docs/_prompts/plan/data-storage-backup.md index 9879b30..9df1319 100644 --- a/docs/_prompts/plan/data-storage-backup.md +++ b/docs/_prompts/plan/data-storage-backup.md @@ -1,6 +1,6 @@ # Home IoT Maintenance App: Data Model, Storage, and Backup Design -Status: v1.3 (2026-11-06). Maintainer role, critical items, and per-role room restrictions added (section 2.3.1). Open questions answered by Shane (section 6); multiple buildings per property added (section 2.3, 2.3.2). Source spec: `HomeIOTManagementApp.md`. +Status: v1.4 (2026-11-07). Implementation status and remaining work are in section 8. Maintainer role, critical items, and per-role room restrictions added (section 2.3.1). Open questions answered by Shane (section 6); multiple buildings per property added (section 2.3, 2.3.2). Source spec: `HomeIOTManagementApp.md`. Assumes the stack from the master plan ([HomeIOT-Master-Plan.md](HomeIOT-Master-Plan.md)): Python + FastAPI, SQLAlchemy 2.x + Alembic, SQLite by default, PostgreSQL optional. --- @@ -12,9 +12,9 @@ Assumes the stack from the master plan ([HomeIOT-Master-Plan.md](HomeIOT-Master- | Primary database | **SQLite 3 (WAL mode)**, single file. One household is thousands of rows, not millions; zero setup, works offline on a laptop, trivially backed up. | Public domain | | Optional database | **PostgreSQL 15+** for cloud / multi-instance deployments, behind the same SQLAlchemy models. | PostgreSQL License (permissive) | | ORM / migrations | SQLAlchemy 2.x + Alembic (batch mode for SQLite `ALTER`s). | MIT / MIT | -| DB drivers | `aiosqlite` for SQLite, **`asyncpg`** for Postgres (psycopg is LGPL, so avoid). | MIT / Apache-2.0 | +| DB drivers | Synchronous SQLAlchemy: standard library `sqlite3`, and **`pg8000>=1.31.5`** for Postgres as the optional `domus[postgres]` extra (psycopg is LGPL, so avoid). This replaced the earlier aiosqlite and asyncpg proposal (decision 24). | PSF / BSD-3 | | IDs | **UUIDv7** (RFC 9562, time-ordered) for every row, generated by the app. Stored as 36-char text for portability and readability in exports. Python 3.14 has `uuid.uuid7()`; otherwise `uuid6` package (MIT). | | -| File storage | **Content-addressed blob store** (SHA-256 keyed) behind a small `BlobStore` interface. Default: local filesystem. Optional: any S3-compatible service via `boto3`/`aioboto3`. | Apache-2.0 | +| File storage | **Content-addressed blob store** (SHA-256 keyed) behind a small `BlobStore` interface. Default: local filesystem. Optional: any S3-compatible service via `boto3`. | Apache-2.0 | | Image processing | Pillow for thumbnails and EXIF/GPS stripping. pdf.js in the browser to render manuals. **Avoid** `sharp`/libvips (LGPL), MuPDF (AGPL), Poppler (GPL), MinIO and Garage (AGPL) as bundled dependencies. | HPND / Apache-2.0 | | Recurrence | `python-dateutil` `rrule` (RFC 5545) for calendar-fixed schedules, plus a simple "N days/months after last completion" mode. | Apache-2.0 / BSD | | Search | SQLite FTS5 virtual table (Postgres: `tsvector` + `pg_trgm`), wrapped in one `SearchIndex` service. | built in | @@ -77,8 +77,8 @@ erDiagram | `building` | property_id, name, kind (house, garage, shed, barn, workshop, pool_house, cottage, other), is_primary, year_built, notes, site_x, site_y, rotation_deg, footprint (GeoJSON polygon, nullable) | A structure on the property. Every property gets one default building ("House") so the simple case needs no extra setup. The `site_*` and `footprint` columns are nullable placeholders for the future outdoor map, in site coordinates (section 2.3.2). | | `floor` | building_id, name, level (int), ha_floor_id | Mirrors HA floors. HA has no building concept, so on import the import preview asks which building each HA floor belongs to, defaulting to the primary building. | | `spatial_relation` | property_id, from_type (building, area), from_id, to_type, to_id, kind (attached_to, adjacent_to, detached_from, connected_by), via (breezeway, underground_conduit, path, driveway, free text), distance_m, bearing_deg, notes | Basic relationships between buildings and outdoor areas: "garage attached to house, east side", "shed 25 m north of house, power via buried conduit". Physical utility runs between buildings (a subpanel in the garage fed from the house panel) stay in `asset_relation`. | -| `area` | property_id, building_id (nullable), floor_id (nullable), name, kind (room, hallway, attic, crawlspace, basement, yard, garden, driveway, patio, pool, other_outdoor), site_x, site_y, footprint (nullable), ha_area_id, is_critical (bool, default false) | HA calls rooms "areas"; we keep that name in code, show "Room" in the UI. Indoor areas have a `floor_id` (and its building); outdoor areas such as the yard or driveway have no building or floor and hang off the property directly, ready for landscape lighting and irrigation on the outdoor map. A check constraint enforces: floor set implies building set and matching. | -| `location` | area_id, parent_location_id, name, kind (wall, window, door, ceiling, floor, cabinet, closet, exterior_wall), orientation (N/E/S/W or free text), position_note | The "north wall, left of the window" level. Self-nesting allows "cabinet under sink > back panel". | +| `area` | property_id, building_id (nullable), floor_id (nullable), name, kind (room, hallway, attic, crawlspace, basement, yard, garden, driveway, patio, pool, other_outdoor), site_x, site_y, footprint (nullable), ha_area_id, is_critical (bool, default false) | HA calls rooms "areas"; we keep that name in code and show "Area" in the UI too (decision 25). Indoor areas have a `floor_id` (and its building); outdoor areas such as the yard or driveway have no building or floor and hang off the property directly, ready for landscape lighting and irrigation on the outdoor map. A check constraint enforces: floor set implies building set and matching. | +| `location` | area_id, parent_location_id, name, kind (wall, window, door, ceiling, floor, cabinet, closet, exterior_wall, unspecified), orientation (N/E/S/W or free text), position_note | The "north wall, left of the window" level. Self-nesting allows "cabinet under sink > back panel". `unspecified` is the one "Somewhere in this area" location per area that Home Assistant import uses when HA knows only the area (decision 22). | **Assets (devices, appliances, equipment)** @@ -199,16 +199,19 @@ A single `data_dir` setting (default `~/.local/share//` on a laptop, `/data ### 3.2 `BlobStore` interface +As built in v0.1 (`src/domus/services/blobstore.py`), the store is synchronous except for reading the upload body: + ```python -class BlobStore(Protocol): - async def put(self, stream: AsyncIterator[bytes], mime: str) -> BlobRef: ... # hashes while streaming, returns sha256 - async def open(self, sha256: str) -> AsyncIterator[bytes]: ... - async def exists(self, sha256: str) -> bool: ... - async def delete(self, sha256: str) -> None: ... - async def iter_all(self) -> AsyncIterator[str]: ... +class LocalFsBlobStore: + def path(self, sha256: str) -> Path: ... + def exists(self, sha256: str) -> bool: ... + async def stage_stream(self, chunks: AsyncIterator[bytes], *, max_bytes: int) -> Path: ... # size limit while streaming + def commit(self, staged: Path) -> StoredBlob: ... # hash, then atomic rename to blobs/ ``` -- `LocalFsBlobStore` (default): write to a temp file, fsync, atomic rename into place. +A `BlobStore` protocol with `open`, `delete`, and `iter_all` comes with the second implementation (S3) and the cleanup job; neither is built yet. + +- `LocalFsBlobStore` (default): write to a staging file, then an atomic rename into place under its SHA-256. - `S3BlobStore` (optional): any S3-compatible endpoint (AWS S3, Backblaze B2, Cloudflare R2, or a self-hosted SeaweedFS which is Apache-2.0). We do not bundle or require MinIO/Garage because of AGPL. - Content addressing gives free dedupe (the same manual PDF attached to 6 smoke detectors is stored once), integrity checks (re-hash and compare), and simple backup diffing. - Unreferenced blobs are removed by a mark-and-sweep job with a 7-day grace period, so an in-progress upload or a recent undo never loses data. @@ -244,19 +247,19 @@ How the snapshot is taken safely while the app runs: SQLite `VACUUM INTO 'tmp.sq ### 4.2 Backup features -- **Manual backup**: "Download backup" button (Admin only) and `domus backup create` CLI. +- **Manual backup**: "Make a backup now" and download on the Backups screen, and `domus backup create` CLI. Backups hold every property, so only someone who is Admin of every property can make or download one (PR #12). - **Scheduled backups**: built-in scheduler (APScheduler, MIT) writes to `backups/` daily by default. - **Retention**: keep 7 daily, 4 weekly, 12 monthly by default; configurable. - **Optional encryption**: passphrase-encrypted archive using the `age` format via `pyrage` (MIT/Apache-2.0), so backups can be safely copied to cloud storage and decrypted with the standard `age` CLI. Passphrase never stored by the app. - **Off-site copies**: optional `S3BlobStore`-style upload target for archives, plus documented recipes for restic and Litestream for users who already run them. -- **Verify**: `domus backup verify ` and a UI button check every hash, open the snapshot, run `integrity_check`, and confirm every referenced blob is present. A scheduled weekly verify of the newest backup catches silent corruption. +- **Verify**: `domus backup verify ` (and later a UI button) check every hash, open the snapshot, run `integrity_check`, and confirm every referenced blob is present. A scheduled weekly verify of the newest backup catches silent corruption. - **Health indicator**: the admin dashboard shows "last successful backup N days ago" and warns after a configurable threshold. ### 4.3 Restore -- **Full restore (replace)**: Admin only, works with Home Assistant offline. Steps: verify archive, take an automatic safety backup of the current state, restore into a new temp database, run Alembic migrations forward if the archive is older, copy blobs, then atomically swap the database file and restart the app's DB pool. If anything fails, the current data is untouched. -- **Merge import**: load JSONL rows and upsert by UUID. Rules: newer `updated_at` wins by default; conflicts are listed in a preview for the user to accept per record. Soft-deleted rows propagate deletions. This is the same code path used by partial exports and HA-free transfers between installs. -- **Version rules**: restoring an archive from an older app version is always supported (migrate forward). Restoring a newer archive into an older app is refused with a clear message. +- **Full restore (replace)**: CLI only in v0.1 (decision 30), works with Home Assistant offline. Steps: verify archive, take an automatic safety backup of the current state, restore into a new temp database, run Alembic migrations forward if the archive is older, copy blobs, then atomically swap the database file and restart the app's DB pool. If anything fails, the current data is untouched. +- **Merge import**: load JSONL rows and upsert by UUID. Rules: newer `updated_at` wins by default; `--dry-run` shows the counts first. (A per-record conflict preview for the user to accept is designed but not built.) Soft-deleted rows propagate deletions. This is the same code path used by partial exports and HA-free transfers between installs. +- **Version rules**: from v0.3 on, restoring an archive from an older app version is always supported (migrate forward). Before v0.3 this is not promised (decision 28). Restoring a newer archive into an older app is refused with a clear message. - **CLI first**: `domus restore [--merge] [--dry-run]` exists so recovery works even if the web UI is broken. ### 4.4 Export and transfer @@ -274,16 +277,16 @@ How the snapshot is taken safely while the app runs: SQLite `VACUUM INTO 'tmp.sq ## 5. Postgres support: scope for v1 -Keep the schema portable from day one (SQLAlchemy types only, UUIDs as text, JSON via SQLAlchemy `JSON`, FTS behind `SearchIndex`), and run the test suite against both engines in CI. Recommendation: ship v1 officially on SQLite, mark Postgres as "supported, experimental" until the cloud deployment story is built. Moving between them is just backup on one, restore (JSONL path) on the other. +Keep the schema portable from day one (SQLAlchemy types only, UUIDs as text, JSON via SQLAlchemy `JSON`, FTS behind `SearchIndex`), and run the test suite against both engines (in v0.1 by hand with `DOMUS_TEST_DATABASE_URL`; a Postgres CI job needs a maintainer's OK). Recommendation: ship v1 officially on SQLite, mark Postgres as "supported, experimental" until the cloud deployment story is built. Moving between them is just backup on one, restore (JSONL path) on the other. --- ## 6. Decisions (answered by Shane, 2026-11-06) 1. **Multiple properties per install: yes.** The schema already carries `property_id`; the UI needs a property switcher. -2. **PostgreSQL: experimental in v1.** SQLite is the official engine; Postgres is tested in CI but labelled experimental. +2. **PostgreSQL: experimental in v1.** SQLite is the official engine; Postgres is labelled experimental. In v0.1 the whole suite passes on Postgres 16 when run by hand; it is not in CI yet. 3. **Backup encryption: yes, optional.** Off by default for local backups, offered (and recommended) when an off-site or cloud target is configured. -4. **HEIC: optional only.** Project-wide rule: never use LGPL (or any FSF-licensed) code in the core application, only as an extension a user explicitly asks to install. CI should run a license check (e.g. `pip-licenses --fail-on` with a list of GPL/LGPL/AGPL identifiers) on the core dependency set. +4. **HEIC: optional only.** Project-wide rule: never use LGPL (or any FSF-licensed) code in the core application, only as an extension a user explicitly asks to install. CI runs a license check (`pip-licenses` plus `scripts/check_licenses.py`, which allows only ASF Category A) on the core dependency set and every dependency group. 5. **Guests: limited both in what they see and what they control**, per room and per device. Designed in section 2.3.1. 6. **Maintainer role added** (between Admin and Resident): can add items and configure most devices and HA integrations, but cannot change admins or roles and cannot manage items marked critical; rooms can be restricted per role or per person. Designed in section 2.3.1. @@ -299,3 +302,31 @@ Keep the schema portable from day one (SQLAlchemy types only, UUIDs as text, JSO 6. Implement the `AccessPolicy` service (four roles, access levels, rules, critical items) with a table-driven test suite covering role defaults, area vs asset vs tag precedence, membership vs role rules, expiry, and critical inheritance, before any endpoint ships. 7. Add the FTS5 search index and read-only REST endpoints over the same service layer. 8. CI: run model, migration, and backup round-trip tests (backup, wipe, restore, compare row counts and hashes) on SQLite and Postgres. + +--- + +## 8. Implementation status (2026-11-07) + +No schema or backup-format compatibility is promised before v0.3 (decision 28); section 4.3's "migrate forward" rule applies from v0.3 on. + +**Built and merged** +- Data model and migrations for every table in section 2, plus `canvas` and `placement` (migrations 0001 to 0003), JSONL export and import, `.hiotbak` backup, verify, restore with `--merge` and `--dry-run`, the safety copy before restore, and the sample-home import (PR #4). +- `AccessPolicy` with roles, access rules, and critical items, with table-driven tests (`src/domus/services/access.py`, PR #4). +- iCalendar feed at `/calendar.ics`, read with a personal access token that has the `calendar` scope (PR #4). +- Local blob store, uploads with type sniffing, size limits, and EXIF stripping; Residents and above only (decision 29, PR #8). +- Search: SQLite FTS5 `search_fts` and Postgres `search_doc` (`tsvector` + `pg_trgm`); the suite passes on Postgres 16 by hand (PR #11). +- Backup screen for making, listing, and downloading backups (PR #12). Restore stays CLI-only (decision 30). + +**Designed here but not built yet** +1. Scheduled backups with 7/4/12 retention, the weekly automatic verify, and the "last backup N days ago" admin warning (section 4.2). +2. Optional backup encryption with the `age` format (section 4.2). Check `pyrage` against AGENTS.md's ASF Category A rule before adding it. +3. S3-compatible blob store and off-site backup upload (sections 3.2, 4.2). +4. Unreferenced-blob cleanup with a 7-day grace period (section 3.2), and thumbnails. +5. Partial export with closure, house handover export, CSV export, and the published JSON Schema (section 4.4). `domus export` today writes every record except accounts. +6. The per-record merge conflict preview (section 4.3). +7. The guest-only Home Assistant control proxy (section 2.3.1); HA control itself is v0.2. +8. A Postgres CI job (section 5). +9. HEIC support as an opt-in extension only (section 3.3). +10. Later: PDF manual text in search, the site map and outdoor areas on a map (v0.3+, section 2.3.2), and the optional geo anchor. + +**Open decisions:** none blocking. A scheduler for item 1 (APScheduler, MIT), an encryption library for item 2, and a Postgres CI job need a maintainer's OK under AGENTS.md before they are added. diff --git a/docs/_prompts/plan/frontend-options.md b/docs/_prompts/plan/frontend-options.md index 6fbf879..f44951d 100644 --- a/docs/_prompts/plan/frontend-options.md +++ b/docs/_prompts/plan/frontend-options.md @@ -1,6 +1,6 @@ # Front end architecture options -*Home IoT Maintenance App · prepared 2026-11-06 · status: **decided 2026-11-06: Option A, React + Mantine** (Shane, citing the wide contributor pools)* +*Home IoT Maintenance App · prepared 2026-11-06 · status: **decided 2026-11-06: Option A, React + Mantine** (Shane, citing the wide contributor pools). v0.1 status is at the end.* ## What the front end has to do @@ -128,4 +128,18 @@ Pick **B** if you value a lean, fast UI and are happy to assemble more widgets. 8. Build the HA import preview (backend does discovery; UI shows match, merge, and select). 9. Configure the PWA and test it on a phone over the LAN. +## Status of these steps in v0.1 (2026-11-07) + +Built and merged (PRs #3, #6, #8, #10, #11, #12): + +- Step 1, except Playwright: Vite 8 app in `src/frontend/` with ESLint, Prettier, Vitest, and a lockfile license check (`scripts/check-licenses.mjs`, no extra package) in CI. lightningcss (MPL-2.0) is allowed as a build-only tool (decision 20). +- Step 2: `openapi-typescript` with `openapi-fetch`; CI fails if `openapi.json` or `src/api/schema.d.ts` drifts. +- Step 3, with one change: the system font stack instead of bundled fonts, because most open fonts use the OFL (ASF Category B). +- Steps 4 and 5, without the calendar view: Devices list and detail, device add and edit, the due maintenance list, and **Mark done** with cost. The UI says "Area" and "Device" (decision 25). +- Steps 6 and 7: floor plans and wall photos with draggable pins (react-konva, normalized coordinates). +- Step 8: Home Assistant import preview and apply. +- Also: search, the Admin backup screen, and **Load sample data** with a property switcher. + +Not built yet: Playwright tests, the maintenance calendar (FullCalendar), the PWA (step 9), attaching photos and manuals to a device from the UI (the API supports it; step 4's camera upload), and screens for members, access rules, personal access tokens, and the calendar feed URL. TanStack Table, `@mantine/dates`, `@mantine/dropzone`, and `dayjs` were not needed so far. + *Versions and licenses were checked against the npm registry on 2026-11-06.* diff --git a/docs/index.md b/docs/index.md index d184c62..97da380 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,7 +5,7 @@ devices, where they are, how to maintain them, and how they connect to Home Assi It runs on your own computer or home server, works offline, and keeps your data in one folder that you can back up and restore. -Domus is in early development (v0.1). +Domus is in early development. The v0.1 features are built; no release is tagged yet. - **[Install locally](install-local.md)**: run Domus with uv or Docker, load the sample home, and back up and restore your data. diff --git a/docs/install-local.md b/docs/install-local.md index b493f9f..1459d62 100644 --- a/docs/install-local.md +++ b/docs/install-local.md @@ -4,8 +4,8 @@ This guide gets Domus running on one computer, loads the sample home so you have something to click through, and shows how to back up, restore, and check your data. The last section is a checklist for testing upgrades. -It describes what is on `main` today (v0.1 in progress). Notes marked **Coming in v0.1** -mark where features that are still being built will be documented. +It describes what is on `main` today: the v0.1 features are merged, and no release is +tagged yet. > **Before v0.3, upgrades may not keep your data.** The database schema and backup format > can still change between versions with no upgrade path, so a newer Domus may not open @@ -21,10 +21,11 @@ mark where features that are still being built will be documented. 5. [Load the sample home](#load-the-sample-home) 6. [Connect Home Assistant (optional)](#connect-home-assistant-optional) 7. [Where your data lives](#where-your-data-lives) -8. [Back up, verify, and restore](#back-up-verify-and-restore) -9. [Upgrade test checklist](#upgrade-test-checklist) -10. [Settings](#settings) -11. [Troubleshooting](#troubleshooting) +8. [Search](#search) +9. [Back up, verify, and restore](#back-up-verify-and-restore) +10. [Upgrade test checklist](#upgrade-test-checklist) +11. [Settings](#settings) +12. [Troubleshooting](#troubleshooting) ## Prerequisites @@ -161,7 +162,7 @@ curl http://127.0.0.1:8000/api/v1/health # {"status":"ok","version":"... ## Load the sample home The sample home in [`examples/sample-home/`](https://github.com/punderthings/domus/tree/main/examples/sample-home) is a -small fictional property: one house, two floors, four rooms, nine devices, five +small fictional property: one house, two floors, four areas, nine devices, five maintenance tasks (two already overdue), tags, and access rules. Use it to try Domus or to test changes by hand. @@ -169,7 +170,7 @@ There are two ways to load it. Both give you the same data. ### From the web interface -Sign in as an Admin. While your property has no rooms yet (as it is right after setup), +Sign in as an Admin. While your property has no areas yet (as it is right after setup), the Overview shows **Try Domus with sample data**. Select **Load sample data**: Domus adds Sample Home as a second property, makes you its Admin, and switches to it. Your own property isn't changed. To switch between the two, open the account menu (the round @@ -230,13 +231,36 @@ To start over, stop the server and delete the data folder (here `.domus-test`; f ## Connect Home Assistant (optional) -Domus works on its own; Home Assistant is optional. Devices already have fields for -Home Assistant device and entity ids (the sample Living Room Light Switch has them), and -you can fill those in by hand today. - -> **Coming in v0.1:** importing areas and devices from Home Assistant. This section will -> cover creating a long-lived access token in Home Assistant, giving it to Domus, and -> running the import. +Domus works on its own; Home Assistant is optional. In v0.1, Domus can import floors, +areas, and devices from Home Assistant. Live state and control from Domus come in v0.2. + +You need to be a Maintainer or Admin in Domus, and the Domus server must be able to reach +Home Assistant over the network. + +1. In Home Assistant, open your profile (your name, bottom left), go to the **Security** + tab, and under **Long-lived access tokens** select **Create token**. Use a Home + Assistant admin user, because only admins can read the device registry. Copy the token. +2. In Domus, select **Import from HA** in the menu. Enter the address you open Home + Assistant at (for example `http://homeassistant.local:8123`) and paste the token. +3. Select **Preview import**. Domus reads the floors, areas, and devices, matches them with what + is already in Domus (by Home Assistant id, then MAC address, then serial number, then a + similar name in the same area), and shows what each device would do. Nothing is saved + yet. +4. If Home Assistant has floors Domus doesn't know, choose which building each one goes + in (the main building by default). Change the action for any device you want to skip + or link differently. +5. Select **Import N devices**. It runs in one step: everything is saved or nothing is. + +Domus uses the token for that import only. It doesn't save, log, or return it, so you +paste it again for the next import, and you can delete it in Home Assistant afterwards. + +Importing again later adds only what is new and fills in missing details. It never +overwrites a name or other field you changed in Domus. A device that Home Assistant puts +in an area but not at a spot goes to that area's **Somewhere in this area** location, so +you can move it later. + +With Docker, `homeassistant.local` may not resolve inside the container. Use Home +Assistant's IP address instead. ## Where your data lives @@ -261,7 +285,13 @@ contain password hashes and everything about your home, so keep them somewhere p Uploaded images are re-encoded when they are saved, which removes EXIF data such as GPS location. They are stored in `blobs/` and included in backups like everything else. -> **Coming in v0.1:** search. +## Search + +Use the search box at the top of every page, or the **Search** page. Search covers +devices and areas: names, notes, makes and models, tags, areas, locations, serial +numbers, and MAC addresses and other ids. Every word must match the start of a word, +so `therm` finds "Thermostat". Guests' results never match serial numbers, network ids, +or other details they can't see. ## Back up, verify, and restore @@ -272,6 +302,12 @@ one JSONL file per table, and the blobs. You can open them with any zip tool. The server can keep running. +From the web interface, an Admin opens **Backups** in the menu and selects **Make a +backup now**, then downloads it from the list. A backup holds every property on the +server, so this needs you to be an Admin of all of them. + +From the command line: + ```sh uv run domus backup create # Backup written to ~/.local/share/domus/backups/domus-20261106T230337Z.hiotbak @@ -302,6 +338,7 @@ is newer than this app. ### Restore a backup **Stop the server first.** A full restore replaces all current data, accounts included. +Restore is done from the command line only in v0.1, not from the web interface. ```sh uv run domus restore --dry-run path/to/backup.hiotbak # what would change; saves nothing @@ -422,7 +459,7 @@ Domus reads settings from environment variables that start with `DOMUS_`. | Variable | Default | What it does | | :-- | :-- | :-- | | `DOMUS_DATA_DIR` | `~/.local/share/domus` (`/data` in Docker) | Folder for the database, files, and backups | -| `DOMUS_DATABASE_URL` | SQLite in the data folder | Database URL. Leave unset; PostgreSQL support is experimental and not in v0.1 yet. | +| `DOMUS_DATABASE_URL` | SQLite in the data folder | Database URL. Leave unset to use SQLite. PostgreSQL 15+ is experimental: install the `postgres` extra (`uv sync --extra postgres`) and use a URL like `postgresql+pg8000://user:password@host/domus`. The Docker image doesn't include it. | | `DOMUS_COOKIE_SECURE` | `true` | Send the login cookie over HTTPS only (plain http to `localhost` and `127.0.0.1` still works). Set `false` only for plain http on a trusted network. | | `DOMUS_SESSION_DAYS` | `14` | How long a sign-in lasts | | `DOMUS_LOGIN_MAX_FAILURES` | `5` | Failed sign-ins allowed per window before Domus blocks more attempts | diff --git a/examples/sample-home/README.md b/examples/sample-home/README.md index 8bbdf71..0731f02 100644 --- a/examples/sample-home/README.md +++ b/examples/sample-home/README.md @@ -6,10 +6,10 @@ A small, fictional example property for demos, tests, and trying out Domus. All - **Property**: "Sample Home", with one building, **House**. - **Floors**: Main Floor and Basement. -- **Rooms**: Kitchen, Living Room, Primary Bedroom, and Utility Room. +- **Areas**: Kitchen, Living Room, Primary Bedroom, and Utility Room. - **Devices** (9): - | Device | Room | Shows off | + | Device | Area | Shows off | | :-- | :-- | :-- | | Refrigerator | Kitchen | A manual link, a serial, a warranty, and a filter task every 6 months counted from the last change | | Kitchen Smoke Detector | Kitchen | A yearly fixed-date task (November 1), already overdue in the demo |