# sentryco/telemetric architecture

> Architecture diagram of the GitHub repository sentryco/telemetric, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sentryco/telemetric
- Repository: https://github.com/sentryco/telemetric

## Overview

##### Main Components

a) Client Application Layer:
- IOS/macOS app integration point
- Main Telemetric interface class
- Event Collector mechanism

b) Core Components:
- Tracker System
- Event Processing
- Identity Management
- Storage & Caching

c) External Systems:
- Google Analytics 4 (GA4) Backend
- Measurement Protocol API

##### Specific Implementation Details

**┌─ Application Layer ─────────────────────┐**

- iOS/macOS Client App                  │

- ┤

- Telemetric Interface                  │
- (TelemetricKind Protocol)            │

- ┤

- Event Management                      │
- ┌─────────────┐    ┌──────────────┐  │
- Event     │    │    Event     │  │
- Collector  │◄───│   Builder    │  │
- ┘    └──────────────┘  │

- ┤

- Core Services                         │
- ┌─────────────┐    ┌──────────────┐  │
- Tracker   │    │   Identity   │  │
- Service   │    │   Manager    │  │
- ┘    └──────────────┘  │

- ┌─────────────┐    ┌──────────────┐  │
- Timing    │    │   System     │  │
- Tracker   │    │   Utils      │  │
- ┘    └──────────────┘  │

- ┤

- Storage Layer                         │
- ┌─────────────┐    ┌──────────────┐  │
- Keychain   │    │ UserDefaults │  │
- Storage   │    │   Storage    │  │
- ┘    └──────────────┘  │

- ┘

- ▼
**┌─ External Services ──────────────────────┐**

- Google Analytics 4 (GA4)               │
- Measurement Protocol API            │

- ┘

##### Important Flows to Highlight

a) Event Flow:
- Event creation
- Batch collection
- Processing
- Transmission to GA4

b) Identity Management Flow:
- Three-tier identity storage (vendor, userDefault, keychain)
- Client ID generation
- Persistence management

##### Key Technical Details to Note

- Batch processing limits (25 events per request)
- Payload size limits (130kB)
- Data persistence options
- Timing tracking mechanisms

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        ClientApp["iOS/macOS Client App"]
        TelemetricInterface["Telemetric Interface"]:::interface
    end

    subgraph "Event Management"
        EventCollector["Event Collector"]:::core
        EventBuilder["Event Builder"]:::core
        EventDefinition["Event Definition"]:::core
        PayloadHandler["Payload Handler"]:::core
    end

    subgraph "Core Services"
        TrackerService["Tracker Service"]:::core
        IdentityManager["Identity Manager"]:::core
        TimingTracker["Timing Tracker"]:::core
        SystemUtils["System Utils"]:::core
    end

    subgraph "Storage Layer"
        KeychainStorage["Keychain Storage"]:::storage
        UserDefaultsStorage["UserDefaults Storage"]:::storage
    end

    subgraph "External Services"
        GA4["Google Analytics 4"]:::external
        MeasurementAPI["Measurement Protocol API"]:::external
    end

    %% Connections
    ClientApp --> TelemetricInterface
    TelemetricInterface --> EventCollector
    EventCollector --> EventBuilder
    EventBuilder --> EventDefinition
    EventDefinition --> PayloadHandler
    PayloadHandler --> TrackerService
    TrackerService --> IdentityManager
    TrackerService --> TimingTracker
    TrackerService --> SystemUtils
    IdentityManager --> KeychainStorage
    IdentityManager --> UserDefaultsStorage
    TrackerService --> MeasurementAPI
    MeasurementAPI --> GA4

    %% Click Events
    click TelemetricInterface "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/protocol/TelemetricKind.swift"
    click EventCollector "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/util/EventCollector.swift"
    click EventDefinition "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/Event.swift"
    click PayloadHandler "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/Payload.swift"
    click TrackerService "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/Tracker.swift"
    click IdentityManager "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/util/Identity.swift"
    click TimingTracker "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/util/TimingTracker.swift"
    click SystemUtils "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/util/System.swift"
    click KeychainStorage "https://github.com/sentryco/telemetric/blob/main/Sources/Telemetric/ext/Keychain.swift"

    %% Styles
    classDef core fill:#a2d2ff,stroke:#333,stroke-width:2px
    classDef storage fill:#caffbf,stroke:#333,stroke-width:2px
    classDef external fill:#ffd6a5,stroke:#333,stroke-width:2px
    classDef interface fill:#bdb2ff,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Storage Component"]:::storage
        L3["External Service"]:::external
        L4["Interface Layer"]:::interface
    end
```
