Skip to main content

πŸŽ›οΈ Backend Architecture

The backend is built on AdonisJS, a robust Node.js web framework that follows the MVC (Model-View-Controller) pattern. We rigorously apply the Service-Repository pattern to keep controllers thin and logic testable.

Directory Structure​

app/
β”œβ”€β”€ Controllers/ # Request Handling (Input Validation, HTTP Responses)
β”œβ”€β”€ Models/ # Lucid ORM Definitions (Database Schema)
β”œβ”€β”€ Services/ # Business Logic (The core intelligence)
β”œβ”€β”€ Validators/ # Data validation rules
β”œβ”€β”€ Websockets/ # Real-time event handlers
└── Tasks/ # Planned tasks (Cron jobs)

Core Design Patterns​

1. Service Layer​

We do not put business logic in Controllers. Instead, we use dedicated Services.

  • CameraService: Manages camera provisioning, connection status checks, and configuration updates.
  • AlertService: Handles the lifecycle of an alert (Trigger -> Notify Users -> Acknowledge -> Archive).
  • StatsService: Aggregates time-series data for dashboard graphs (e.g., "Activity Over Time").

2. Real-Time Communication​

We use Websockets to obtain sub-second latency for critical alerts.

ChannelEventPayloadDescription
camerasstatus:update{ id, status }Camera going Online/offline
alertsnew:alert{ type, severity }Critical user notification
streamframeBinary BlobLive preview (MJPEG over socket)

Database Schema (MySQL)​

The database is normalized to ensure data integrity.

  • Users 1:N Stables
  • Stables 1:N Boxes
  • Boxes 1:1 Cameras
  • Cameras 1:N Alerts

Note: We use Lucid ORM Migrations to manage schema changes versioning. Always run node ace migration:run after pulling updates.