# davidakpele/wifi-densepose architecture

> Architecture diagram of the GitHub repository davidakpele/wifi-densepose, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davidakpele/wifi-densepose
- Repository: https://github.com/davidakpele/wifi-densepose

## Overview

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: [`src/app.py`](https://github.com/davidakpele/wifi-densepose/blob/main/src/app.py) (App wiring), [`src/services/orchestrator.py`](https://github.com/davidakpele/wifi-densepose/blob/main/src/services/orchestrator.py) (Orchestrator), [`src/api/routers/health.py`](https://github.com/davidakpele/wifi-densepose/blob/main/src/api/routers/health.py) (API routers), [`src/database/connection.py`](https://github.com/davidakpele/wifi-densepose/blob/main/src/database/connection.py) (Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_hardware["Hardware & model"]
  node_node_csi_extractor["CSI extractor<br/>hardware adapter<br/>[csi_extractor.py]"]
  node_node_csi_processor["CSI processor<br/>signal pipeline<br/>[csi_processor.py]"]
  node_node_phase_sanitizer["Phase sanitizer<br/>signal cleanup<br/>[phase_sanitizer.py]"]
  node_node_router_boundary["Router boundary<br/>hardware interface"]
  node_node_models["Pose models<br/>ml models<br/>[densepose_head.py]"]
end

subgraph group_group_api["Application API"]
  node_node_main["Main app<br/>python entrypoint<br/>[main.py]"]
  node_node_app["App wiring<br/>app bootstrap<br/>[app.py]"]
  node_node_cli["CLI<br/>operator command<br/>[cli.py]"]
  node_node_commands["Control cmds<br/>command handlers<br/>[start.py]"]
  node_node_hw_service["Hardware svc"]
  node_node_orchestrator["Orchestrator<br/>workflow service<br/>[orchestrator.py]"]
  node_node_pose_service["Pose svc<br/>domain service<br/>[pose_service.py]"]
  node_node_stream_service["Stream svc<br/>realtime service<br/>[stream_service.py]"]
  node_node_health_metrics["Health & metrics<br/>ops service<br/>[health_check.py]"]
  node_node_api_routers["API routers<br/>REST boundary<br/>[health.py]"]
  node_node_ws["WebSocket stream<br/>push channel"]
  node_node_middleware["Middleware<br/>cross-cutting<br/>[auth.py]"]
  node_node_dependencies["Dependencies<br/>api wiring<br/>[dependencies.py]"]
end

subgraph group_group_ops["Operations"]
  node_node_db[("Database<br/>persistence<br/>[connection.py]")]
  node_node_tasks["Background tasks<br/>maintenance jobs<br/>[backup.py]"]
  node_node_deploy["Deploy stack<br/>infra assets"]
  node_node_monitoring["Observability<br/>monitoring stack"]
end

subgraph group_group_ui["UI client"]
  node_node_ui["Browser UI<br/>frontend client<br/>[app.js]"]
end

node_node_main -->|"boots"| node_node_app
node_node_cli -->|"dispatches"| node_node_commands
node_node_app -->|"wraps"| node_node_middleware
node_node_app -->|"injects"| node_node_dependencies
node_node_app -->|"serves"| node_node_api_routers
node_node_app -->|"opens"| node_node_ws
node_node_api_routers -->|"reads"| node_node_health_metrics
node_node_api_routers -->|"queries"| node_node_pose_service
node_node_api_routers -->|"publishes"| node_node_stream_service
node_node_ws -->|"streams"| node_node_stream_service
node_node_orchestrator -->|"pulls"| node_node_csi_extractor
node_node_orchestrator -->|"prepares"| node_node_csi_processor
node_node_csi_processor -->|"cleans"| node_node_phase_sanitizer
node_node_orchestrator -->|"infers"| node_node_models
node_node_orchestrator -->|"updates"| node_node_pose_service
node_node_orchestrator -->|"emits"| node_node_stream_service
node_node_hw_service -->|"operates"| node_node_router_boundary
node_node_hw_service -->|"controls"| node_node_csi_extractor
node_node_router_boundary -->|"feeds"| node_node_csi_extractor
node_node_db -->|"stores"| node_node_pose_service
node_node_db -->|"records"| node_node_health_metrics
node_node_tasks -->|"maintains"| node_node_db
node_node_monitoring -->|"backs"| node_node_health_metrics
node_node_deploy -->|"runs"| node_node_app
node_node_ui -->|"calls"| node_node_api_routers
node_node_ui -->|"subscribes"| node_node_ws

click node_node_main "https://github.com/davidakpele/wifi-densepose/blob/main/src/main.py"
click node_node_app "https://github.com/davidakpele/wifi-densepose/blob/main/src/app.py"
click node_node_cli "https://github.com/davidakpele/wifi-densepose/blob/main/src/cli.py"
click node_node_commands "https://github.com/davidakpele/wifi-densepose/blob/main/src/commands/start.py"
click node_node_hw_service "https://github.com/davidakpele/wifi-densepose/blob/main/src/services/hardware_service.py"
click node_node_orchestrator "https://github.com/davidakpele/wifi-densepose/blob/main/src/services/orchestrator.py"
click node_node_pose_service "https://github.com/davidakpele/wifi-densepose/blob/main/src/services/pose_service.py"
click node_node_stream_service "https://github.com/davidakpele/wifi-densepose/blob/main/src/services/stream_service.py"
click node_node_health_metrics "https://github.com/davidakpele/wifi-densepose/blob/main/src/services/health_check.py"
click node_node_api_routers "https://github.com/davidakpele/wifi-densepose/blob/main/src/api/routers/health.py"
click node_node_ws "https://github.com/davidakpele/wifi-densepose/blob/main/src/api/websocket/connection_manager.py"
click node_node_middleware "https://github.com/davidakpele/wifi-densepose/blob/main/src/middleware/auth.py"
click node_node_dependencies "https://github.com/davidakpele/wifi-densepose/blob/main/src/api/dependencies.py"
click node_node_csi_extractor "https://github.com/davidakpele/wifi-densepose/blob/main/src/hardware/csi_extractor.py"
click node_node_csi_processor "https://github.com/davidakpele/wifi-densepose/blob/main/src/core/csi_processor.py"
click node_node_phase_sanitizer "https://github.com/davidakpele/wifi-densepose/blob/main/src/core/phase_sanitizer.py"
click node_node_router_boundary "https://github.com/davidakpele/wifi-densepose/blob/main/src/core/router_interface.py"
click node_node_models "https://github.com/davidakpele/wifi-densepose/blob/main/src/models/densepose_head.py"
click node_node_db "https://github.com/davidakpele/wifi-densepose/blob/main/src/database/connection.py"
click node_node_tasks "https://github.com/davidakpele/wifi-densepose/blob/main/src/tasks/backup.py"
click node_node_deploy "https://github.com/davidakpele/wifi-densepose/tree/main/Dockerfile"
click node_node_monitoring "https://github.com/davidakpele/wifi-densepose/blob/main/monitoring/prometheus-config.yml"
click node_node_ui "https://github.com/davidakpele/wifi-densepose/blob/main/ui/app.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_csi_extractor,node_node_csi_processor,node_node_phase_sanitizer,node_node_router_boundary,node_node_models toneBlue
class node_node_main,node_node_app,node_node_cli,node_node_commands,node_node_hw_service,node_node_orchestrator,node_node_pose_service,node_node_stream_service,node_node_health_metrics,node_node_api_routers,node_node_ws,node_node_middleware,node_node_dependencies toneAmber
class node_node_db,node_node_tasks,node_node_deploy,node_node_monitoring toneMint
class node_node_ui toneRose
```

## Components

### Hardware & model

CSI acquisition, preprocessing, sanitization, and learned pose mapping.

- [CSI extractor](https://github.com/davidakpele/wifi-densepose/blob/main/src/hardware/csi_extractor.py): hardware adapter · Acquires CSI data from hardware sources. · `src/hardware/csi_extractor.py`
- [CSI processor](https://github.com/davidakpele/wifi-densepose/blob/main/src/core/csi_processor.py): signal pipeline · Prepares and normalizes CSI input for inference. · `src/core/csi_processor.py`
- [Phase sanitizer](https://github.com/davidakpele/wifi-densepose/blob/main/src/core/phase_sanitizer.py): signal cleanup · Removes phase noise and hardware-specific offsets. · `src/core/phase_sanitizer.py`
- [Router boundary](https://github.com/davidakpele/wifi-densepose/blob/main/src/core/router_interface.py): hardware interface · Software boundary to the physical router / WiFi environment. · `src/core/router_interface.py`
- [Pose models](https://github.com/davidakpele/wifi-densepose/blob/main/src/models/densepose_head.py): ml 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](https://github.com/davidakpele/wifi-densepose/blob/main/src/main.py): python entrypoint · Primary server entrypoint for the package. · `src/main.py`
- [App wiring](https://github.com/davidakpele/wifi-densepose/blob/main/src/app.py): app bootstrap · Application assembly and startup wiring. · `src/app.py`
- [CLI](https://github.com/davidakpele/wifi-densepose/blob/main/src/cli.py): operator command · Lifecycle control entrypoint for start, status, and stop. · `src/cli.py`
- [Control cmds](https://github.com/davidakpele/wifi-densepose/blob/main/src/commands/start.py): command handlers · Start, status, and stop command implementations. · `src/commands/start.py`
- [Hardware svc](https://github.com/davidakpele/wifi-densepose/blob/main/src/services/hardware_service.py): service · Coordinates hardware access and device health. · `src/services/hardware_service.py`
- [Orchestrator](https://github.com/davidakpele/wifi-densepose/blob/main/src/services/orchestrator.py): workflow service · Connects hardware input, preprocessing, inference, and publishing. · `src/services/orchestrator.py`
- [Pose svc](https://github.com/davidakpele/wifi-densepose/blob/main/src/services/pose_service.py): domain service · Pose-specific business logic and retrieval. · `src/services/pose_service.py`
- [Stream svc](https://github.com/davidakpele/wifi-densepose/blob/main/src/services/stream_service.py): realtime service · Real-time pose broadcast and delivery. · `src/services/stream_service.py`
- [Health & metrics](https://github.com/davidakpele/wifi-densepose/blob/main/src/services/health_check.py): ops service · Operational checks and observability signals. · `src/services/health_check.py`
- [API routers](https://github.com/davidakpele/wifi-densepose/blob/main/src/api/routers/health.py): REST boundary · Health, pose, and stream HTTP endpoints. · `src/api/routers/health.py`
- [WebSocket stream](https://github.com/davidakpele/wifi-densepose/blob/main/src/api/websocket/connection_manager.py): push channel · Connection manager and live pose websocket delivery. · `src/api/websocket/connection_manager.py`
- [Middleware](https://github.com/davidakpele/wifi-densepose/blob/main/src/middleware/auth.py): cross-cutting · Auth, rate limiting, CORS, and error handling. · `src/middleware/auth.py`
- [Dependencies](https://github.com/davidakpele/wifi-densepose/blob/main/src/api/dependencies.py): api wiring · Shared request-scoped dependency wiring. · `src/api/dependencies.py`

### Operations

Persistence, tasks, observability, and deployment assets.

- [Database](https://github.com/davidakpele/wifi-densepose/blob/main/src/database/connection.py): persistence · Connection, models, and schema migrations. · `src/database/connection.py`
- [Background tasks](https://github.com/davidakpele/wifi-densepose/blob/main/src/tasks/backup.py): maintenance jobs · Backup, cleanup, and monitoring jobs. · `src/tasks/backup.py`
- [Deploy stack](https://github.com/davidakpele/wifi-densepose/tree/main/Dockerfile): infra assets · Docker, compose, Kubernetes, Ansible, and Terraform deployment assets. · `Dockerfile`
- [Observability](https://github.com/davidakpele/wifi-densepose/blob/main/monitoring/prometheus-config.yml): monitoring stack · Prometheus, Grafana, Fluentd, and alerting configuration. · `monitoring/prometheus-config.yml`

### UI client

Browser frontend consuming REST and websocket feeds.

- [Browser UI](https://github.com/davidakpele/wifi-densepose/blob/main/ui/app.js): frontend client · Dashboard and live demo interface consuming APIs and websocket feeds. · `ui/app.js`

## Connections

- 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.
