Prisma Schema & Models
The system uses Prisma ORM with MongoDB. The schema is defined in server-nest/prisma/schema.prisma and contains 71 models.
Multi-Tenancy Filtering
Prisma middleware in PrismaService automatically injects userId into every query for tenant-scoped models. Admin users bypass this filter unless impersonating via x-customer-context.
Critical Rule
Never manually filter by userId in services for tenant models. The middleware handles this automatically.
Tenant-Scoped Models (50)
These models have a userId field and are automatically filtered per tenant.
Devices & Configuration
| Model | Description |
|---|---|
Device | Registered devices |
DeviceConfiguration | Per-device configuration |
DeviceMetrics | Performance metrics (CPU, RAM, uptime) |
DeviceMonitoring | Monitoring data & alerts |
DeviceSettings | Display & operation settings |
Synagogue & Content
| Model | Description |
|---|---|
TfilaTime | Prayer times |
GeneralMessage | Messages displayed to congregants |
Hanzch | Memorial (yahrzeit) entries |
Shior | Torah classes |
OlieLatora | Torah reading assignments |
ScreenTimer | Content display scheduling |
AliyaNotification | Aliyah notifications |
DailyContentPreference | Daily content preferences |
HolidayTimes | Holiday times |
Synagogue | Synagogue profile |
Notification | General notifications |
NotificationPreferences | Notification preferences |
WhatsApp & Communication
| Model | Description |
|---|---|
WhatsAppMessage | WhatsApp messages |
WhatsAppConfig | WhatsApp connection settings |
ScheduledMessage | Scheduled messages |
IncomingMessage | Incoming messages |
AutoResponseRule | Auto-response rules |
WhatsAppContactAlias | Contact aliases |
EmailConfig | Email SMTP configuration |
SmsConfig | SMS configuration |
NotificationLog | Notification delivery log |
Alerts & Monitoring
| Model | Description |
|---|---|
AlertRule | Automated alert rules |
NotificationHistory | Notification history |
NetworkMetrics | Network metrics |
Analytics & AI
| Model | Description |
|---|---|
MLModel | Machine learning model definitions |
TrainedModel | Trained ML models |
AnomalyDetection | Anomaly detection records |
BehavioralAnalytics | Behavioral analytics data |
SecurityAnalysis | Security analysis results |
SmartMaintenance | Smart maintenance recommendations |
AdvancedReport | Advanced reports |
System & Operations
| Model | Description |
|---|---|
SoftwareUpdate | Software updates |
UpdateStatus | Update statuses |
CommandHistory | Command history |
ConfigurationBackup | Configuration backups |
WebhookEndpoint | Webhook endpoints |
WebhookLog | Webhook delivery log |
BatchCommand | Batch commands |
BatchCommandResult | Batch command results |
EnhancedMqttSession | MQTT sessions |
UploadAsset | Uploaded assets |
SystemConfiguration | System configuration |
SystemBackup | System backups |
Security & Audit
| Model | Description |
|---|---|
SecurityIncident | Security incidents |
SecurityEvent | Security events |
SuspiciousIp | Suspicious IP addresses |
SystemIssue | System issues |
SystemMetricSample | Metric samples |
SystemServiceStatus | Service status records |
AuditLog | Audit trail |
Global Models (21)
These models are not filtered by tenant. They either have no userId field or serve cross-tenant purposes.
| Model | Description |
|---|---|
User | User accounts & authentication |
DeviceCertificate | Device SSL certificates |
DeviceToken | Push notification tokens |
License | License management |
RemoteInstallation | Remote installation records |
MqttTopic | MQTT topic definitions |
MqttConnection | MQTT connection records |
MqttTopicState | MQTT topic state |
MlPrediction | ML prediction results |
Anomaly | Detected anomalies |
Alert | System alerts |
DetectedPattern | Detected patterns |
DetectedAnomaly | Detected anomaly records |
MaintenancePrediction | Maintenance predictions |
MaintenanceMode | Maintenance mode state |
TelemetryData | Telemetry data points |
HealthCheckHistory | Health check history |
Working with the Schema
Regenerate Client
After editing schema.prisma:
npx prisma generate
Push Schema Changes (Dev Only)
npx prisma db push
Visual Database Browser
npx prisma studio
Key Conventions
- All tenant models include a
userId: Stringfield - Timestamps:
createdAt/updatedAtwith@default(now())and@updatedAt - IDs:
@id @default(auto()) @map("_id") @db.ObjectId - Relations use
@db.ObjectIdfor MongoDB ObjectId fields