diff --git a/docs/2025-10-18_MODULAR_STRUCTURE.md b/docs/2025-10-18_MODULAR_STRUCTURE.md new file mode 100644 index 0000000..810fc57 --- /dev/null +++ b/docs/2025-10-18_MODULAR_STRUCTURE.md @@ -0,0 +1,82 @@ +# Medication Plan Assistant - Modular Structure + +This application has been successfully modularized to simplify maintenance and further development. + +## 📁 New Project Structure + +```text +src/ +├── App.js # Main component (greatly simplified) +├── components/ # UI components +│ ├── DoseSchedule.js # Dosage schedule input +│ ├── DeviationList.js # Deviations from the schedule +│ ├── SuggestionPanel.js # Correction suggestions +│ ├── SimulationChart.js # Chart component +│ ├── Settings.js # Settings panel +│ ├── TimeInput.js # Time input with picker +│ └── NumericInput.js # Numeric input with +/- buttons +├── hooks/ # Custom React hooks +│ ├── useAppState.js # State management & local storage +│ └── useSimulation.js # Simulation logic & calculations +├── utils/ # Utility functions +│ ├── timeUtils.js # Time utility functions +│ ├── pharmacokinetics.js # PK calculations +│ ├── calculations.js # Concentration calculations +│ └── suggestions.js # Correction suggestion algorithm +└── constants/ + └── defaults.js # Constants & default values +``` + +## 🎯 Advantages of the new structure + +### ✅ Better maintainability + +- **Small, focused modules**: Each file has a clear responsibility +- **Easier debugging**: Problems can be localized more quickly +- **Clearer code organization**: Related functions are grouped together + +### ✅ Reusability + +- **UI components**: `TimeInput`, `NumericInput` can be used anywhere +- **Utility functions**: PK calculations are isolated and testable +- **Custom hooks**: State logic is reusable + +### ✅ Development friendliness + +- **Parallel development**: Teams can work on different modules +- **Simpler testing**: Each module can be tested in isolation +- **Better IDE support**: Smaller files = better performance + +### ✅ Scalability + +- **New features**: Easy to add as new modules +- **Code splitting**: Possible for better performance +- **Refactoring**: Changes are limited locally + +## 🔧 Technical details + +### State management + +- **useAppState**: Manages global app state and LocalStorage +- **useSimulation**: Manages all simulation-related calculations + +### Component architecture + +- **Dumb components**: UI components receive props and call callbacks +- **Smart Components**: Hooks manage state and business logic +- **Separation of Concerns**: UI, state, and business logic are separated + +### Utils & Calculations + +- **Pure functions**: All calculations are side-effect-free +- **Modular exports**: Functions can be imported individually +- **Typed interfaces**: Clear input/output definitions + +## 🚀 Migration complete + +The application works identically to the original version, but now: + +- Split into **350+ lines** across **several small modules** +- **Easier to understand** and modify +- **Ready for further features** and improvements +- **More test-friendly** for unit and integration tests diff --git a/README.create-react-app.md b/docs/README.create-react-app.md similarity index 100% rename from README.create-react-app.md rename to docs/README.create-react-app.md diff --git a/src/App.js b/src/App.js index f0b03ae..26a3b6b 100644 --- a/src/App.js +++ b/src/App.js @@ -6,36 +6,40 @@ import DeviationList from './components/DeviationList.js'; import SuggestionPanel from './components/SuggestionPanel.js'; import SimulationChart from './components/SimulationChart.js'; import Settings from './components/Settings.js'; +import LanguageSelector from './components/LanguageSelector.js'; // Custom Hooks import { useAppState } from './hooks/useAppState.js'; import { useSimulation } from './hooks/useSimulation.js'; +import { useLanguage } from './hooks/useLanguage.js'; // --- Main Component --- const MedPlanAssistant = () => { - const { - appState, - updateState, - updateNestedState, - updateUiSetting, - handleReset + const { currentLanguage, t, changeLanguage } = useLanguage(); + + const { + appState, + updateState, + updateNestedState, + updateUiSetting, + handleReset } = useAppState(); - const { - pkParams, - doses, - therapeuticRange, - doseIncrement, - uiSettings + const { + pkParams, + doses, + therapeuticRange, + doseIncrement, + uiSettings } = appState; - - const { - showDayTimeXAxis, - chartView, - yAxisMin, - yAxisMax, - simulationDays, - displayedDays + + const { + showDayTimeXAxis, + chartView, + yAxisMin, + yAxisMax, + simulationDays, + displayedDays } = uiSettings; const { @@ -54,57 +58,65 @@ const MedPlanAssistant = () => {
Simulation für Lisdexamfetamin (LDX) und d-Amphetamin (d-amph)
+{t.appSubtitle}
+- Vorschlag: {suggestion.dose}mg (statt {suggestion.originalDose}mg) um {suggestion.time}. + {t.suggestion}: {suggestion.dose}{t.mg} ({t.instead} {suggestion.originalDose}{t.mg}) {t.at} {suggestion.time}.