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
- Bus - Central event hub that manages resources and signals
- Connectors - Adapters that translate vendor protocols
- HTTP API - REST endpoints for control and monitoring
- gRPC API - Streaming protocol for high-performance integrations
- Dashboard - Web UI for real-time monitoring
Data Flow
``` Connector → Bus → API → Dashboard ↓ ↑ Device Action ```
- Connectors register resources with capabilities
- Connectors emit signals to the bus
- Bus forwards signals to subscribers (APIs, dashboard)
- 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
// Start device polling/listening
// Emit periodic signals
}
// Called when agent stops
async stop(): Promise
// Handle actions sent to your resources
async handleAction(action: Action): Promise
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 messageacoustic.tone- Play alert toneacoustic.status- Get device status
Webhook Connector
HTTP webhook integration for external APIs.
Adding a New Connector
- Create
edge-agent/src/connectors/my-connector.ts - Extend
Connectorclass - Implement
start()andhandleAction() - Register in
edge-agent/src/connectors/loader.ts - 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
- GitHub: https://github.com/opsg/opsg
- Issues: https://github.com/opsg/opsg/issues
- Discussions: https://github.com/opsg/opsg/discussions
License
MIT License - See LICENSE file for details.