meditohq/medito-app

Refactor Backend Models for UI Separation and Clean Architecture

michaelcspeed opened this issue · 1 comments

Objective:
This ticket aims to refactor multiple backend models used in our codebase, including TrackModel, ShortcutsModel, and others, to align them with clean architecture principles. The focus is on establishing a clear separation between the network layer (handling data from the backend) and the business logic layer (handling UI state and interactions).

Background:
We have identified a pattern in our codebase where several backend models are being directly used for UI state management and interactions. This approach poses risks in terms of mutable state, complexity, and maintainability.

Tasks:

  • Identify Affected Models: Conduct a comprehensive review of the codebase to identify all backend models currently used in the UI.

  • Create Immutable Network Models: For each identified model, ensure it remains immutable (@freezed) when representing backend data. These models should only reflect the data as it is received from the backend, with no UI-related logic.

  • Develop Corresponding Mutable UI Models: Introduce new, mutable models dedicated to the UI layer. These models will handle state and interactions within the UI, clearly separated from the backend data models.

  • Implement Conversion Logic: Develop robust conversion logic between the network layer models and the UI layer models, facilitating a clean and maintainable data flow within the application.

  • Refactor State Management: Update the state management approach to accommodate these architectural changes. This includes ensuring the UI reacts appropriately to user interactions while maintaining stable and predictable state.

  • Update and Expand Testing: Revise existing tests and add new ones to comprehensively cover the updated architecture. Ensure both unit and integration tests adequately reflect the changes.

Expected Outcomes:

  • A clear and consistent separation of concerns between data retrieval (network layer) and UI state management (business logic layer).
  • Enhanced code maintainability and scalability.
  • Improved stability and predictability in the application’s behavior.

Additional Notes:
This refactor is essential for the long-term health of our application. It aligns our codebase with best practices in software architecture, ensuring robustness, clarity, and efficiency. The changes will aid in future development and make the application more resilient to changes and scaling.

This is a big chunk of work, so I would start with a simple example (maybe TracksModel or Shortcuts) and we can review it from there before doing the rest