2.8 KiB
storage
Purpose
The persistence layer. Defines every SQLite table, opens the WAL-mode database, exposes hand-written SQLAlchemy Core queries for the rest of the codebase, and provides the AES-256-CTR file encryption used to seal recordings as .vge. It is a library package, not a supervised subsystem process.
Key files
vigilar/storage/schema.py— SQLAlchemy CoreMetaDataand 19Tabledefinitionsvigilar/storage/db.py— engine creation, WAL pragmas,init_db,get_db_pathvigilar/storage/queries.py— allinsert_*/get_*/update_*/delete_*helpersvigilar/storage/encryption.py— AES-256-CTRencrypt_file/decrypt_streamfor.vgerecordings
MQTT topics
Subscribes: none Publishes: none
Database tables
cameras— configured camera registrysensors— configured sensor registrysensor_states— current key/value state per sensorevents— canonical event log written by the events processorrecordings— video clip metadata (path, duration, trigger, event_id, starred)system_events— operator-facing component log (info/alert/critical)arm_state_log— arm-state FSM transitionsalert_log— one row per alert delivery attempt and outcomepush_subscriptions— VAPID Web Push subscription endpointspets— known pets (name, species, breed, training count)pet_sightings— per-frame pet observations with confidence and crop pathwildlife_sightings— wildlife observations with species, threat level, weather contextpackage_events— package delivery state machine rows (detected/reminded/collected)pet_training_images— images staged for pet-ID model retrainingpet_rules— per-pet rule definitions with cooldown and priorityface_profiles— known faces, household flag, visit countface_embeddings— serialized face vectors linked to a profilevisits— per-visit records for recognized facestimelapse_schedules— per-camera timelapse generation schedules
Depends on
- Filesystem: SQLite database under
system.data_dir, AES key at/etc/vigilar/secrets/storage.key
Consumed by
- Every other subsystem. Camera encrypts recordings through it, events/alerts/sensors/ups/pets/highlights/presence/web all import
vigilar.storage.queries.
Notes
Encryption is AES-256 in CTR mode (no GCM), so .vge files are confidential but not tamper-evident — there is no authentication tag and a bit-flip in the ciphertext produces a corresponding bit-flip in the plaintext without detection. The 16-byte IV is prepended to each file and the plaintext is unlinked after encryption. The codebase uses SQLAlchemy Core exclusively — there are no mapped ORM classes. The database is opened in WAL mode so the web process can read while the events processor writes.