# pschkllr/flutter_true_time architecture

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

- Interactive diagram: https://gitdiagram.com/pschkllr/flutter_true_time
- Repository: https://github.com/pschkllr/flutter_true_time

## Overview

flutter_true_time is a Flutter package for network-derived UTC readings, with a Flutter-independent timing engine. The principal workflow is app initialization, source sampling and synchronization, anchoring timestamps to a monotonic clock, then returning readings with freshness and uncertainty evidence; optional persistence supports guarded offline restoration. The README documents platform-specific epoch evidence and browser endpoint requirements. Dart implementation excerpts were not supplied, so internal edges below are limited to documented relationships; the Android bootstrap behavior is directly visible in its excerpt.

Main entry points: [`lib/src/engine.dart`](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/engine.dart) (Sync engine), [`lib/src/facade.dart`](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/facade.dart) (TrueTime facade), [`lib/src/sources.dart`](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/sources.dart) (Time sources), [`lib/src/clock.dart`](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock.dart) (Monotonic clock)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_facade["TrueTime facade<br/>[facade.dart]"]
  node_flutter_api["Flutter exports"]
  node_core_api["Core exports<br/>[core.dart]"]
  node_models["Reading models<br/>[models.dart]"]
end

subgraph group_sync["Synchronization"]
  node_engine["Sync engine<br/>[engine.dart]"]
  node_sources["Time sources<br/>[sources.dart]"]
  node_provider_group["Provider grouping"]
  node_cancellation["Cancellation<br/>[cancellation.dart]"]
end

subgraph group_clock["Clock and state"]
  node_clock["Monotonic clock<br/>[clock.dart]"]
  node_clock_native["Native clock<br/>[clock_native.dart]"]
  node_clock_portable["Portable clock"]
  node_persistence["Anchor persistence<br/>[persistence.dart]"]
  node_secure_store["Secure storage<br/>[secure_store.dart]"]
  node_diagnostics["Diagnostics<br/>[diagnostics.dart]"]
end

subgraph group_platform["Platform adapters"]
  node_epoch["Platform epoch"]
  node_epoch_io["I/O epoch<br/>[epoch_io.dart]"]
  node_epoch_portable["Portable epoch"]
  node_ntp_io["Native NTP<br/>[ntp_io.dart]"]
  node_ntp_stub["NTP stub<br/>[ntp_stub.dart]"]
  node_dart_plugin["Dart plugin bridge"]
  node_web_plugin["Web plugin"]
  node_android_plugin["Android epoch bridge"]
end

node_app(("Flutter app"))
node_android_os[("Android boot metadata")]
node_ntp_servers(("Configured NTP servers"))
node_browser_endpoints(("HTTPS date endpoints"))

node_app -->|"initializes and reads"| node_facade
node_facade -->|"starts sync"| node_engine
node_facade -->|"waits for readiness"| node_engine
node_facade -->|"reads estimate"| node_engine
node_engine -.->|"samples sources"| node_sources
node_sources -->|"queries defaults"| node_ntp_servers
node_sources -->|"uses configured endpoints"| node_browser_endpoints
node_engine -->|"restores and saves anchors"| node_persistence
node_engine -->|"anchors timestamps"| node_clock
node_facade -.->|"exposes status"| node_diagnostics
node_engine -->|"cancels owned work"| node_cancellation
node_persistence -.->|"uses storage"| node_secure_store
node_clock -.->|"selects native clock"| node_clock_native
node_clock -.->|"selects portable clock"| node_clock_portable
node_epoch -.->|"uses I/O provider"| node_epoch_io
node_epoch -.->|"uses portable provider"| node_epoch_portable
node_engine -->|"checks epoch evidence"| node_epoch
node_android_plugin -->|"reads boot count; stores installation marker"| node_android_os
node_ntp_io -.->|"queries servers"| node_ntp_servers

