OPSG Implementation Guide

Complete guide to building the Open Physical Security Graph system.

Overview

OPSG is a vendor-agnostic protocol and edge agent platform for unifying physical security systems. It breaks vendor lock-in by providing:

  • Universal primitives: Resource, Capability, Signal, Action
  • Edge-native architecture: Deploy agents near devices
  • Real-time event streaming: SSE and gRPC streaming
  • Extensible connector system: Write adapters for any vendor

Getting Started

1. Start the Edge Agent

```bash cd edge-agent npm install npm run dev ```

The agent starts on:

  • HTTP: http://localhost:8080
  • gRPC: localhost:9090

2. View the Dashboard

In another terminal:

```bash npm install npm run dev ```

Open http://localhost:3000/dashboard

3. Test the System

List resources: ```bash curl http://localhost:8080/v1/resources ```

Stream signals: ```bash curl http://localhost:8080/v1/stream ```

Send an action: ```bash curl -X POST http://localhost:8080/v1/actions
-H "Content-Type: application/json"
-d '{ "targetId": "acoustic-main-entrance", "action": "acoustic.warn", "params": {"message": "Warning: Restricted area"}, "requestedBy": "user:alice" }' ```

Architecture

Core Components

  1. Bus - Central event hub that manages resources and signals
  2. Connectors - Adapters that translate vendor protocols
  3. HTTP API - REST endpoints for control and monitoring
  4. gRPC API - Streaming protocol for high-performance integrations
  5. Dashboard - Web UI for real-time monitoring

Data Flow

``` Connector → Bus → API → Dashboard ↓ ↑ Device Action ```

  1. Connectors register resources with capabilities
  2. Connectors emit signals to the bus
  3. Bus forwards signals to subscribers (APIs, dashboard)
  4. Actions flow from API → Bus → Connector → Device

Writing Connectors

Connectors are the integration layer between OPSG and physical devices.

Connector Structure

```typescript export class MyConnector extends Connector { // Called when agent starts async start(): Promise { // Register resources this.registerResource(resource, capabilities)

// Start device polling/listening
// Emit periodic signals

}

// Called when agent stops async stop(): Promise { // Cleanup resources }

// Handle actions sent to your resources async handleAction(action: Action): Promise { // Send command to device // Emit response signal } } ```

Built-in Connectors

Dummy Connector

Simulates devices for testing. Creates dummy resources with heartbeat signals.

Acoustic Deterrent Connector

Acoustic hailing device integration. Supports:

  • acoustic.warn - Broadcast warning message
  • acoustic.tone - Play alert tone
  • acoustic.status - Get device status

Webhook Connector

HTTP webhook integration for external APIs.

Adding a New Connector

  1. Create edge-agent/src/connectors/my-connector.ts
  2. Extend Connector class
  3. Implement start() and handleAction()
  4. Register in edge-agent/src/connectors/loader.ts
  5. Enable in edge-agent/src/config.ts

Protocol Specification

Resource

Any addressable physical security entity.

```typescript interface Resource { id: string // Unique identifier type: string // camera, door, acoustic_device, sensor, etc. labels: Record<string, string> // Metadata (location, model, etc.) } ```

Capability

What a resource can do.

```typescript interface Capability { entityId: string // Resource ID name: string // Capability name (e.g., "access.unlock") params: Record<string, string> // Configuration } ```

Signal

Real-time event or telemetry.

```typescript interface Signal { id: string sourceId: string // Resource ID or agent ID kind: string // Event type (e.g., "door.opened") tsMs: number // Timestamp in milliseconds severity: "INFO" | "WARN" | "CRIT" data: Record<string, string> // Event payload } ```

Action

Command sent to a resource.

```typescript interface Action { id: string targetId: string // Resource ID action: string // Action name (e.g., "door.lock") params: Record<string, string> // Action parameters tsMs: number requestedBy: string // Principal (user, service, etc.) } ```

Deployment

Development

```bash npm run dev ```

Production

Build and run: ```bash cd edge-agent npm run build npm start ```

Docker

```bash docker build -t opsg-edge-agent . docker run -p 8080:8080 -p 9090:9090 opsg-edge-agent ```

Roadmap

v0.1 (Current)

  • Core protocol (Resource, Capability, Signal, Action)
  • Edge agent with in-memory bus
  • HTTP + gRPC APIs
  • Real-time SSE streaming
  • Web dashboard
  • Example connectors (Dummy, Acoustic, Webhook)

v0.2 (Next)

  • Proto code generation
  • Persistent storage (SQLite)
  • Authentication & authorization
  • Production connectors (ONVIF, HID, S2)
  • Client SDKs (TypeScript, Python)

v1.0 (Future)

  • Multi-agent federation
  • Event correlation engine
  • Policy enforcement system
  • Cloud control plane
  • AI agent integration

Community

License

MIT License - See LICENSE file for details.