plans/phase1-specification/api-spec.md
This document defines the complete API specification for the WiFi-DensePose system, including REST endpoints, WebSocket protocols, data models, authentication mechanisms, and external integration interfaces.
The API specification covers all programmatic interfaces for pose data access, system control, real-time streaming, external integrations, and authentication/authorization mechanisms.
The system provides a comprehensive FastAPI-based REST interface with WebSocket streaming capabilities, supporting real-time pose data distribution, system management, and integration with external services including MQTT, webhooks, and Restream platforms.
Endpoint: GET /pose/latest
Description: Retrieve the most recent pose estimation results
Authentication: Bearer token required
Response Format:
{
"timestamp": "2025-01-07T04:46:32.123Z",
"frame_id": 12345,
"processing_time_ms": 45,
"persons": [
{
"id": 1,
"confidence": 0.87,
"bounding_box": {
"x": 120,
"y": 80,
"width": 200,
"height": 400
},
"keypoints": [
{
"name": "nose",
"x": 220,
"y": 100,
"confidence": 0.95
}
],
"dense_pose": {
"body_parts": [
{
"part_id": 1,
"part_name": "torso",
"uv_coordinates": [[0.5, 0.3], [0.6, 0.4]],
"confidence": 0.89
}
]
}
}
],
"metadata": {
"environment_id": "room_001",
"router_count": 3,
"signal_quality": 0.82
}
}
Error Responses:
404: No pose data available503: System not initialized401: Authentication required// TEST: Verify latest pose endpoint returns valid pose data structure // TEST: Confirm error handling for missing data scenarios // TEST: Validate authentication token requirements
Endpoint: GET /pose/history
Description: Retrieve historical pose data with filtering options
Authentication: Bearer token required
Query Parameters:
start_time (optional): ISO 8601 timestamp for range startend_time (optional): ISO 8601 timestamp for range endlimit (optional): Maximum number of records (default: 100, max: 1000)person_id (optional): Filter by specific person IDconfidence_threshold (optional): Minimum confidence score (0.0-1.0)Response Format:
{
"poses": [
{
"timestamp": "2025-01-07T04:46:32.123Z",
"persons": [...],
"metadata": {...}
}
],
"pagination": {
"total_count": 1500,
"returned_count": 100,
"has_more": true,
"next_cursor": "eyJpZCI6MTIzNDV9"
}
}
// TEST: Validate historical data retrieval with various filter combinations // TEST: Confirm pagination functionality works correctly // TEST: Verify time range filtering accuracy
Endpoint: POST /pose/query
Description: Execute complex queries on pose data
Authentication: Bearer token required
Request Body:
{
"query": {
"time_range": {
"start": "2025-01-07T00:00:00Z",
"end": "2025-01-07T23:59:59Z"
},
"filters": {
"person_count": {"min": 1, "max": 5},
"confidence": {"min": 0.7},
"activity": ["walking", "standing"]
},
"aggregation": {
"type": "hourly_summary",
"metrics": ["person_count", "avg_confidence"]
}
}
}
Response Format:
{
"results": [
{
"timestamp": "2025-01-07T10:00:00Z",
"person_count": 3,
"avg_confidence": 0.85,
"activities": {
"walking": 0.6,
"standing": 0.4
}
}
],
"query_metadata": {
"execution_time_ms": 150,
"total_records_scanned": 10000,
"cache_hit": false
}
}
// TEST: Verify complex query execution with multiple filters // TEST: Confirm aggregation calculations are accurate // TEST: Validate query performance within acceptable limits
Endpoint: GET /system/status
Description: Get comprehensive system health and status information
Authentication: Bearer token required
Response Format:
{
"status": "running",
"uptime_seconds": 86400,
"version": "1.0.0",
"components": {
"csi_receiver": {
"status": "active",
"data_rate_hz": 25.3,
"packet_loss_rate": 0.02,
"last_packet_time": "2025-01-07T04:46:32Z"
},
"neural_network": {
"status": "active",
"model_loaded": true,
"inference_time_ms": 45,
"gpu_utilization": 0.65
},
"tracking": {
"status": "active",
"active_tracks": 2,
"track_quality": 0.89
}
},
"hardware": {
"cpu_usage": 0.45,
"memory_usage": 0.62,
"gpu_memory_usage": 0.78,
"disk_usage": 0.23
},
"network": {
"connected_routers": 3,
"signal_strength": -45,
"interference_level": 0.15
}
}
// TEST: Verify system status endpoint returns accurate component states // TEST: Confirm hardware metrics are within expected ranges // TEST: Validate network status reflects actual router connectivity
Endpoint: POST /system/start
Description: Start the pose estimation system
Authentication: Bearer token required
Request Body:
{
"configuration": {
"domain": "healthcare",
"environment_id": "room_001",
"calibration_required": true
}
}
Response Format:
{
"status": "starting",
"estimated_ready_time": "2025-01-07T04:47:00Z",
"initialization_steps": [
{
"step": "hardware_initialization",
"status": "in_progress",
"progress": 0.3
},
{
"step": "model_loading",
"status": "pending",
"progress": 0.0
}
]
}
// TEST: Verify system startup sequence completes successfully // TEST: Confirm initialization steps progress correctly // TEST: Validate configuration parameters are applied
Endpoint: POST /system/stop
Description: Gracefully stop the pose estimation system
Authentication: Bearer token required
Request Body:
{
"force": false,
"save_state": true
}
Response Format:
{
"status": "stopping",
"estimated_stop_time": "2025-01-07T04:47:30Z",
"shutdown_steps": [
{
"step": "data_pipeline_stop",
"status": "completed",
"progress": 1.0
},
{
"step": "model_unloading",
"status": "in_progress",
"progress": 0.7
}
]
}
// TEST: Verify graceful system shutdown preserves data integrity // TEST: Confirm force stop functionality works when needed // TEST: Validate state saving during shutdown process
Endpoint: GET /config
Description: Retrieve current system configuration
Authentication: Bearer token required
Response Format:
{
"domain": "healthcare",
"environment": {
"id": "room_001",
"name": "Patient Room 1",
"calibration_timestamp": "2025-01-07T04:00:00Z"
},
"detection": {
"confidence_threshold": 0.7,
"max_persons": 5,
"tracking_enabled": true
},
"alerts": {
"fall_detection": {
"enabled": true,
"sensitivity": 0.8,
"notification_delay_seconds": 5
},
"inactivity_detection": {
"enabled": true,
"threshold_minutes": 30
}
},
"streaming": {
"restream_enabled": false,
"websocket_enabled": true,
"mqtt_enabled": true
}
}
// TEST: Verify configuration retrieval returns complete settings // TEST: Confirm domain-specific configurations are properly loaded // TEST: Validate configuration structure matches schema
Endpoint: PUT /config
Description: Update system configuration
Authentication: Bearer token required
Request Body:
{
"detection": {
"confidence_threshold": 0.75,
"max_persons": 3
},
"alerts": {
"fall_detection": {
"sensitivity": 0.9
}
}
}
Response Format:
{
"status": "updated",
"changes_applied": [
"detection.confidence_threshold",
"alerts.fall_detection.sensitivity"
],
"restart_required": false,
"validation_warnings": []
}
// TEST: Verify configuration updates are applied correctly // TEST: Confirm validation prevents invalid configuration values // TEST: Validate restart requirements are accurately reported
Endpoint: GET /analytics/healthcare
Description: Retrieve healthcare-specific analytics and insights
Authentication: Bearer token required
Query Parameters:
period: Time period (hour, day, week, month)metrics: Comma-separated list of metricsResponse Format:
{
"period": "day",
"date": "2025-01-07",
"metrics": {
"fall_events": {
"count": 2,
"events": [
{
"timestamp": "2025-01-07T14:30:15Z",
"person_id": 1,
"severity": "moderate",
"response_time_seconds": 45
}
]
},
"activity_summary": {
"walking_minutes": 120,
"sitting_minutes": 480,
"lying_minutes": 360,
"standing_minutes": 180
},
"mobility_score": 0.75
}
}
// TEST: Verify healthcare analytics calculations are accurate // TEST: Confirm fall detection events are properly recorded // TEST: Validate activity classification metrics
Endpoint: GET /analytics/retail
Description: Retrieve retail-specific analytics and insights
Authentication: Bearer token required
Response Format:
{
"period": "day",
"date": "2025-01-07",
"metrics": {
"traffic": {
"total_visitors": 245,
"peak_hour": "14:00",
"peak_count": 15,
"average_dwell_time_minutes": 12.5
},
"zones": [
{
"zone_id": "entrance",
"visitor_count": 245,
"avg_dwell_time_minutes": 2.1
},
{
"zone_id": "electronics",
"visitor_count": 89,
"avg_dwell_time_minutes": 8.7
}
],
"conversion_funnel": {
"entrance": 245,
"product_interaction": 156,
"checkout": 67
}
}
}
// TEST: Verify retail traffic counting accuracy // TEST: Confirm zone analytics provide meaningful insights // TEST: Validate conversion funnel calculations
Endpoint: ws://host:port/ws/pose
Authentication: Token via query parameter or header
Connection Message:
{
"type": "connection_established",
"client_id": "client_12345",
"server_time": "2025-01-07T04:46:32Z",
"supported_protocols": ["pose_v1", "alerts_v1"]
}
Subscribe to Pose Updates:
{
"type": "subscribe",
"channel": "pose_updates",
"filters": {
"min_confidence": 0.7,
"person_ids": [1, 2, 3]
}
}
Subscription Confirmation:
{
"type": "subscription_confirmed",
"channel": "pose_updates",
"subscription_id": "sub_67890"
}
// TEST: Verify WebSocket connection establishment works correctly // TEST: Confirm subscription filtering functions as expected // TEST: Validate subscription management handles multiple channels
Pose Update Message:
{
"type": "pose_update",
"subscription_id": "sub_67890",
"timestamp": "2025-01-07T04:46:32.123Z",
"data": {
"frame_id": 12345,
"persons": [...],
"metadata": {...}
}
}
System Status Update:
{
"type": "system_status",
"timestamp": "2025-01-07T04:46:32Z",
"status": {
"processing_fps": 25.3,
"active_persons": 2,
"system_health": "good"
}
}
// TEST: Verify pose data streaming maintains real-time performance // TEST: Confirm message ordering and delivery guarantees // TEST: Validate system status updates are timely and accurate
Subscribe to Alerts:
{
"type": "subscribe",
"channel": "alerts",
"filters": {
"alert_types": ["fall_detection", "intrusion"],
"severity": ["high", "critical"]
}
}
Fall Detection Alert:
{
"type": "alert",
"alert_id": "alert_12345",
"timestamp": "2025-01-07T04:46:32Z",
"alert_type": "fall_detection",
"severity": "high",
"data": {
"person_id": 1,
"location": {"x": 220, "y": 180},
"confidence": 0.92,
"video_clip_url": "/clips/fall_12345.mp4"
},
"actions_required": ["medical_response", "notification"]
}
// TEST: Verify alert streaming delivers critical notifications immediately // TEST: Confirm alert filtering works for different severity levels // TEST: Validate alert data contains all necessary information
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "Unique person identifier"
},
"confidence": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0,
"description": "Detection confidence score"
},
"bounding_box": {
"$ref": "#/definitions/BoundingBox"
},
"keypoints": {
"type": "array",
"items": {"$ref": "#/definitions/Keypoint"}
},
"dense_pose": {
"$ref": "#/definitions/DensePose"
},
"tracking_info": {
"$ref": "#/definitions/TrackingInfo"
}
},
"required": ["id", "confidence", "bounding_box", "keypoints"]
}
{
"type": "object",
"properties": {
"name": {
"type": "string",
"enum": ["nose", "left_eye", "right_eye", "left_ear", "right_ear",
"left_shoulder", "right_shoulder", "left_elbow", "right_elbow",
"left_wrist", "right_wrist", "left_hip", "right_hip",
"left_knee", "right_knee", "left_ankle", "right_ankle"]
},
"x": {"type": "number"},
"y": {"type": "number"},
"confidence": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0
},
"visible": {"type": "boolean"}
},
"required": ["name", "x", "y", "confidence"]
}
{
"type": "object",
"properties": {
"body_parts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"part_id": {"type": "integer"},
"part_name": {"type": "string"},
"uv_coordinates": {
"type": "array",
"items": {
"type": "array",
"items": {"type": "number"},
"minItems": 2,
"maxItems": 2
}
},
"confidence": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0
}
},
"required": ["part_id", "part_name", "uv_coordinates", "confidence"]
}
}
}
}
// TEST: Verify data models validate correctly against schemas // TEST: Confirm all required fields are present in API responses // TEST: Validate data type constraints are enforced
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"domain": {
"type": "string",
"enum": ["healthcare", "retail", "security", "general"]
},
"environment": {
"type": "object",
"properties": {
"id": {"type": "string"},
"name": {"type": "string"},
"calibration_timestamp": {"type": "string", "format": "date-time"}
},
"required": ["id", "name"]
},
"detection": {
"type": "object",
"properties": {
"confidence_threshold": {
"type": "number",
"minimum": 0.0,
"maximum": 1.0,
"default": 0.7
},
"max_persons": {
"type": "integer",
"minimum": 1,
"maximum": 10,
"default": 5
},
"tracking_enabled": {
"type": "boolean",
"default": true
}
}
}
},
"required": ["domain", "environment", "detection"]
}
// TEST: Verify configuration schema validation prevents invalid settings // TEST: Confirm default values are applied when not specified // TEST: Validate domain-specific configuration requirements
Header Format: Authorization: Bearer <token>
Token Type: JWT (JSON Web Token)
Expiration: Configurable (default: 24 hours)
Token Payload:
{
"sub": "user_12345",
"iat": 1704600000,
"exp": 1704686400,
"scope": ["pose:read", "system:control", "config:write"],
"domain": "healthcare"
}
Header Format: X-API-Key: <api_key>
Use Case: Service-to-service communication
Scope: Limited to specific endpoints
// TEST: Verify JWT token validation works correctly // TEST: Confirm API key authentication for service accounts // TEST: Validate token expiration handling
pose:read - Read pose data and analyticspose:stream - Access real-time streamingsystem:control - Start/stop system operationssystem:status - View system status and healthconfig:read - Read configuration settingsconfig:write - Modify configuration settingsalerts:manage - Manage alert configurationsadmin:full - Full administrative access// TEST: Verify permission-based access control works correctly // TEST: Confirm domain-specific authorization rules // TEST: Validate audit logging for sensitive operations
wifi-densepose/
├── pose/
│ ├── person/{person_id} # Individual person data
│ ├── summary # Aggregated pose data
│ └── raw # Raw pose frames
├── alerts/
│ ├── fall_detection # Fall detection alerts
│ ├── intrusion # Security alerts
│ └── system # System alerts
├── status/
│ ├── system # System health status
│ ├── hardware # Hardware status
│ └── network # Network connectivity
└── analytics/
├── healthcare # Healthcare metrics
├── retail # Retail analytics
└── security # Security metrics
Person Pose Message:
{
"timestamp": "2025-01-07T04:46:32Z",
"person_id": 1,
"confidence": 0.87,
"keypoints": [...],
"activity": "walking",
"location": {"x": 220, "y": 180}
}
Alert Message:
{
"alert_id": "alert_12345",
"timestamp": "2025-01-07T04:46:32Z",
"type": "fall_detection",
"severity": "high",
"person_id": 1,
"location": {"x": 220, "y": 180},
"confidence": 0.92
}
// TEST: Verify MQTT message publishing works reliably // TEST: Confirm topic structure follows specification // TEST: Validate message format consistency
Endpoint: POST /webhooks
Description: Configure webhook endpoints for event notifications
Request Body:
{
"url": "https://example.com/webhook",
"events": ["fall_detection", "person_detected"],
"authentication": {
"type": "bearer",
"token": "webhook_token_12345"
},
"retry_policy": {
"max_retries": 3,
"retry_delay_seconds": 5
}
}
Event Notification:
{
"webhook_id": "webhook_67890",
"event_type": "fall_detection",
"timestamp": "2025-01-07T04:46:32Z",
"data": {
"alert_id": "alert_12345",
"person_id": 1,
"severity": "high",
"location": {"x": 220, "y": 180}
},
"metadata": {
"environment_id": "room_001",
"system_version": "1.0.0"
}
}
// TEST: Verify webhook delivery with retry logic // TEST: Confirm authentication methods work correctly // TEST: Validate event filtering and payload formatting
Endpoint: POST /streaming/restream
Description: Configure Restream integration for live broadcasting
Request Body:
{
"restream_key": "restream_api_key",
"platforms": ["youtube", "twitch", "facebook"],
"video_settings": {
"resolution": "1280x720",
"fps": 30,
"bitrate": 2500
},
"overlay_settings": {
"show_keypoints": true,
"show_confidence": true,
"show_person_ids": true,
"background_type": "transparent"
}
}
Endpoint: GET /streaming/status
Response:
{
"status": "streaming",
"platforms": [
{
"name": "youtube",
"status": "connected",
"viewers": 45,
"uptime_seconds": 3600
},
{
"name": "twitch",
"status": "connected",
"viewers": 23,
"uptime_seconds": 3600
}
],
"video_stats": {
"fps": 29.8,
"bitrate": 2480,
"dropped_frames": 12
}
}
// TEST: Verify Restream integration connects successfully // TEST: Confirm multi-platform streaming works simultaneously // TEST: Validate video quality and performance metrics
200 OK - Request successful201 Created - Resource created successfully202 Accepted - Request accepted for processing204 No Content - Request successful, no content returned400 Bad Request - Invalid request format or parameters401 Unauthorized - Authentication required or invalid403 Forbidden - Insufficient permissions404 Not Found - Resource not found409 Conflict - Resource conflict (e.g., system already running)422 Unprocessable Entity - Validation errors429 Too Many Requests - Rate limit exceeded500 Internal Server Error - Unexpected server error502 Bad Gateway - Upstream service error503 Service Unavailable - System not ready or overloaded504 Gateway Timeout - Request timeout{
"error": {
"code": "POSE_DATA_NOT_FOUND",
"message": "No pose data available for the specified time range",
"details": {
"requested_range": {
"start": "2025-01-07T00:00:00Z",
"end": "2025-01-07T01:00:00Z"
},
"available_range": {
"start": "2025-01-07T02:00:00Z",
"end": "2025-01-07T04:46:32Z"
}
},
"timestamp": "2025-01-07T04:46:32Z",
"request_id": "req_12345"
}
}
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": {
"field_errors": [
{
"field": "confidence_threshold",
"message": "Value must be between 0.0 and 1.0",
"received_value": 1.5
}
]
},
"timestamp": "2025-01-07T04:46:32Z",
"request_id": "req_12346"
}
}
// TEST: Verify error responses follow consistent format // TEST: Confirm appropriate status codes are returned // TEST: Validate error details provide actionable information
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1704686400
X-RateLimit-Window: 3600
// TEST: Verify rate limiting enforces configured limits // TEST: Confirm performance targets are met under load // TEST: Validate system scales to handle concurrent users
/api/v1//api/v2/, /api/v3/Accept: application/vnd.wifi-densepose.v1+jsonAPI-Version: 1.0Deprecation: true
Sunset: Wed, 07 Jan 2026 04:46:32 GMT
Link: </api/v2/pose/latest>; rel="successor-version"
// TEST: Verify API versioning works correctly // TEST: Confirm backward compatibility is maintained // TEST: Validate deprecation notices are properly communicated
// TEST: Verify comprehensive test coverage for all endpoints // TEST: Confirm test data accurately represents real scenarios // TEST: Validate test automation runs reliably
// TEST: Verify API documentation matches implementation // TEST: Confirm all examples and code samples work correctly // TEST: Validate documentation completeness and accuracy
// TEST: Validate all API endpoints meet functional requirements // TEST: Confirm performance targets are achieved under load // TEST: Verify external integrations work reliably // TEST: Ensure comprehensive error handling covers all scenarios // TEST: Validate API documentation accuracy and completeness