click node_facade "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/facade.dart"
click node_flutter_api "https://github.com/pschkllr/flutter_true_time/blob/main/lib/flutter_true_time.dart"
click node_core_api "https://github.com/pschkllr/flutter_true_time/blob/main/lib/core.dart"
click node_models "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/models.dart"
click node_engine "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/engine.dart"
click node_sources "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/sources.dart"
click node_provider_group "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/provider_group.dart"
click node_cancellation "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/cancellation.dart"
click node_clock "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock.dart"
click node_clock_native "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock_native.dart"
click node_clock_portable "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock_portable.dart"
click node_persistence "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/persistence.dart"
click node_secure_store "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/secure_store.dart"
click node_diagnostics "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/diagnostics.dart"
click node_epoch "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/epoch_platform.dart"
click node_epoch_io "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/epoch_io.dart"
click node_epoch_portable "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/epoch_portable.dart"
click node_ntp_io "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/ntp_io.dart"
click node_ntp_stub "https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/ntp_stub.dart"
click node_dart_plugin "https://github.com/pschkllr/flutter_true_time/blob/main/lib/flutter_true_time_dart_plugin.dart"
click node_web_plugin "https://github.com/pschkllr/flutter_true_time/blob/main/lib/flutter_true_time_web.dart"
click node_android_plugin "https://github.com/pschkllr/flutter_true_time/blob/main/android/src/main/java/dev/pschkllr/flutter_true_time/FlutterTrueTimePlugin.java"

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_facade,node_flutter_api,node_core_api,node_models toneBlue
class node_engine,node_sources,node_provider_group,node_cancellation,node_android_os toneAmber
class node_clock,node_clock_native,node_clock_portable,node_persistence,node_secure_store,node_diagnostics,node_ntp_servers toneMint
class node_epoch,node_epoch_io,node_epoch_portable,node_ntp_io,node_ntp_stub,node_dart_plugin,node_web_plugin,node_android_plugin toneRose
class node_app,node_browser_endpoints toneIndigo
```

## Components

### Public API

- [TrueTime facade](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/facade.dart): `lib/src/facade.dart`
- [Flutter exports](https://github.com/pschkllr/flutter_true_time/blob/main/lib/flutter_true_time.dart): `lib/flutter_true_time.dart`
- [Core exports](https://github.com/pschkllr/flutter_true_time/blob/main/lib/core.dart): `lib/core.dart`
- [Reading models](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/models.dart): `lib/src/models.dart`

### Synchronization

- [Sync engine](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/engine.dart): `lib/src/engine.dart`
- [Time sources](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/sources.dart): `lib/src/sources.dart`
- [Provider grouping](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/provider_group.dart): `lib/src/provider_group.dart`
- [Cancellation](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/cancellation.dart): `lib/src/cancellation.dart`

### Clock and state

- [Monotonic clock](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock.dart): `lib/src/clock.dart`
- [Native clock](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock_native.dart): `lib/src/clock_native.dart`
- [Portable clock](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/clock_portable.dart): `lib/src/clock_portable.dart`
- [Anchor persistence](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/persistence.dart): `lib/src/persistence.dart`
- [Secure storage](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/secure_store.dart): `lib/src/secure_store.dart`
- [Diagnostics](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/diagnostics.dart): `lib/src/diagnostics.dart`

### Platform adapters

- [Platform epoch](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/epoch_platform.dart): `lib/src/epoch_platform.dart`
- [I/O epoch](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/epoch_io.dart): `lib/src/epoch_io.dart`
- [Portable epoch](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/epoch_portable.dart): `lib/src/epoch_portable.dart`
- [Native NTP](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/ntp_io.dart): `lib/src/ntp_io.dart`
- [NTP stub](https://github.com/pschkllr/flutter_true_time/blob/main/lib/src/ntp_stub.dart): `lib/src/ntp_stub.dart`
- [Dart plugin bridge](https://github.com/pschkllr/flutter_true_time/blob/main/lib/flutter_true_time_dart_plugin.dart): `lib/flutter_true_time_dart_plugin.dart`
- [Web plugin](https://github.com/pschkllr/flutter_true_time/blob/main/lib/flutter_true_time_web.dart): `lib/flutter_true_time_web.dart`
- [Android epoch bridge](https://github.com/pschkllr/flutter_true_time/blob/main/android/src/main/java/dev/pschkllr/flutter_true_time/FlutterTrueTimePlugin.java): `android/src/main/java/dev/pschkllr/flutter_true_time/FlutterTrueTimePlugin.java`

### Other components

- **Flutter app**
- **Android boot metadata**
- **Configured NTP servers**
- **HTTPS date endpoints**

## Connections

- Flutter app → TrueTime facade: initializes and reads (evidence: `README.md`)
- TrueTime facade → Sync engine: starts sync (evidence: `README.md`)
- TrueTime facade → Sync engine: waits for readiness (evidence: `README.md`)
- TrueTime facade → Sync engine: reads estimate (evidence: `README.md`)
- Sync engine → Time sources: samples sources
- Time sources → Configured NTP servers: queries defaults (evidence: `README.md`)
- Time sources → HTTPS date endpoints: uses configured endpoints (evidence: `README.md`)
- Sync engine → Anchor persistence: restores and saves anchors (evidence: `README.md`)
- Sync engine → Monotonic clock: anchors timestamps (evidence: `README.md`)
- TrueTime facade → Diagnostics: exposes status
- Sync engine → Cancellation: cancels owned work (evidence: `README.md`)
- Anchor persistence → Secure storage: uses storage
- Monotonic clock → Native clock: selects native clock
- Monotonic clock → Portable clock: selects portable clock
- Platform epoch → I/O epoch: uses I/O provider
- Platform epoch → Portable epoch: uses portable provider
- Sync engine → Platform epoch: checks epoch evidence (evidence: `README.md`)
- Android epoch bridge → Android boot metadata: reads boot count; stores installation marker (evidence: `android/src/main/java/dev/pschkllr/flutter_true_time/FlutterTrueTimePlugin.java`)
- Native NTP → Configured NTP servers: queries servers
