# antiwork/exemplar architecture

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

- Interactive diagram: https://gitdiagram.com/antiwork/exemplar
- Repository: https://github.com/antiwork/exemplar

## Overview

##### Main Components
- Container Applications: There are separate targets for iOS (App and Extension) and macOS (App and Extension). They serve dual purposes:
- The App targets provide the host environment (with AppDelegate, Storyboards, etc.) and may handle overall configuration, API key management, and launching of the extension.
- The Extension targets (including files like SafariWebExtensionHandler.swift, Info.plist in the Extension directories) implement the actual browser extension functionality.
- Shared Resources:
- “Shared (App)” contains assets, user interface elements (HTML, CSS, JavaScript) that define the layout and design—the “look and feel” shared across platforms.
- “Shared (Extension)” comprises web extension-specific scripts (background.js, content.js, popup files) and localization files, alongside the manifest.json which is critical for defining extension behavior.
- External Services:
- The README mentions requiring an Anthropic API key; this indicates integration with an external API to generate anonymized data.

##### Component Relationships and Data Flow
- The User Interaction Flow:
- The extension loads its user interface (the popup) and embedded scripts (from Shared (Extension)): background, content, and popup scripts enable communication with the web page.
- Data Handling:
- The script components (in Shared (Extension)) analyze web page content, detect sensitive information, and call on an anonymization mechanism (potentially via the Anthropic API) to replace real data with placeholder values.
- Integration with the Container App:
- The container app component (within the iOS and macOS App directories) likely facilitates setup, API key entry, and configuration, ensuring the extension has the necessary credentials and settings.

##### Architectural Patterns and Design Principles
- Multi-Target Architecture: The project is structured to support multiple platforms (iOS and macOS) with shared logic and assets. Reusable shared code (in Shared (App) and Shared (Extension)) minimizes duplication.
- Separation of Concerns: UI components, business logic (the anonymization routines), and extension-specific scripts are clearly separated. Assets and localization files are distinct.
- Clear Extension Integration: The manifest.json and WebExtensionHandler files illustrate adherence to browser extension guidelines, emphasizing modularity between the host container and the extension logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User Interaction"]:::user

    subgraph "Container Applications"
        iOSApp["iOS Container App"]:::container
        macOSApp["macOS Container App"]:::container
    end

    subgraph "Extension Modules"
        iOSExt["iOS Extension"]:::extension
        macOSExt["macOS Extension"]:::extension
    end

    sharedUI["Shared UI/Asset Resources"]:::shared
    sharedExt["Shared Extension Scripts & Resources"]:::shared
    API["Anthropic API"]:::external

    %% User triggers container apps
    User --> iOSApp
    User --> macOSApp

    %% Container Apps pass configuration to their extensions
    iOSApp -->|"providesConfig"| iOSExt
    macOSApp -->|"providesConfig"| macOSExt

    %% Container Apps use shared UI resources
    iOSApp -->|"uses"| sharedUI
    macOSApp -->|"uses"| sharedUI

    %% Extension modules use shared extension resources
    iOSExt -->|"uses"| sharedExt
    macOSExt -->|"uses"| sharedExt

    %% Extensions make external API calls for anonymization
    iOSExt -->|"calls"| API
    macOSExt -->|"calls"| API

    %% Click Events
    click iOSApp "https://github.com/antiwork/exemplar/tree/main/iOS (App)"
    click iOSExt "https://github.com/antiwork/exemplar/tree/main/iOS (Extension)"
    click macOSApp "https://github.com/antiwork/exemplar/tree/main/macOS (App)"
    click macOSExt "https://github.com/antiwork/exemplar/tree/main/macOS (Extension)"
    click sharedUI "https://github.com/antiwork/exemplar/tree/main/Shared (App)"
    click sharedExt "https://github.com/antiwork/exemplar/tree/main/Shared (Extension)"

    %% Styles
    classDef container fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef extension fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef shared fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#D5DBDB,stroke:#566573,stroke-width:2px;
    classDef user fill:#F5B7B1,stroke:#943126,stroke-width:2px;
```
