How davidakpele/wifi-densepose works
1. Overall shape
- This repo is a Python package centered on a real-time inference backend for WiFi CSI-based pose estimation.
- The main runtime is a FastAPI service, with a separate CLI, a browser UI client, and deployment/infrastructure assets around it.
2. Primary execution entry points
- src/main.py and src/app.py are the server/package entry points.
- src/cli.py plus src/commands/{start,status,stop}.py provide lifecycle control for starting, checking, and stopping the system.
- The API server is the production-facing process; the CLI is the operator-facing control plane.
3. Core data pipeline
- The central flow is: WiFi CSI input from hardware → preprocessing/sanitization → pose inference → tracking/aggregation → API/stream output.
- src/hardware/csi_extractor.py and src/core/csi_processor.py handle CSI acquisition and signal preparation.
- src/core/phase_sanitizer.py removes phase noise / hardware-specific offsets before inference.
- src/models/densepose_head.py and src/models/modality_translation.py represent the learned model layer that maps WiFi-derived features to pose outputs.
4. Hardware boundary
- src/hardware/router_interface.py and src/core/router_interface.py define the boundary between the software stack and the physical WiFi/router environment.
- src/services/hardware_service.py likely coordinates device access, polling, and hardware health from the application layer.
- The repo is explicitly designed for CSI-capable routers/cards rather than cameras, so hardware integration is a first-class subsystem.
5. Orchestration and application services
- src/services/orchestrator.py appears to be the main coordination layer that connects hardware input, preprocessing, inference, and downstream publishing.
- src/services/pose_service.py manages pose-specific business logic, while src/services/stream_service.py handles real-time broadcasting.
- src/services/health_check.py and src/services/metrics.py provide operational status and observability data for the API and deployment stack.
6. API surface
- src/api/routers/health.py, pose.py, and stream.py form the main REST API boundary.
- The README’s endpoints match this split: health/system status, pose retrieval/history, and analytics-related access.
- src/api/dependencies.py centralizes shared request-scoped wiring used by the routers.
7. WebSocket streaming path
- src/api/websocket/connection_manager.py and pose_stream.py implement server-push delivery for live pose data.
- This is a separate real-time channel from REST, intended for continuous consumers like dashboards and live monitoring clients.
- The UI and external clients consume this stream for low-latency updates rather than polling.
8. Middleware and cross-cutting controls
- Authentication and rate limiting are implemented both in src/api/middleware/* and src/middleware/*, indicating reusable cross-cutting controls around request handling.
- src/middleware/cors.py and error_handler.py support browser/client interoperability and consistent failure handling.
- Security and traffic-shaping are part of the API boundary, not an afterthought.
9. Persistence and migrations
- src/database/connection.py, models.py, and model_types.py define the persistence layer.
- Alembic migrations live under src/database/migrations, with 001_initial.py as the initial schema baseline.
- The repository includes local SQLite databases in data/, suggesting a default/dev persistence mode plus migration-driven relational storage for production history, analytics, or system state.
10. Background and operational tasks
- src/tasks/backup.py, cleanup.py, and monitoring.py indicate scheduled or operator-triggered background work.
- These tasks support data retention, maintenance, and runtime health rather than the main inference loop.
- They sit beside the API, not inside request handling, which helps keep live pose processing isolated from housekeeping work.
11. User interface client
- The ui/ directory is a separate frontend application that consumes the backend API and WebSocket feeds.
- Components such as DashboardTab, HardwareTab, LiveDemoTab, and PoseDetectionCanvas map directly to system views and live pose visualization.
- ui/services/* and ui/utils/mock-server.js show that the UI can operate against real or mocked backend endpoints.
12. Deployment and infrastructure
- The repo includes Docker, Docker Compose, Kubernetes manifests, Ansible, and Terraform, so deployment is multi-target rather than single-environment.
- monitoring/ and logging/ contain Prometheus, Grafana, Fluentd, and alerting configuration, indicating production observability is a defined subsystem.
- deploy.sh and scripts/validate-deployment.sh support environment validation and release workflows.
13. Testing and validation boundaries
- Tests are organized by unit, integration, end-to-end, and performance under tests/, with mocks for hardware-dependent paths.
- The test suite reflects the same architecture boundaries as the code: CSI extraction, preprocessing, inference, authentication, streaming, and hardware integration.
- The scripts/ folder contains API, websocket, monitoring, and deployment validation scripts used to verify operational behavior.
14. Reference and legacy assets
- references/ contains a separate prototype/demo implementation and data artifacts, likely used as a source reference or historical baseline.
- plans/ and docs/ document the intended architecture, API, integration, and deployment strategy, which is useful for understanding the system’s intended boundaries even when some parts are partially aspirational.
15. How to draw the architecture
- A good diagram should show three major planes: the hardware/data plane (routers/CSI → preprocessing → model inference), the application plane (FastAPI REST + WebSocket + middleware + services), and the operations plane (database, tasks, monitoring, deployment).
- The UI should be shown as a consumer of REST/WebSocket APIs, not as part of the inference pipeline.
- External dependencies worth showing are the WiFi/CSI hardware, persistent storage/database, and monitoring/logging stack.
Main entry points: app.py App wiring · orchestrator.py Orchestrator · health.py API routers · connection.py Database
Components 23
Hardware & model
CSI acquisition, preprocessing, sanitization, and learned pose mapping.
- CSI extractor · Acquires CSI data from hardware sources.
src/hardware/csi_extractor.py - CSI processor · Prepares and normalizes CSI input for inference.
src/core/csi_processor.py - Phase sanitizer · Removes phase noise and hardware-specific offsets.
src/core/phase_sanitizer.py - Router boundary · Software boundary to the physical router / WiFi environment.
src/core/router_interface.py - Pose models · DensePose head and modality translation layers.
src/models/densepose_head.py
Application API
FastAPI entrypoints, middleware, routers, websocket streaming, and orchestration services.
- Main app · Primary server entrypoint for the package.
src/main.py - App wiring · Application assembly and startup wiring.
src/app.py - CLI · Lifecycle control entrypoint for start, status, and stop.
src/cli.py - Control cmds · Start, status, and stop command implementations.
src/commands/start.py - Hardware svc · Coordinates hardware access and device health.
src/services/hardware_service.py - Orchestrator · Connects hardware input, preprocessing, inference, and publishing.
src/services/orchestrator.py - Pose svc · Pose-specific business logic and retrieval.
src/services/pose_service.py - Stream svc · Real-time pose broadcast and delivery.
src/services/stream_service.py - Health & metrics · Operational checks and observability signals.
src/services/health_check.py - API routers · Health, pose, and stream HTTP endpoints.
src/api/routers/health.py - WebSocket stream · Connection manager and live pose websocket delivery.
src/api/websocket/connection_manager.py - Middleware · Auth, rate limiting, CORS, and error handling.
src/middleware/auth.py - Dependencies · Shared request-scoped dependency wiring.
src/api/dependencies.py
Operations
Persistence, tasks, observability, and deployment assets.
- Database · Connection, models, and schema migrations.
src/database/connection.py - Background tasks · Backup, cleanup, and monitoring jobs.
src/tasks/backup.py - Deploy stack · Docker, compose, Kubernetes, Ansible, and Terraform deployment assets.
Dockerfile - Observability · Prometheus, Grafana, Fluentd, and alerting configuration.
monitoring/prometheus-config.yml
UI client
Browser frontend consuming REST and websocket feeds.
- Browser UI · Dashboard and live demo interface consuming APIs and websocket feeds.
ui/app.js
Connections 26
- Main app → App wiring: boots · Main entrypoint initializes the application.
- CLI → Control cmds: dispatches · CLI routes operator actions to lifecycle commands.
- App wiring → Middleware: wraps · Application applies cross-cutting request controls.
- App wiring → Dependencies: injects · Shared dependencies are wired into request handlers.
- App wiring → API routers: serves · HTTP endpoints are mounted into the app.
- App wiring → WebSocket stream: opens · WebSocket channel is exposed by the server.
- API routers → Health & metrics: reads · Health endpoints expose operational state.
- API routers → Pose svc: queries · Pose endpoints use pose domain logic.
- API routers → Stream svc: publishes · Stream endpoints expose realtime delivery.
- WebSocket stream → Stream svc: streams · WebSocket delivery is backed by stream service.
- Orchestrator → CSI extractor: pulls · Orchestrator starts from CSI acquisition.
- Orchestrator → CSI processor: prepares · Raw CSI is transformed into model-ready features.
- CSI processor → Phase sanitizer: cleans · Phase sanitization is part of signal preparation.
- Orchestrator → Pose models: infers · Prepared signal features are passed to learned models.
- Orchestrator → Pose svc: updates · Inference results are turned into pose domain state.
- Orchestrator → Stream svc: emits · Live pose results are pushed to streaming consumers.
- Hardware svc → Router boundary: operates · Hardware service manages the router boundary.
- Hardware svc → CSI extractor: controls · Hardware service coordinates CSI access.
- Router boundary → CSI extractor: feeds · Physical WiFi/router environment provides CSI input.
- Database → Pose svc: stores · Pose history and state persist in the database.
- Database → Health & metrics: records · Operational data and metrics can be persisted.
- Background tasks → Database: maintains · Background jobs manage stored data and runtime upkeep.
- Observability → Health & metrics: backs · Monitoring stack consumes health and metrics signals.
- Deploy stack → App wiring: runs · Deployment assets package the server runtime.
- Browser UI → API routers: calls · UI consumes REST endpoints.
- Browser UI → WebSocket stream: subscribes · UI consumes live websocket pose updates.