# SwiftData Retirement Inventory

**Last Updated:** 2026-05-26

This inventory supports Milestone 9 in [`Refactoring-Plan.md`](Refactoring-Plan.md).
SwiftData is legacy/prototype infrastructure only. The target app must launch
and run active Time Machine flows from SQLite archive + Core Data cache, with
local settings stored outside SwiftData where needed.

## Current Count

After moving the Snapshots, Data Types, Dashboard view, and Dashboard view model
roots away from direct SwiftData imports, 4 app files still have SwiftData
imports because launch, capture bridge writes, and remaining model definitions
still use prototype snapshot handles.

## Launch Container

This file keeps SwiftData required at app launch:

- `HealthProbe/HealthProbeApp.swift`

Retirement path:
- remove `.modelContainer(...)` once no active view or capture service needs
  `@Query` or `ModelContext`.

## Legacy Model Definitions

These files define SwiftData `@Model` classes and are the largest retirement
block:

- `HealthProbe/Models/HealthSnapshot.swift`
- `HealthProbe/Models/TypeCount.swift`

Retirement path:
- replace `HealthSnapshot` and `TypeCount` active reads/writes with
  archive/cache DTOs;
- retire active reads/writes before removing the launch container.

## Capture And Maintenance Services

These services still write/read legacy SwiftData transition models:

- `HealthProbe/Services/HealthKitService.swift`

Retirement path:
- make capture persist archive observations without writing prototype
  `HealthSnapshot` bridge rows.

## UI And View Models

No active UI/view-model file currently imports SwiftData. Dashboard
capture/review actions now pass only DTOs and snapshot ids while the bridge
exists; `HealthSnapshot` instances, `ModelContext`, and `FetchDescriptor`
access are isolated in `HealthKitService`.

Retirement path:
- stop writing prototype `HealthSnapshot` bridge rows during capture/review
  flows;
- keep status/report rows on archive/cache APIs.

## Removed During This Pass

The following SwiftData dependencies were removed from active flows:

- `HealthProbe/Services/AnomalyDetector.swift`
- `HealthProbe/Services/IntegrityService.swift`
- `HealthProbe/Models/MetricTimeoutProfile.swift` was deleted.
- Metric timeout learning/calibration now uses
  `HealthProbe/Utilities/LocalMetricTimeoutProfile.swift`, a Codable local
  store outside `ModelContainer`.
- `SettingsView`, `DashboardView`, and `HealthKitService` read/write timeout
  calibration through the local store.
- `HealthProbe/Models/DeviceProfile.swift` was deleted.
- Device display name/color settings now use
  `HealthProbe/Utilities/LocalDeviceProfile.swift`, a Codable local store used
  by Settings, Dashboard, and archive/cache snapshot rows.
- `HealthProbe/Models/OperationLog.swift` was deleted.
- Snapshot deletion logging now uses
  `HealthProbe/Utilities/LocalOperationLog.swift`, a bounded Codable local log
  outside `ModelContainer`.
- `HealthProbe/ContentView.swift` no longer imports SwiftData; its preview no
  longer creates a legacy model container.
- `HealthProbe/Views/Settings/SettingsView.swift` no longer imports SwiftData.
  Its Data section now reports/rebuilds/deletes the rebuildable Core Data UI
  cache and leaves the SQLite archive untouched.
- `HealthProbe/Views/Dashboard/DashboardView.swift` no longer imports SwiftData
  or reads `ModelContext`. Capture/review actions now route through the
  Dashboard view model while the legacy bridge is retired.
- `HealthProbe/ViewModels/DashboardViewModel.swift` no longer imports SwiftData
  or reads `ModelContext`/`FetchDescriptor`. It now keeps only snapshot ids and
  DTO review state; legacy snapshot-cache operations are isolated in
  `HealthKitService`.
- `HealthProbe/Views/DataTypes/RecordChangeEvolutionChart.swift` now accepts a
  small `RecordChangeEvolutionSnapshot` DTO and loads archive/cache counts
  without importing SwiftData or querying `SnapshotDelta`.
