System Overview
Unhook consists of several key components working together to provide seamless webhook development:
Data Flow Steps
Webhook Reception
- Provider sends webhook to
https://unhook.sh/t_123?e=ENDPOINT
- API validates the API key and processes the request
- Event is stored in the database
Real-time Distribution
- CLI clients subscribe to new events
- Database triggers notify connected clients
- Events are delivered to local development servers
Local Processing
- CLI delivers requests to specified port or URL
- Responses are captured and stored
- Results are visible in the dashboard
Database Schema
Core Entities
Users and Organizations
Webhooks and Connections
Key Tables
Users
interface User {
id: string;
email: string;
firstName?: string;
lastName?: string;
online: boolean;
lastLoggedInAt?: Date;
}
Organizations
interface Org {
id: string;
createdByUserId: string;
clerkOrgId?: string;
}
Webhooks
interface Webhook {
id: string;
clientId: string;
port: number;
status: 'active' | 'inactive';
localConnectionStatus: 'connected' | 'disconnected';
config: WebhookConfig;
userId: string;
orgId: string;
}
Events
interface Event {
id: string;
webhookId: string;
originalRequest: RequestPayload;
status: 'pending' | 'processing' | 'completed' | 'failed';
retryCount: number;
maxRetries: number;
}
Configuration Types
Webhook Configuration
interface WebhookConfig {
storage: {
storeHeaders: boolean;
storeRequestBody: boolean;
storeResponseBody: boolean;
maxRequestBodySize: number;
maxResponseBodySize: number;
};
headers: {
allowList?: string[];
blockList?: string[];
sensitiveHeaders?: string[];
};
requests: {
allowedMethods?: string[];
allowedFrom?: string[];
blockedFrom?: string[];
maxRequestsPerMinute?: number;
maxRetries?: number;
};
}
Component Architecture
API Server
The API server handles:
- Webhook reception and validation
- Event storage and distribution
- Authentication and authorization
- Team management
- Real-time updates
CLI Client
The CLI client manages:
- Local webhook connections
- Event subscription
- Request delivery
- Health monitoring
- Debug logging
Dashboard
The web dashboard provides:
- Real-time event monitoring
- Team management
- Configuration controls
- Analytics and debugging
- Request/response inspection
Security Model
-
API Authentication
- API keys for webhook endpoints
- JWT tokens for dashboard access
- Role-based access control
-
Data Privacy
- Configurable header filtering
- Request/response body size limits
- Sensitive data redaction
-
Team Access
- Organization-based isolation
- Member role management
- Shared webhook endpoints
Scaling Considerations
-
Database
- Real-time notification system
- Event archival strategy
- Connection pooling
-
API Layer
- Request rate limiting
- Load balancing
- Regional distribution
-
Event Processing
- Retry mechanisms
- Failure handling
- Queue management
Development Setup
For local development:
- Database
# Start Postgres
docker compose up db
- API Server
# Start API server
npm run dev:api
- CLI Development
# Build and run CLI
npm run dev:cli
Best Practices
-
Event Handling
- Implement proper retry logic
- Handle timeouts gracefully
- Log relevant debugging info
-
Security
- Rotate API keys regularly
- Monitor failed attempts
- Review access logs
-
Team Workflow
- Use meaningful client IDs
- Configure appropriate timeouts
- Set up health checks
Responses are generated using AI and may contain mistakes.