# HealthProbe iOS – Specification (MVP)

## Overview
HealthProbe is an iOS application designed to **audit and monitor the integrity of HealthKit data**.  
It detects anomalies such as:
- unexpected historical insertions
- silent deletions of past data
- duplicate records
- divergence trends over time

The application operates as a **local audit and capture agent**. It does not sync HealthProbe data via CloudKit/iCloud; HealthKit databases can evolve differently per device, so the MVP keeps each device archive local and explicit.

⚠️ This document describes ONLY the iOS application (MVP phase).  
A future macOS application will act as a visualization/analysis layer.

---

## Core Principles

1. **Read-only with respect to HealthKit**
   - Never modify or delete HealthKit data
   - Only observe and audit

2. **Local-first architecture**
   - All detection must work without network access

3. **Incremental observation**
   - Use anchored queries to track changes

4. **No app cloud sync**
   - HealthProbe does not sync raw samples, digests, or reports through CloudKit/iCloud

5. **Robust local archive**
   - Store captured HealthKit data in one local archive store, not per-data-type silos
   - SwiftData is used for derived UI data, settings, logs, and history only

---

## Features (MVP)

### 1. HealthKit Monitoring
Use:
- `HKAnchoredObjectQuery`
- `HKObserverQuery`

Track:
- Workouts (`HKWorkoutType`)
- Heart Rate (`HKQuantityTypeIdentifierHeartRate`)
- High Heart Rate Events
- Other relevant samples (extensible)

Persist:
- sample values and units
- source and source revision metadata
- device metadata exposed by HealthKit
- HealthKit metadata dictionaries
- first-seen / last-seen / last-verified timestamps
- fingerprints for matching against Apple Health XML exports and backup database extracts

---

### 2. Anomaly Detection

#### A. Historical Insertions
Detect samples where:
- `startDate << now`
- AND `firstSeenAt ≈ now`

#### B. Deletions
Detect via:
- `HKDeletedObject`
- Compare with previously stored snapshot

#### C. Duplicate Detection
Fingerprint:
