mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
16 KiB
16 KiB
REFACTOR RULES
- Do NOT change ANY functionality. All changes must be purely internal refactors.
- Refactor for simplification and maintainability.
- Remove unused files/code only when verified unused.
- No backwards compatability is needed anywhere. Clients and the server are both always up to date.
- Keep behavior/API contracts unchanged.
Required safety checks for every change
- Preserve imports/exports and call signatures unless internal-only and non-observable.
- Validate no runtime behavior changes (manual flow checks + targeted tests when available).
- Make small, reviewable commits per service/component area.
- Treat
npm run buildoutput files committed into this repo as intentional deployment artifacts; do not discard them as noise.
Server backend
- Every service must live in its own folder, even when it remains a single-file implementation.
- Convert every service into a folder-based structure.
- Split very large service files into smaller focused modules.
- Keep files concise and single-purpose.
- Add clear title comments at top of split files.
- Every service/module file should start with a descriptive comment header containing:
- a title line naming the service/module file
- a longer purpose/scope description (not a one-liner)
WebUI frontend
- Every component must live in its own folder, even when it remains a single-file implementation.
- Split large JSX/components and large backing JS files into folderized modules.
- Keep modules clear and focused, with title comments.
- Every component/module file should start with a descriptive comment header containing:
- a title line naming the file/module
- a longer purpose/scope description (not a one-liner)
- Each component must live entirely inside its own folder; do not leave wrapper/compatibility component files outside that folder.
- Remove stale compatibility/leftover code only after usage verification.
REFACTOR TRACKING
Current phase
- Phase 1: Inventory + usage mapping (server + webui)
- Phase 2: Refactor highest-impact offenders first
- Phase 3: Sweep remaining services/components
- Phase 4: Dead code/file removal pass
- Phase 5: Final regression validation (in progress)
Server backend
BIGGEST OFFENDERS
- audio forward service
- button box service
- chat service
- discord bot service
- home assistant service
- llm commentary service
- private rover access request service
- replay services (consolidated under replayEngineV2)
- room camera services (consolidated into roomCameraService multipart folder)
- rover manager service
- session service
- turn service
- verification service
- video auth service
- All remaining services: reorganize to folder structure where needed
COMPLETED SERVICES
- turn service
- session service
- chat service
LARGE CHANGES
- Folderized all files in
server/src/services/into per-service folders withindex.jsentrypoints and updated internal relative imports for new path depth. - Split
server/src/services/turnService/index.jsby extracting constants, shared state helpers, and side-effect action helpers intoturnService/constants.js,turnService/state.js, andturnService/actions.js. - Split
server/src/services/sessionService/index.jsby extracting config/timing constants, sync-throttle state storage, and visibility filter helpers intosessionService/constants.js,sessionService/state.js, andsessionService/filters.js. - Began splitting
server/src/services/roverManager/index.jsby extracting immutable constants and shared state containers intoroverManager/constants.jsandroverManager/state.js. - Continued
roverManagersplit by extracting socket event wiring/handlers intoroverManager/socketHandlers.jswith dependency injection to keep existing behavior unchanged. - Continued
roverManagersplit by extracting numeric/private-safety normalization and battery math intoroverManager/mathUtils.js. - Continued
roverManagersplit by extracting control lifecycle/switching logic intoroverManager/roverLifecycle.js. - Continued
roverManagersplit by extracting sensor processing + private safety + dock guard logic intoroverManager/sensorPipeline.js. - Finished
roverManagerdecomposition by extracting private access policy, roster lifecycle, and spectator/auto-close orchestration intoroverManager/privateAccess.js,roverManager/rosterLifecycle.js, androverManager/spectatorAccess.js;roverManager/index.jsis now a thin composition layer. - Hotfix: corrected
llmCommentaryServiceprompt file path toserver/prompts/commentary_system.txtafter service folder move. - Hotfix: added
server/src/helpers/dataPaths.jsand rewired data-backed services to resolve canonical + legacy data-file locations safely after folderization (adminReason,audioLevels,buttonBox,globalObjective,discordGuildStore,verification,replayEngineV2). - Began
llmCommentaryServicedecomposition by extracting immutable runtime limits/path/frequency normalization tollmCommentaryService/constants.jsand pure prompt/text output helpers tollmCommentaryService/formatters.js. - Continued
llmCommentaryServicedecomposition by extracting admin/runtime projection + failure-normalization helpers tollmCommentaryService/runtimeHelpers.js. - Continued
llmCommentaryServicedecomposition by extracting sensor activity aggregation and snapshot assembly tollmCommentaryService/snapshotEngine.js; rewired commentary tick/event flow to use the new engine. - Continued
llmCommentaryServicedecomposition by extracting socket/role/rover event wiring intollmCommentaryService/hooks.jsand keepingindex.jsfocused on orchestration. - Finished major
llmCommentaryServicedecomposition by extracting tick scheduling, run-loop orchestration, and history-reset behavior intollmCommentaryService/runner.js;llmCommentaryService/index.jsis now a thin composition layer. - Began
audioForwardServicedecomposition by extracting permission/path policy helpers toaudioForwardService/policy.jsand rover/turn/socket event wiring toaudioForwardService/hooks.js; rewired service entrypoint to use extracted modules. - Continued
audioForwardServicedecomposition by extracting ffmpeg worker lifecycle, upload playback, and WHIP ownership/session control intoaudioForwardService/workerEngine.js;audioForwardService/index.jsis now a thin composition layer. - Finished
buttonBoxServicedecomposition by extracting persisted state management tobuttonBoxService/store.js, reward/effect workflows tobuttonBoxService/core.js, and HTTP transport wiring tobuttonBoxService/httpRoute.js;buttonBoxService/index.jsis now a thin composition layer. - Finished
verificationServicedecomposition by extracting persisted store handling toverificationService/store.js, identity/selector normalization toverificationService/identity.js, verification/deterrence/request lifecycle logic toverificationService/verificationFlow.js,verificationService/deterrenceFlow.js, andverificationService/requestFlow.js, plus socket/role event wiring toverificationService/hooks.js;verificationService/index.jsis now a thin composition layer. - Finished
videoAuthServicedecomposition by extracting MediaMTX stream parsing tovideoAuthService/streamParsing.js, role/mode/stream policy checks tovideoAuthService/policy.js, and auth HTTP transport wiring tovideoAuthService/httpRoute.js;videoAuthService/index.jsis now a thin composition layer. - Finished
privateRoverAccessRequestServicedecomposition by extracting in-memory maps/events/constants toprivateRoverAccessRequestService/state.js, shared keying/lookup helpers toprivateRoverAccessRequestService/helpers.js, request/grant business logic toprivateRoverAccessRequestService/core.js, and rover/socket event wiring toprivateRoverAccessRequestService/hooks.js;privateRoverAccessRequestService/index.jsis now a thin composition layer. - Finished
homeAssistantServicedecomposition by extracting shared runtime caches/constants tohomeAssistantService/state.js, entity/trigger normalization helpers tohomeAssistantService/entityHelpers.js, automation/state engine logic tohomeAssistantService/runtimeEngine.js, websocket transport/reconnect lifecycle tohomeAssistantService/transport.js, and mode/turn/socket event wiring tohomeAssistantService/hooks.js;homeAssistantService/index.jsis now a thin composition layer. - Finished
discordBotServicedecomposition by extracting presence rotation/state todiscordBotService/presence.js, channel/typing transport helpers todiscordBotService/channelIO.js, command routing and admin command handlers todiscordBotService/commandHandlers.js, and event-bus/chat-bridge/moderation DM workflows todiscordBotService/integrations.js;discordBotService/index.jsis now a thin composition layer. - Finished
replayEngineV2decomposition by extracting environment/path constants toreplayEngineV2/constants.js, mutable runtime state toreplayEngineV2/state.js, source discovery/worker arg building toreplayEngineV2/sources.js, ffmpeg worker lifecycle toreplayEngineV2/workerManager.js, segment indexing/retention/health snapshot logic toreplayEngineV2/segmentStore.js, sidebar SVG/video rendering toreplayEngineV2/sidebarRenderer.js, and replay assembly pipeline toreplayEngineV2/replayBuilder.js;replayEngineV2/index.jsis now a thin orchestration layer. - Consolidated replay-related single-file services into
replayEngineV2by moving cooldown state (cooldown.js), user-facing replay source validation/defaults (replaySources.js), and replay socket hooks (socketHooks.js) into the engine folder; removed obsolete standalone servicesreplayBuildService,replayService,replaySourceService, andreplaySocketServiceand rewired dependents to import directly fromreplayEngineV2. - Finished
chatServicedecomposition by extracting runtime constants (chatService/constants.js), shared mutable state (chatService/state.js), content/moderation helpers (chatService/contentFilters.js), payload/context builders (chatService/contextBuilders.js), bus/history broadcast pipeline (chatService/broadcast.js), rover-side notification helpers (chatService/notifications.js), message handlers (chatService/handlers.js), and socket/event-bus wiring (chatService/socketHooks.js);chatService/index.jsis now a thin orchestration layer. - Consolidated room-camera services into
roomCameraServiceby absorbing catalog (roomCameraService), snapshot polling/streaming (roomCameraSnapshotService), socket fan-out (roomCameraSocketService), and replay assembly (roomCameraReplayService) into one multipart folder (roomCameraService/catalog.js,snapshotEngine.js,socketGateway.js,replayBuilder.js), and updated imports/startup wiring to use the consolidated service exports. - Follow-up: moved room-camera replay assembly module from
roomCameraService/replayBuilder.jsintoreplayEngineV2/roomCameraReplayBuilder.js;roomCameraServicenow consumes replay functionality from replay engine ownership while keeping the same exported room-camera replay API. - Consolidated rover snapshot polling/socket services into
roverSnapshotServiceby absorbingroverSnapshotSocketServiceinto folder modules (roverSnapshotService/poller.js,socketGateway.js) and keepingroverSnapshotService/index.jsas the startup composition/export layer.
WebUI frontend
BIGGEST OFFENDERS
- mini summary app
- spectator app
- vip audio upload card
- admin panel
- drive dock action
- gamepad mapping settings
- mobile controls
- top down map
- video tile
- Sweep
webuifor unused or unneeded files/code with verification
COMPLETED COMPONENTS
- mini summary app
- spectator app
- video tile
- vip audio upload card
- admin panel
- drive dock action
- gamepad mapping settings
- mobile controls
- top down map
LARGE CHANGES
- Split mini summary app into folderized modules under
webui/src/mini/MiniSummaryApp/, then removed the now-unneeded external wrapper (webui/src/mini/MiniSummaryApp.jsx) and rewired app bootstrap imports directly to the folder entrypoint module. - Split spectator app into folderized modules under
webui/src/spectate/SpectatorApp/, then removed the now-unneeded external wrapper (webui/src/spectate/SpectatorApp.jsx) and rewired app bootstrap imports directly to the folder entrypoint module. - Split
webui/src/components/VideoTile.jsxby extracting HUD, overlays, chat input, and constants intowebui/src/components/VideoTile/while preserving the existingVideoTile.jsxpublic component API. - Split
webui/src/components/vip/VipAudioUploadCard.jsxby extracting transport/audio helpers and UI atoms intowebui/src/components/vip/VipAudioUploadCard/while preserving the existingVipAudioUploadCard.jsximport/export API. - Split
webui/src/components/AdminPanel.jsxintowebui/src/components/AdminPanel/and extracted monitor/health/log/LLM helper modules; updated consumers to folder entrypoint and removed external wrapper file. - Moved
DriveDockActiontowebui/src/components/DriveDockAction/index.jsxand updated all consumers to folder entrypoint imports. - Split
webui/src/components/GamepadMappingSettings.jsxintowebui/src/components/GamepadMappingSettings/with extracted constants/helpers/SliderField modules and removed the standalone component file. - Split
webui/src/components/MobileControls.jsxintowebui/src/components/MobileControls/with extracted joystick/aux/constants modules; preserved named exports and moved app import to folder entrypoint. - Split
webui/src/components/TopDownMap.jsxintowebui/src/components/TopDownMap/with extracted geometry/color helpers and visual SVG primitive modules; updated all consumers to folder entrypoint. - Folderized all remaining top-level files under
webui/src/components/into per-componentindex.jsxfolders and rewired component imports to match the new structure. - Removed unreferenced components
CameraServoPanelandControlSummaryafter dependency-map verification and successful rebuild.
Done criteria (per item)
- Folderized structure created.
- Large functions extracted into focused files.
- Imports/exports updated with no external behavior change.
- Verified references/usages still resolve.
- Passed targeted checks/tests for touched area.
Phase 4 notes
- Removed stale WebUI compatibility wrapper files
webui/src/mini/MiniSummaryApp.jsxandwebui/src/spectate/SpectatorApp.jsxafter reference verification; rewiredwebui/src/main.jsxdirectly to folder entrypoint modules. - Verified no remaining replay/room-camera/rover-snapshot legacy service imports (
replayBuildService,replayService,replaySourceService,replaySocketService,roomCameraReplayService,roomCameraSocketService,roomCameraSnapshotService,roverSnapshotSocketService) in server startup/runtime wiring.
Phase 5 checklist
- WebUI production build passes (
npm run build), including updated import graph after wrapper removals. - Server JS syntax check passes (
node --checkacrossserver/src/**/*.js). - Live rover snapshots: verify continuously updating snapshots from mediaMTX writer on deployed server.
- Replay from WebUI button: verify request -> build -> delivery path on deployed server.
- Replay from Discord command: verify request -> build -> delivery path on deployed server.
- Discord verification + private access request flow: verify end-to-end behavior on deployed server.
- Home Assistant idle-light behavior: verify expected mode/idle transitions on deployed server.
- Driver/session/turn core flow: verify control assignment, queue movement, command acceptance/rejection behavior.