Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

refactor: decompose sensing-server main.rs (3,765 lines → 14 modules) — ADR-051 #174

@ruvnet

Description

@ruvnet

Problem

sensing-server/src/main.rs is 3,765 lines with cyclomatic complexity ~65. It contains 12 structs, 60+ functions, and a 37-field AppStateInner god object. This was identified as Finding #2 in the quality engineering analysis (#170) and is tracked as Sprint 2 in ADR-050.

Plan

Decompose into 14 focused modules across 6 phases. See ADR-051 for the full extraction plan.

Module Breakdown

Module Contents ~Lines
cli.rs Args struct, CLI parsing 100
state.rs AppStateInner + all DTOs 220
signal.rs Feature extraction, classification 350
smoothing.rs EMA smoothing, vital sign filtering 180
routes_health.rs Health/readiness/info endpoints 350
routes_model.rs Model management endpoints 180
routes_recording.rs Recording endpoints 210
routes_training.rs Training + adaptive endpoints 120
routes_sensing.rs Vitals, WASM, SONA endpoints 150
routes_pose.rs Pose estimation + endpoints 280
websocket.rs WS upgrade + client handlers 170
udp_receiver.rs UDP CSI frame receiver 170
data_sources.rs Windows WiFi + simulated data 400
router.rs Route assembly 80

Result: main.rs drops to ~250 lines (startup only).

Extraction Phases

  1. cli.rs + state.rs (types only, zero behavioral change)
  2. signal.rs + smoothing.rs (pure functions)
  3. routes_health.rs + routes_model.rs + routes_recording.rs
  4. routes_training.rs + routes_sensing.rs + routes_pose.rs
  5. websocket.rs + udp_receiver.rs + data_sources.rs
  6. router.rs + final cleanup

Acceptance Criteria

  • No file over 500 lines
  • cargo check and cargo test pass after each phase
  • All existing endpoints behave identically
  • Each new module has at least smoke tests
  • AppStateInner refactored into domain sub-states
  • Add criterion benchmarks for CSI parsing, signal pipeline, WS fanout

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions