Audit Log Architecture
Switchbord maintains anaudit_logs table that records security-relevant operations performed within each workspace. The audit trail is designed to answer: who did what, to which object, in which workspace, and when.
Schema
workspace_id, ensuring workspace isolation extends to the audit trail itself.
What Is Logged
Currently Implemented
Writing an Audit Log Entry
Audit log entries are written synchronously within the same database transaction as the operation they record where possible. This ensures the audit trail reflects actual operations, not just attempted ones.
Planned Audit Log Enhancements
Read-Access Logging (BORD-168)
Currently, only write operations (mutations, deletions) are logged. Planned work includes logging read access to PII tables — specifically tracking which users accessed which contact records and when. This is required for full HIPAA §164.312(b) compliance.Tamper-Evident Hash Chain (BORD-168)
Each audit log entry will include a cryptographic hash of the previous entry in the workspace’s log chain. This creates a tamper-evident structure where modification of any past entry invalidates all subsequent hashes. Planned implementation uses SHA-256 chaining.Immutable Export to Object Storage (BORD-168)
Audit logs will be periodically exported to write-once object storage (e.g., Supabase Storage with immutable bucket policy) to provide a backup that cannot be modified even by database administrators.Observability Stack
Error Monitoring: Sentry
Switchbord integrates with Sentry for real-time error monitoring across all application surfaces. Sentry captures:- Unhandled exceptions in API routes
- Worker job failures
- Frontend JavaScript errors
packages/observability.
Log Aggregation: Better Stack
Application logs from Vercel and Railway are aggregated in Better Stack (formerly Logtail). Structured logs include request IDs for correlation across services.Health Monitoring
The/api/health and /api/ready endpoints are publicly accessible and monitored by uptime services to detect availability degradation.
Account Alerts (BORD-189)
Switchbord ships real-time account-level alerts that surface operational and security-relevant events to workspace operators:- WhatsApp API health alerts — notifications when the Meta API returns elevated error rates, rate-limit responses, or webhook delivery failures for a workspace’s phone numbers
- Secret expiry alerts — warnings when Vault-stored tokens or API keys are approaching expiration
- Consent threshold alerts — notifications when a workspace’s opt-out rate exceeds a configurable threshold, indicating potential compliance risk
- Usage anomaly alerts — flags for unusual message volume spikes, bulk contact operations, or API key usage patterns
audit_logs table under the account_alert entity type.
Planned: Security Incident Detection (BORD-166)
The following capabilities are planned as part of BORD-166:- Anomaly detection: Flag unusual patterns such as bulk contact exports, high API key usage volume, or access from unexpected IP ranges
- Security event monitoring: Dedicated alerting for security-relevant events (failed auth bursts, concurrent session anomalies, privilege escalation attempts)
- Alerting integration: Webhook-based alerts to Slack, PagerDuty, or operator-configured endpoints
Planned: Breach Notification Workflow (BORD-166)
GDPR Art.33 requires notification to the supervisory authority within 72 hours of becoming aware of a personal data breach. Art.34 may require notification to affected data subjects. Planned capabilities to support this obligation:- Incident detection triggers that create an incident record with timestamp of detection
- Breach assessment workflow — guided questions to determine notification scope
- Notification draft generation — pre-populated templates for DPA submission
- 72-hour countdown timer — visible in the admin UI once an incident is declared
- Affected workspace and contact scoping — identify which contacts’ data may have been involved
Retention of Audit Logs
Audit logs are retained for the workspace’s configureddata_retention_days period, with a minimum retention of 365 days regardless of the workspace setting. This ensures that audit trails remain available for post-incident investigation and compliance audits.
GDPR erasure requests do not delete audit log entries. Entries recording the fact of an erasure are themselves retained as evidence of compliance.