Skip to main content

Service Pattern

To keep controllers thin and logic testable, we strictly adhere to the Service-Repository Pattern.

Directory Structure

app/
├── Controllers/ # HTTP Handling only (Parsing input, returning JSON)
├── Services/ # Pure Business Logic
├── Models/ # Database Definitions
└── Validators/ # Yup/VineJS Schema Validation

Key Services

Key Services

🔧 Device Management

CameraService & CameraManagerService

These services form the backbone of device provisioning.

  • Provisioning: Handling unique credential generation for camera access.
  • Monitoring: Scheduled tasks checking connectivity.

RtspToWebService

A wrapper around the RTSPtoWeb open-source project. It allows the backend to:

  • Start/Stop Streams: Only active when a user is actually viewing the dashboard to save bandwidth.
  • Protocol Negotiation: Returns HLS, WebRTC, or MSE URLs based on client capabilities.

🔔 Event Processing

RedisSubscriptionsService

The integration point with the Python Vision System.

  • Input: Listens to Redis channel camera:sitting.
  • Logic:
    1. Receives a MotionEvent (Agitation score, Class Name).
    2. Resolves the Camera -> Site -> Users.
    3. Filters users based on emailNotificationsEnabled.
  • Output: Dispatches emails via SMTP and SMS via Twilio.

NotificationService

Handles the persistence of in-app notifications (the bell icon) and push notifications to mobile devices.