# unknsn/childgaurd architecture

> Architecture diagram of the GitHub repository unknsn/childgaurd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unknsn/childgaurd
- Repository: https://github.com/unknsn/childgaurd

## Overview

SafeBand is an offline-first Android child-safety app. In the documented workflow, child SOS, motion, and location inputs feed on-device risk assessment and ViewModel orchestration; the child device broadcasts alerts over BLE, and the parent device receives them for a safety dashboard and emergency actions. The app also covers safe-zone configuration, incident history, trusted contacts, and local persistence. The source excerpts contain no runtime code, so relationships below rely on README documentation; unsampled implementation details are not inferred.

Main entry points: [`app/src/main/java/com/example/ui/SafeBandViewModel.kt`](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/SafeBandViewModel.kt) (State orchestration), [`app/src/main/java/com/example/service/BleSafetyManager.kt`](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/BleSafetyManager.kt) (BLE safety manager), [`app/src/main/java/com/example/engine/RiskEngine.kt`](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/engine/RiskEngine.kt) (Risk engine), [`app/src/main/java/com/example/data/repository/SafetyRepository.kt`](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/repository/SafetyRepository.kt) (Safety repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Safety Inputs"]
  node_motion{{"Motion sensor"}}
  node_location{{"Location provider"}}
  node_sos["Manual SOS<br/>[ChildHomeScreen.kt]"]
end

subgraph group_core["On-Device Safety"]
  node_detector["Motion detector"]
  node_locationhelper["Location safety"]
  node_risk["Risk engine<br/>[RiskEngine.kt]"]
  node_viewmodel["State orchestration"]
  node_models["Safety models<br/>[SafetyModels.kt]"]
end

subgraph group_peer["Peer Alerts"]
  node_ble["BLE safety manager"]
  node_notifier["Alert notifier<br/>[AlertNotifier.kt]"]
  node_address["Address resolver"]
end

subgraph group_experience["App Experience"]
  node_childscreen["Child dashboard<br/>[ChildHomeScreen.kt]"]
  node_parentscreen["Parent dashboard"]
  node_zone["Safe-zone setup"]
  node_history["Alert history"]
  node_contacts["Trusted contacts"]
end

subgraph group_storage["Local Data"]
  node_repository["Safety repository"]
  node_room[("Room database")]
  node_preferences[("Encrypted preferences")]
end

node_child(("Child user"))
node_parent(("Parent user"))

node_motion -->|"senses motion"| node_detector
node_location -->|"provides location"| node_locationhelper
node_detector -->|"assesses anomaly"| node_risk
node_locationhelper -->|"assesses geofence"| node_risk
node_sos -->|"triggers emergency"| node_risk
node_risk -->|"updates state"| node_viewmodel
node_viewmodel -->|"broadcasts alert"| node_ble
node_ble -.->|"beacons to peer"| node_ble
node_ble -->|"delivers beacon"| node_viewmodel
node_viewmodel -->|"drives dashboard"| node_childscreen
node_viewmodel -->|"drives dashboard"| node_parentscreen
node_viewmodel -.->|"supports safe zones"| node_zone
node_viewmodel -.->|"supports history"| node_history
node_viewmodel -.->|"supports contacts"| node_contacts
node_parentscreen -.->|"shows alerts"| node_notifier
node_viewmodel -.->|"resolves coordinates"| node_address
node_viewmodel -.->|"persists safety data"| node_repository
node_repository -.->|"stores event data"| node_room
node_repository -.->|"stores preferences"| node_preferences
node_child -.->|"uses"| node_childscreen
node_parent -.->|"uses"| node_parentscreen

click node_sos "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/ChildHomeScreen.kt"
click node_detector "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/MotionAnomalyDetector.kt"
click node_locationhelper "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/LocationSafetyHelper.kt"
click node_risk "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/engine/RiskEngine.kt"
click node_viewmodel "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/SafeBandViewModel.kt"
click node_ble "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/BleSafetyManager.kt"
click node_notifier "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/AlertNotifier.kt"
click node_address "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/LocationAddressResolver.kt"
click node_childscreen "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/ChildHomeScreen.kt"
click node_parentscreen "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/ParentHomeScreen.kt"
click node_zone "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/SafeZoneConfigScreen.kt"
click node_history "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/AlertHistoryScreen.kt"
click node_contacts "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/TrustedContactsScreen.kt"
click node_repository "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/repository/SafetyRepository.kt"
click node_room "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/local/SafeBandDatabase.kt"
click node_preferences "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/preferences/SafeBandPreferences.kt"
click node_models "https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/model/SafetyModels.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_motion,node_location,node_sos,node_child,node_parent toneBlue
class node_detector,node_locationhelper,node_risk,node_viewmodel,node_models toneAmber
class node_ble,node_notifier,node_address toneMint
class node_childscreen,node_parentscreen,node_zone,node_history,node_contacts toneRose
class node_repository,node_room,node_preferences toneIndigo
```

## Components

### Safety Inputs

- **Motion sensor**
- **Location provider**
- [Manual SOS](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/ChildHomeScreen.kt): `app/src/main/java/com/example/ui/screens/ChildHomeScreen.kt`

### On-Device Safety

- [Motion detector](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/MotionAnomalyDetector.kt): `app/src/main/java/com/example/service/MotionAnomalyDetector.kt`
- [Location safety](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/LocationSafetyHelper.kt): `app/src/main/java/com/example/service/LocationSafetyHelper.kt`
- [Risk engine](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/engine/RiskEngine.kt): `app/src/main/java/com/example/engine/RiskEngine.kt`
- [State orchestration](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/SafeBandViewModel.kt): `app/src/main/java/com/example/ui/SafeBandViewModel.kt`
- [Safety models](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/model/SafetyModels.kt): `app/src/main/java/com/example/model/SafetyModels.kt`

### Peer Alerts

- [BLE safety manager](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/BleSafetyManager.kt): `app/src/main/java/com/example/service/BleSafetyManager.kt`
- [Alert notifier](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/AlertNotifier.kt): `app/src/main/java/com/example/service/AlertNotifier.kt`
- [Address resolver](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/service/LocationAddressResolver.kt): `app/src/main/java/com/example/service/LocationAddressResolver.kt`

### App Experience

- [Child dashboard](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/ChildHomeScreen.kt): `app/src/main/java/com/example/ui/screens/ChildHomeScreen.kt`
- [Parent dashboard](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/ParentHomeScreen.kt): `app/src/main/java/com/example/ui/screens/ParentHomeScreen.kt`
- [Safe-zone setup](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/SafeZoneConfigScreen.kt): `app/src/main/java/com/example/ui/screens/SafeZoneConfigScreen.kt`
- [Alert history](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/AlertHistoryScreen.kt): `app/src/main/java/com/example/ui/screens/AlertHistoryScreen.kt`
- [Trusted contacts](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/ui/screens/TrustedContactsScreen.kt): `app/src/main/java/com/example/ui/screens/TrustedContactsScreen.kt`

### Local Data

- [Safety repository](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/repository/SafetyRepository.kt): `app/src/main/java/com/example/data/repository/SafetyRepository.kt`
- [Room database](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/local/SafeBandDatabase.kt): `app/src/main/java/com/example/data/local/SafeBandDatabase.kt`
- [Encrypted preferences](https://github.com/unknsn/childgaurd/blob/main/app/src/main/java/com/example/data/preferences/SafeBandPreferences.kt): `app/src/main/java/com/example/data/preferences/SafeBandPreferences.kt`

### Other components

- **Child user**
- **Parent user**

## Connections

- Motion sensor → Motion detector: senses motion (evidence: `README.md`)
- Location provider → Location safety: provides location (evidence: `README.md`)
- Motion detector → Risk engine: assesses anomaly (evidence: `README.md`)
- Location safety → Risk engine: assesses geofence (evidence: `README.md`)
- Manual SOS → Risk engine: triggers emergency (evidence: `README.md`)
- Risk engine → State orchestration: updates state (evidence: `README.md`)
- State orchestration → BLE safety manager: broadcasts alert (evidence: `README.md`)
- BLE safety manager → BLE safety manager: beacons to peer (evidence: `README.md`)
- BLE safety manager → State orchestration: delivers beacon (evidence: `README.md`)
- State orchestration → Child dashboard: drives dashboard (evidence: `README.md`)
- State orchestration → Parent dashboard: drives dashboard (evidence: `README.md`)
- State orchestration → Safe-zone setup: supports safe zones (evidence: `README.md`)
- State orchestration → Alert history: supports history (evidence: `README.md`)
- State orchestration → Trusted contacts: supports contacts (evidence: `README.md`)
- Parent dashboard → Alert notifier: shows alerts (evidence: `README.md`)
- State orchestration → Address resolver: resolves coordinates (evidence: `README.md`)
- State orchestration → Safety repository: persists safety data (evidence: `README.md`)
- Safety repository → Room database: stores event data (evidence: `README.md`)
- Safety repository → Encrypted preferences: stores preferences (evidence: `README.md`)
- Child user → Child dashboard: uses
- Parent user → Parent dashboard: uses
