# darktt/jsonprotection architecture

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

## Overview

##### Main Components Identification
- JSONProtection Library: This is the core of the project. It is implemented in the SourceCode/JsonProtection folder and includes all the key property wrappers (BoolProtection, MissingKeyProtection, NumberProtection, NumbersProtection, NumberArrayProtection, ObjectProtection, DateProtection, UIImageProtection, URLProtection, and AESDecoder).
- Client Application / Example App: The Xcode project (JsonDecodeProtection.xcodeproj) appears to be an example or demo app that shows how to use the JSONProtection library.
- Testing Suite: The JsonDecodeProtectionTests directory contains unit tests that validate the behavior of the various protection mechanisms.
- Package Management & CI/CD: The Package.swift and GitHub workflows indicate that this is also set up as a Swift Package and uses GitHub Actions for automation.

##### Analyzing the Architectural Layers
- Presentation/Client Layer: The iOS app components (AppDelegate.swift, SceneDelegate.swift, ViewController.swift, storyboards, and asset catalogs) are responsible for the UI and application lifecycle.
- Business Logic/Integration Layer: The domain models (declared in the app’s code with protection annotations) use the JSONProtection property wrappers to safely decode JSON. This layer effectively shows how the library is integrated into real-world usage.
- Core Library Layer: This is the SourceCode/JsonProtection directory where the core functionality lives. It encapsulates the logic to convert and validate JSON data (including AES decryption). It’s the heart of the protection mechanisms.
- Testing and Validation: The comprehensive tests in the Test directory ensure proper behavior, which reflects well on the design’s separation of concerns and correctness.
- Infrastructure/Deployment: The Package.swift file makes it a Swift Package Manager-compatible library, and the GitHub workflows under the .github folder indicate CI/CD automation.

##### Relationships and Interactions
- The core library components interact with the Swift Codable system, modifying the behavior when JSON decoding occurs.
- AESDecoder is used as a special case where, after decoding, additional decryption is performed. This can be shown as a branch or separate function within the library.
- Tests interact with each of these components to ensure they behave correctly when presented with both valid and problematic JSON.

##### Architectural Patterns / Design Principles
- Use of Swift’s Property Wrappers to encapsulate cross-cutting concerns (data type validations, conversions, key absence, and decryption).
- Separation of concerns: The core library focuses solely on JSON protection, while the demo app and tests demonstrate and verify its usage.
- Modular design: Packaging the functionality as a Swift Package encourages reusability and independent evolution.
- Integration of CI/CD practices shows an emphasis on automated testing and code quality.

- Demonstrate the application’s dependence on the JSONProtection library by showing how JSON payloads are sent to the decoding engine, which uses the property wrappers to ensure safe conversions.
- A separate branch for specialized functions (like AES decoding) to show where the logic diverges from standard JSON decoding.
- Finally, display the flow of validated data back into the client application and how tests are used to validate each interaction.

## Diagram (Mermaid)

```mermaid
flowchart TD
    ExternalData["External JSON Data"]:::external

    subgraph "Client (iOS App)"
        ClientApp["Client (iOS App)"]:::client
        AppDelegate["AppDelegate.swift"]:::client
        SceneDelegate["SceneDelegate.swift"]:::client
        ViewController["ViewController.swift"]:::client
    end

    subgraph "JSONProtection Core Library"
        subgraph "Property Wrappers"
            BoolProt["BoolProtection"]:::library
            NumberProt["NumberProtection"]:::library
            NumbersProt["NumbersProtection"]:::library
            NumberArrayProt["NumberArrayProtection"]:::library
            MissingKeyProt["MissingKeyProtection"]:::library
            DateProt["DateProtection"]:::library
            UIImageProt["UIImageProtection"]:::library
            URLProt["URLProtection"]:::library
        end
        AESDecoder["AESDecoder"]:::library
    end

    TestingSuite["Testing Suite"]:::test
    PackageManager["Swift Package Manager"]:::infra
    CICD["CI/CD"]:::infra

    %% Relationships
    ExternalData -->|"provides_JSON"| ClientApp
    ClientApp -->|"invokes_decoding"| CoreLibrary[JSONProtection Core Library]
    CoreLibrary -->|"returns_safe_data"| ClientApp
    TestingSuite -->|"validates"| CoreLibrary
    PackageManager -->|"manages"| CoreLibrary
    CICD -->|"automates"| CoreLibrary

    %% Also show internal relationship within Client (iOS App)
    ClientApp --> AppDelegate
    ClientApp --> SceneDelegate
    ClientApp --> ViewController

    %% Testing ties to specific core functionalities
    TestingSuite -->|"tests"| BoolProt
    TestingSuite -->|"tests"| NumberProt
    TestingSuite -->|"tests"| NumbersProt
    TestingSuite -->|"tests"| NumberArrayProt
    TestingSuite -->|"tests"| MissingKeyProt
    TestingSuite -->|"tests"| DateProt
    TestingSuite -->|"tests"| UIImageProt
    TestingSuite -->|"tests"| URLProt
    TestingSuite -->|"tests"| AESDecoder

    %% Click Events
    click CoreLibrary "https://github.com/darktt/jsonprotection/tree/main/SourceCode/JsonProtection"
    click BoolProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/BoolProtection.swift"
    click NumberProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/NumberProtection.swift"
    click NumbersProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/NumbersProtection.swift"
    click NumberArrayProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/NumberArrayProtection.swift"
    click MissingKeyProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/MissingKeyProtection.swift"
    click DateProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/DateProtection.swift"
    click UIImageProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/UIImageProtection.swift"
    click URLProt "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/URLProtection.swift"
    click AESDecoder "https://github.com/darktt/jsonprotection/blob/main/SourceCode/JsonProtection/AESDecoder.swift"
    click ClientApp "https://github.com/darktt/jsonprotection/blob/main/JsonDecodeProtection.xcodeproj"
    click AppDelegate "https://github.com/darktt/jsonprotection/blob/main/JsonDecodeProtection/AppDelegate.swift"
    click SceneDelegate "https://github.com/darktt/jsonprotection/blob/main/JsonDecodeProtection/SceneDelegate.swift"
    click ViewController "https://github.com/darktt/jsonprotection/blob/main/JsonDecodeProtection/ViewController.swift"
    click TestingSuite "https://github.com/darktt/jsonprotection/tree/main/JsonDecodeProtectionTests"
    click PackageManager "https://github.com/darktt/jsonprotection/blob/main/Package.swift"
    click CICD "https://github.com/darktt/jsonprotection/blob/main/.github/workflows/main.yml"

    %% Styles
    classDef external fill:#f5f5dc,stroke:#808000,stroke-width:2px;
    classDef client fill:#ffebcd,stroke:#d2691e,stroke-width:2px;
    classDef library fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef test fill:#98fb98,stroke:#228b22,stroke-width:2px;
    classDef infra fill:#ffe4e1,stroke:#ff1493,stroke-width:2px;
```