- `HealthProbe/ViewModels/DataTypeTemporalDistributionViewModel.swift` and
  `HealthProbe/Views/DataTypes/DataTypeTemporalDistributionView.swift` now read
  a `TemporalDistributionInput` DTO backed by `TypeCountDetailCache`; they no
  longer import SwiftData, query timeline snapshots, or require `ModelContext`.
- `HealthProbe/Views/Snapshots/SnapshotsView.swift` no longer queries
  `SnapshotDelta` or runs `DeltaService` list-summary repair. Timeline change
  summaries come from archive/cache rows when available; SwiftData remains there
  only for temporary snapshot navigation/deletion handles.
- `HealthProbe/ViewModels/DataTypesViewModel.swift` now resolves baselines from
  small observation contexts and builds rows from Core Data cache + SQLite
  archive diff APIs. It no longer falls back to legacy direct SwiftData
  `TypeCount` relationship traversal.
- `HealthProbe/Views/DataTypes/DataTypesView.swift` no longer imports
  SwiftData or queries `HealthSnapshot`; it loads Core Data cached observation
  rows and opens `DataTypeArchiveDetailView`, an archive/cache-only detail view
  with paged SQLite new/missing record drill-down.
- `HealthProbe/Views/Snapshots/SnapshotsView.swift` no longer imports
  SwiftData or queries `HealthSnapshot`; it loads Core Data cached observation
  rows and opens `SnapshotArchiveDetailView`, an archive/cache-only detail view
  that feeds Data Type drill-down through observation ids and cached summaries.
- The unused legacy SwiftData
  `HealthProbe/Views/Snapshots/SnapshotDetailView.swift`,
  `HealthProbe/Views/Snapshots/DataTypeSnapshotDetailView.swift`, and
  `HealthProbe/Utilities/SnapshotPDFExporter.swift` were deleted. Active
  snapshot/type drill-down now uses archive/cache DTOs.
- The unused legacy maintenance services
  `HealthProbe/Services/SnapshotLifecycleService.swift`,
  `HealthProbe/Services/IntegrityService.swift`,
  `HealthProbe/Services/ObserverService.swift`, and
  `HealthProbe/Utilities/TypeCountArchiveRepair.swift` were deleted. Active
  observation deletion/repair/background-capture policy now belongs to the
  SQLite archive/cache design, not the old SwiftData chain.
- The unused legacy delta stack
  `HealthProbe/Services/DeltaService.swift`,
  `HealthProbe/Models/SnapshotDelta.swift`,
  `HealthProbe/Models/TypeDelta.swift`, and
  `HealthProbe/Models/TypeDeltaClassification.swift` was deleted.
  Capture no longer writes prototype `SnapshotDelta`/`TypeDelta` rows after the
  archive observation is saved.
- The unused SwiftData `HealthRecord` model was deleted from
  `HealthProbe/Models/HealthRecord.swift` and removed from `ModelContainer`.
  The file now only contains the `HealthRecordValue` DTO and compact archive
  helpers used by archive/cache record previews.
- `HealthProbe/Models/YearlyCount.swift` and
  `HealthProbe/Models/TypeDistributionBin.swift` now define Codable payload
  structs instead of SwiftData models. `TypeCount` stores those rows in compact
  external-storage data fields while the capture bridge still exists.
- The unused `HealthProbe/Views/DataTypes/TypeEvolutionTimeline.swift` legacy
  chart was deleted, and the remaining `TypeDiff`/`DiffFilter` DTOs now live in
  `HealthProbe/Models/TypeDiff.swift` instead of the removed
  `SnapshotDiffService` helper.
- `HealthProbe/Models/AnomalyRecord.swift`,
  `HealthProbe/Models/AnomalyType.swift`, and
  `HealthProbe/Services/AnomalyDetector.swift` were deleted. The app no longer
  writes count-drop anomaly rows or shows the old Dashboard anomaly review
  section.

## Next Recommended Slices

1. Stop writing prototype `HealthSnapshot` bridge rows during capture now that
   Dashboard review state no longer stores those models.
2. Remove `HealthSnapshot`/`TypeCount` from the remaining service-side bridge
   flow and then delete the launch `ModelContainer`.
