Skip to content

Refactor: Extract components and utilities into modular architecture#3

Open
Gluflex wants to merge 1 commit into
mainfrom
claude/refactor-modular-structure-v1IIX
Open

Refactor: Extract components and utilities into modular architecture#3
Gluflex wants to merge 1 commit into
mainfrom
claude/refactor-modular-structure-v1IIX

Conversation

@Gluflex
Copy link
Copy Markdown
Owner

@Gluflex Gluflex commented Mar 12, 2026

Summary

This PR refactors the monolithic App.jsx and DripitoSim.jsx files into a modular, component-based architecture. The codebase is reorganized into separate concerns: UI components, simulation physics, utility functions, and constants, improving maintainability and testability.

Key Changes

Component Extraction

  • Extracted LCD, Btn into dedicated component files (src/components/LCD.jsx, src/components/Btn.jsx)
  • Created new panel components: DevicePanel, DropSimulatorPanel, LiveStatsPanel, SpecPanel, ScreenJumper for organized UI sections
  • Moved device logic into a custom hook useDripMonitor (src/hooks/useDripMonitor.js)

Simulation Refactoring

  • Extracted physics calculations into src/sim/physics.js (makeDrop, updateDropPhysics, calcBeamOcclusion)
  • Extracted measurement logic into src/sim/measurement.js (tryMeasureDrop)
  • Extracted rendering into src/sim/drawChamber.js and src/sim/drawScope.js
  • Moved simulation constants to src/constants/simConstants.js

Utilities & Constants

  • Created src/utils/displayHelpers.js for LCD display formatting (formatElapsed, alarmLevel, devPct, getLines)
  • Created src/utils/flowCalc.js for flow rate calculations (calcInstFlow, calcAvgFlow, calcTotalMl)
  • Extracted device constants to src/constants/deviceConstants.js (drip sets, alarm states, timing)
  • Added src/styles/theme.js for centralized color tokens

App Structure

  • App.jsx now acts as a thin orchestration layer, delegating to useDripMonitor hook and component composition
  • Removed unused App.css
  • Simplified index.css to essential styles only

Implementation Details

  • The useDripMonitor hook encapsulates all device state management (drop counting, flow calculation, alarm logic, UI state)
  • Physics simulation is now purely functional with immutable drop updates
  • Display logic is separated from state management, making LCD rendering testable
  • All magic numbers and constants are centralized for easier clinical parameter adjustments
  • Component props are explicitly typed through usage patterns, improving clarity

https://claude.ai/code/session_01AGTCTQnVmKLfVutZoNHKhj

…r architecture

Split two 654-line and 824-line monolithic files into 20 focused modules
with clear separation of concerns, following industry best practices.

New structure:
- src/constants/ — deviceConstants.js, simConstants.js (pure data)
- src/components/ — LCD, Btn, DevicePanel, DropSimulatorPanel, LiveStatsPanel,
                    ScreenJumper, SpecPanel (presentational components)
- src/hooks/ — useDripMonitor.js (all device state, effects, handlers)
- src/utils/ — flowCalc.js, displayHelpers.js (pure business logic)
- src/sim/ — physics.js, measurement.js, drawChamber.js, drawScope.js
             (simulation engine separated from rendering)
- src/styles/ — theme.js (design tokens for recurring color values)

App.jsx reduced from 654 to 110 lines (orchestration only).
DripitoSim.jsx tick() reduced from 490 lines to ~30-line orchestrator.
Deleted unused src/App.css; cleaned Vite scaffold styles from index.css.
No behavioral changes; all functionality preserved exactly.

https://claude.ai/code/session_01AGTCTQnVmKLfVutZoNHKhj
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dripito-ui Ready Ready Preview, Comment Mar 12, 2026 8:27am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants