# bpluta/keyrmes architecture

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

- Interactive diagram: https://gitdiagram.com/bpluta/keyrmes
- Repository: https://github.com/bpluta/keyrmes

## Overview

- API Layer – Represented by the KeychainStore and high-level API objects (found in Sources/Keyrmes). This is the primary interface for end users.
- Query Builder – Located in Sources/Keyrmes/Query; this module constructs and configures the low-level keychain queries.
- Serialization & Type Conversion – Shown in the Sources/Keyrmes/Serialization (as well as Extensions and Serialization modules). This component handles automatic encoding/decoding of Swift types.
- Macros – Found under Sources/Macros and Sources/KeyrmesMacros; these modules reduce boilerplate by providing compiler-based code generation and default behaviors.
- Build Plugin & Code Generation – Represented by the KeychainKeysBuilder package in its own folder (and the Binaries directory with the pre-built artifact bundle) along with the Plugins/KeychainConstantsExtractor. This part integrates with Swift’s build process (relying on swift-syntax) to extract and generate code from Apple’s Security.framework headers.
- Test & Example Projects – The Example folder and Tests directory demonstrate usage and verify proper functionality. They are important to understand how the library integrates with client applications.

##### Out the Relationships and Data Flow
▪ The Query Builder – for assembling keychain queries.
▪ The Serialization module – for handling type-safe conversion between Swift types and keychain data representations.
▪ The Macros layer – which provides compile-time code generation support.

##### Architectural Patterns and Technologies
- Use a layered architecture: the library is clearly divided into a front-facing API layer, internal service layers (query building and serialization), and a build-time code generation plugin.
- Use of modern Swift features including concurrency (async/await), macros, and the Swift Package Manager. This indicates that the project is built with a focus on type safety and modern API design.
- That the integration of the compiler plugin (KeychainKeysBuilder) makes use of external tools (swift-syntax) and pre-built binary artifacts to keep the API aligned with Apple’s evolving keychain constants.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Test & Example Projects"]:::test
    B["KeychainStore API"]:::api
    C["Query Builder"]:::module
    D["Serialization & Type Conversion"]:::module
    E["Macros"]:::module
    F["Build Plugin & Code Generation"]:::plugin
    G["Apple Keychain Services (Security.framework)"]:::external

    A -->|"calls"| B
    B -->|"uses"| C
    B -->|"uses"| D
    B -->|"uses"| E
    F -->|"build-time_integration"| B
    B -->|"executes"| G

    click B "https://github.com/bpluta/keyrmes/blob/main/Sources/Keyrmes/KeychainStore.swift"
    click C "https://github.com/bpluta/keyrmes/tree/main/Sources/Keyrmes/Query"
    click D "https://github.com/bpluta/keyrmes/tree/main/Sources/Keyrmes/Serialization"
    click E "https://github.com/bpluta/keyrmes/tree/main/Sources/Macros"
    click E "https://github.com/bpluta/keyrmes/tree/main/Sources/KeyrmesMacros"
    click F "https://github.com/bpluta/keyrmes/tree/main/KeychainKeysBuilder"
    click F "https://github.com/bpluta/keyrmes/blob/main/Binaries/KeychainKeysBuilder.artifactbundle"
    click F "https://github.com/bpluta/keyrmes/tree/main/Plugins/KeychainConstantsExtractor"
    click A "https://github.com/bpluta/keyrmes/tree/main/Example"
    click A "https://github.com/bpluta/keyrmes/tree/main/Tests"

    classDef api fill:#b3d9ff,stroke:#003366,stroke-width:2px;
    classDef module fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef plugin fill:#ffd699,stroke:#cc6600,stroke-width:2px;
    classDef test fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef external fill:#e6e6e6,stroke:#666666,stroke-width:2px;
```
