# sentryco/crashkit architecture

> Architecture diagram of the GitHub repository sentryco/crashkit, 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/crashkit
- Repository: https://github.com/sentryco/crashkit

## Overview

##### Main Components

a) Core Components:
- Crash Detection System
- Crash Log Management
- Sanitization Engine
- Network Communication Layer

b) External Integration Points:
- Host Application
- Custom Analytics Endpoint (e.g., GA4)
- File System Storage

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

- iOS/macOS App (SwiftUI)                        │

- ┬───────────────────────────┤

- CrashKit Core       │  Crash Detection Layer    │
- ┌─────────────────┐ │  ┌────────────────────┐  │
- Crashlytic    │ │  │   CrashHandler     │  │
- (Shared)     │ │  │   - Exception      │  │
- ┬────────┘ │  │   - Signal         │  │
- ┘  │
- ▼          │                           │
- ┌─────────────────┐ │  Sanitization Layer      │
- Crash Logger   │ │  ┌────────────────────┐  │
- ┬────────┘ │  │    Sanitizer       │  │
- Custom Rules    │  │
- ▼          │  └────────────────────┘  │
- ┌─────────────────┐ │                           │
- File Manager   │ │                           │
- ┬────────┘ │                           │

- ┼──────────┴───────────────────────────┘

- ▼
**┌─────────────────────┐    ┌─────────────────────┐**
- Local Storage     │    │  Analytics Endpoint  │
- (Crash Log Files)  │───▶│    (e.g., GA4)      │
- ┘    └─────────────────────┘

##### Important Relationships to Highlight

a) Data Flow:
- Crash Detection → Crash Logger
- Crash Logger → File Manager
- File Manager → Local Storage
- Local Storage → Analytics Endpoint

b) Dependencies:
- Crashlytic shared instance relationship with CrashHandler
- Sanitizer integration with Crash Logger
- FileManager extensions for storage operations

##### Implementation Details

- Signal handler implementation
- Exception handler implementation
- File system interaction points
- Sanitization pipeline
- Network communication pattern

##### Notes Section

Important notes about:
- Privacy considerations
- Initialization requirements
- Platform-specific behaviors
- Testing considerations

Remember to emphasize the modular nature of the system, particularly how it allows for custom sanitization rules and different analytics endpoints, as these are key differentiating features of the project.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Host["Host Application Layer"]
        App["iOS/macOS App (SwiftUI)"]:::host
    end

    subgraph Core["CrashKit Core"]
        CrashHandler["Crash Handler"]:::core
        Sanitizer["Sanitizer"]:::core
        FileManager["File Manager"]:::core
    end

    subgraph Integration["Integration Layer"]
        Crashlytic["Crashlytic (Shared)"]:::integration
        Callbacks["Custom Callbacks"]:::integration
        Network["Network Transport"]:::integration
    end

    subgraph External["External Services"]
        Services["GA4/Telemetric"]:::external
    end

    %% Connections
    App --> Crashlytic
    Crashlytic --> CrashHandler
    CrashHandler --> Sanitizer
    Sanitizer --> FileManager
    Crashlytic --> Callbacks
    Callbacks --> Network
    Network --> Services

    %% Click Events
    click CrashHandler "https://github.com/sentryco/crashkit/blob/main/Sources/CrashKit/util/CrashHandler.swift"
    click Sanitizer "https://github.com/sentryco/crashkit/blob/main/Sources/CrashKit/util/Sanitizer.swift"
    click FileManager "https://github.com/sentryco/crashkit/blob/main/Sources/CrashKit/ext/FileManager+Ext.swift"
    click Crashlytic "https://github.com/sentryco/crashkit/blob/main/Sources/CrashKit/Crashlytic.swift"
    click App "https://github.com/sentryco/crashkit/blob/main/ExampleDemo/ExampleDemo/ExampleDemo.swift"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#2980b9,stroke-width:2px
    classDef integration fill:#b8e994,stroke:#27ae60,stroke-width:2px
    classDef external fill:#f8c291,stroke:#e67e22,stroke-width:2px
    classDef host fill:#d1d8e0,stroke:#2c3e50,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Integration Points"]:::integration
        L3["External Services"]:::external
        L4["Host Application"]:::host
    end
```
