Architecture Overview
The webhook layer serves as a bridge between the Supabase database and external automation: Key Characteristics:- Webhooks are called asynchronously (fire-and-forget)
- Frontend does not wait for webhook responses
- Database writes happen directly via Supabase client
- n8n workflows can trigger additional processing or notifications
Webhook Endpoints
The system defines three webhook endpoints mentioned in the README.1. /actualizar-bahia
Triggered when a truck is dragged to a new bay position. Event:onDrop in the drag-and-drop handler
Timing: After actualizarBahiaDirecto() succeeds (see src/Componentes/SimuladorMapa.tsx:42)
Payload:
- Log bay transitions for analytics
- Notify warehouse staff of new arrivals
- Trigger automated bay assignment optimization
- Update external WMS (Warehouse Management System)
2. /registrar-incidencia
Triggered when an incident is opened or closed. Events:- Incident start: After
abrirIncidencia()succeeds - Incident end: After
cerrarIncidencia()succeeds
src/Componentes/ModalIncidencia.tsx:195)
Payload (Start):
- Real-time incident tracking dashboard
- Escalation to supervisors for repeated incidents
- Root cause analysis data collection
- Performance reports excluding incident time
- Maximum 3 incidents per truck
- 4th incident prevents further registration
- Open incidents have
hora_fin = null - Incident durations are excluded from net yard time calculations
src/services/supabaseService.ts:251-285 for incident management logic.
3. /marcar-salida
Triggered when a truck departs the facility. Event: User clicks “Marcar Salida” button Timing: AftermarcarSalidaDirecto() succeeds (see src/Componentes/SimuladorMapa.tsx:47-48)
Payload:
- Update external logistics system
- Generate departure confirmation
- Trigger gate access control
- Calculate final KPIs (time in yard, incidents, etc.)
- Archive completed trip records
src/services/supabaseService.ts:340-353 for implementation.
n8n Workflow Setup
Create n8n Workflow
In your n8n instance (Azure-hosted), create a new workflow for each webhook endpoint
Add Webhook Trigger Node
Use the Webhook trigger node with these settings:
- HTTP Method: POST
- Path:
/actualizar-bahia,/registrar-incidencia, or/marcar-salida - Response Mode: “Immediately”
- Response Code: 200
Add Business Logic
Connect nodes for your automation:
- Send notifications (Email, Slack, SMS)
- Update external systems (ERP, WMS)
- Trigger analytics pipelines
- Store audit logs
Frontend Integration
To call webhooks from the frontend, add a webhook service:Environment Variables
Add to.env:
Error Handling
Philosophy: Webhooks are non-critical. Database operations must succeed even if webhooks fail. Implementation:- Check n8n execution logs for failed workflows
- Set up alerts for repeated webhook failures
- Monitor Azure Function App metrics
Security Considerations
-
API Key Authentication
- IP Whitelisting Configure Azure to only accept requests from your Vercel deployment IPs
-
Request Signing
Use HMAC signatures to verify webhook authenticity:
- Rate Limiting Implement rate limiting in n8n or Azure to prevent abuse
Testing Webhooks
Use curl to test webhook endpoints:Common n8n Workflow Patterns
Send Slack Notification on Incident
Update External WMS on Bay Change
Log All Events to BigQuery
Next Steps
Database Schema
Understand the tables webhooks interact with
Bay Configuration
See bay IDs referenced in webhook payloads
