# Spec 013: Facility Monitoring & Security Integration

**Status:** Draft
**Owner:** Engineering Team
**Last Updated:** 2025-12-11

## 1. Overview

This specification details the integration of physical security and monitoring systems (primarily CCTV) into the CA Grow Ops Manager platform. The goal is to provide unauthorized access alerts and real-time visual monitoring of facility operations directly within the application dashboard.

## 2. Scope

* **CCTV Integration:** Display live video feeds from IP cameras (RTSP/ONVIF).
* **Access Control:** Integration with door sensors/smart locks for entry logs (Future Phase).
* **Environmental Monitoring:** (Covered in separate spec, but related visually).

## 3. Architecture

### 3.1 Stream Proxy (go2rtc)

Directly embedding RTSP streams in web browsers is not supported. We will use `go2rtc` (or a similar lightweight media server) as a sidecar container to transcode/remux RTSP streams into WebRTC/MSE for low-latency browser playback.

* **Input:** RTSP streams from NVR or IP Cameras.
* **Output:** WebRTC (preferred for <500ms latency) or MSE (Media Source Extensions).
* **Deployment:** Docker container deployed alongside the application stack.

### 3.2 Backend Integration

* **Device Registry:** Database model to store camera configuration (Name, RTSP URL, Room ID, Location).
* **Proxy Authentication:** The backend will handle authentication with the camera/NVR so credentials are not exposed to the client.
* **Snapshots:** Periodic snapshot generation for "Live View" thumbnails on the dashboard.

## 4. Security

* **Network Isolation:** Cameras should be on a separate VLAN. The `nexus-vector` server needs dual-homing or routed access to this VLAN.
* **Token-Based Access:** Frontend requests for video streams must be authenticated via the main application session.
* **Audit Logging:** All "Watch Live" actions are logged in the Audit Log.

## 5. User Interface

### 5.1 Dashboard Widget

* "Security Overview" widget showing thumbnails of critical cameras (Entry, Veg, Flower).
* Clicking a thumbnail opens a modal with the live WebRTC stream.

### 5.2 Layout Designer Integration

* Cameras can be placed as icons on the Facility Map.
* Hovering over a camera icon shows a live tooltip preview.

## 6. Implementation Plan

1. **Phase 1:** Deploy `go2rtc` on `nexus-vector`.
2. **Phase 2:** Implement `Camera` data model and API routes.
3. **Phase 3:** Create frontend VideoPlayer component (using `webrtc-player` or similar).
4. **Phase 4:** Integrate into Dashboard and Layout Designer.

## 7. Supported Protocols

* **RTSP (Real Time Streaming Protocol):** Primary ingest format.
* **ONVIF (Open Network Video Interface Forum):** For auto-discovery and PTZ control (Future).
