# thepearl/echo architecture

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

- Interactive diagram: https://gitdiagram.com/thepearl/echo
- Repository: https://github.com/thepearl/echo

## Overview

##### Project type and purpose
- This is a Swift logging framework (Swift Package) named “Echo,” accompanied by an iOS example app (EchoExample).
- Purpose: provide a flexible, thread-safe logging core, optional persistent storage (in-memory, file system, Core Data), a built-in SwiftUI/ UIKit log viewer, and log export capabilities for iOS apps.

##### File structure
- Top level:
–  .github/workflows/swift.yml → CI build/test
–  Package.swift → SwiftPM package definition
–  Sources/Echo → core framework code (Logger, LogViewer, persistence strategies, data model)
–  Sources/Resources/EchoDataModel.xcdatamodeld → Core Data model
–  EchoExample/… → Xcode project for the demo app
–  Tests/EchoTests → unit tests for the framework
- Patterns & modules:
–  Core Logging module (Logger + configuration + persistence strategies via Strategy pattern)
–  UI module (SwiftUI’s LogViewer, UIKit integration helpers)
–  Resources module (Core Data model)
–  Example app module demonstrating integration

##### Extract architecture hints from README
- Core components: Logger, LoggerConfiguration, PersistenceStrategy (.inMemory, .fileSystem, .coreData)
- UI: SwiftUI LogViewer, UIKit view controllers, export API via UIActivityViewController
- Features: log rotation, filtering, search, crash capture, thread-safety

a.  Client App (EchoExample)
– SwiftUI Views & UIKit ViewControllers
– EnvironmentObject / injected Echo.Logger
b.  Logging Core
– Logger API
– LoggerConfiguration
– LogEntry model
c.  Persistence Layer (Strategy)
– InMemoryStore
– FileSystemStore
– CoreDataStore (uses EchoDataModel.xcdatamodeld)
d.  Log Viewer (UI)
– SwiftUI LogViewer component
– UIKit wrappers
e.  Exporter
– Logger.exportLogs() → String
– UIActivityViewController
f.  CI/CD & Packaging
– SwiftPM → builds Sources/Echo into a library
– Xcode workspace (EchoExample + package)
– GitHub Actions (swift.yml)

1. App code → Logger.log(level, category, message)
2. Logger → applies configuration (level filter, rotation)
3. Logger → PersistenceStrategy.store(entry)
4. PersistenceStrategy → writes to memory / file / Core Data
5. LogViewer subscribes to Logger’s data publisher → read entries from store
6. User taps “Export” → Logger.exportLogs() → UIActivityViewController

##### Architectural patterns & design principles
- Strategy pattern for persistence (swap .inMemory/.fileSystem/.coreData)
- Observer / Publisher–Subscriber (Combine) for real-time UI updates
- MVVM for SwiftUI LogViewer (View ←→ Logger ViewModel)
- Separation of concerns: core logging vs UI vs persistence vs export
- Thread-safe operations (serial queue or locks inside Logger)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client App
    subgraph "Example App" 
        direction TB
        AppEntry["EchoExampleApp (App Entry)"]:::ui
        ContentView["ContentView (LogViewer Demo)"]:::ui
    end
    click AppEntry "https://github.com/thepearl/echo/blob/master/EchoExample/EchoExample/EchoExampleApp.swift"
    click ContentView "https://github.com/thepearl/echo/blob/master/EchoExample/EchoExample/ContentView.swift"
    subgraph "Example App Module" 
        ExampleApp["EchoExample Module"]:::ui
    end
    click ExampleApp "https://github.com/thepearl/echo/tree/master/EchoExample/EchoExample"

    %% Core Library
    LoggingCore["Logging Core\n(Logger + Configuration + PersistenceStrategy)"]:::core
    click LoggingCore "https://github.com/thepearl/echo/blob/master/Sources/Echo/Echo.swift"

    %% Persistence Strategies
    subgraph "Persistence Strategies" 
        direction TB
        InMemory[(InMemory Store)]:::persistence
        FileSystem[(FileSystem Store)]:::persistence
        CoreDataStore[(CoreData Store)]:::persistence
    end
    click InMemory "https://github.com/thepearl/echo/blob/master/Sources/Echo/Echo.swift"
    click FileSystem "https://github.com/thepearl/echo/blob/master/Sources/Echo/Echo.swift"
    click CoreDataStore "https://github.com/thepearl/echo/blob/master/Sources/Echo/Echo.swift"

    %% Core Data Model
    CoreDataModel[(EchoDataModel.xcdatamodeld)]:::external
    click CoreDataModel "https://github.com/thepearl/echo/blob/master/Sources/Resources/EchoDataModel.xcdatamodeld"

    %% Log Viewer & Exporter
    LogViewer["SwiftUI LogViewer\n& UIKit Wrappers"]:::ui
    click LogViewer "https://github.com/thepearl/echo/blob/master/Sources/Echo/LogViewer.swift"
    Exporter["Exporter (exportLogs())"]:::core
    UIActivityVC["UIActivityViewController"]:::external

    %% CI/CD and Packaging
    subgraph "CI/CD & Packaging"
        direction TB
        Package["Package.swift"]:::external
        CI["GitHub Actions\n(.github/workflows/swift.yml)"]:::external
        Tests["Unit Tests\n(EchoTests.swift)"]:::external
    end
    click Package "https://github.com/thepearl/echo/blob/master/Package.swift"
    click CI "https://github.com/thepearl/echo/blob/master/.github/workflows/swift.yml"
    click Tests "https://github.com/thepearl/echo/blob/master/Tests/EchoTests/EchoTests.swift"

    %% Connections
    ExampleApp -->|"inject Echo.Logger"| LoggingCore
    AppEntry -->|"uses Logger.log() call"| LoggingCore
    ContentView -->|"calls log()"| LoggingCore
    LoggingCore -->|"store(entry)"| InMemory
    LoggingCore -->|"store(entry)"| FileSystem
    LoggingCore -->|"store(entry)"| CoreDataStore
    CoreDataStore -->|"uses model"| CoreDataModel
    LoggingCore -->|".publisher updates"| LogViewer
    LogViewer -->|"trigger export"| Exporter
    Exporter -->|"present"| UIActivityVC

    %% CI/CD flows
    Package --> CI
    CI --> Tests

    %% Styles
    classDef core fill:#DDEBF7,stroke:#2F75B5,color:#000;
    classDef persistence fill:#FDE9D9,stroke:#C0504D,color:#000;
    classDef ui fill:#E2EFDA,stroke:#38761D,color:#000;
    classDef external fill:#FCE4D6,stroke:#7F6000,color:#000;
```
