# pointfreeco/swift-snapshot-testing architecture

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

- Interactive diagram: https://gitdiagram.com/pointfreeco/swift-snapshot-testing
- Repository: https://github.com/pointfreeco/swift-snapshot-testing

## Overview

##### Main Components
- SnapshotTesting Core Module: Represented by the “Sources/SnapshotTesting” directory. This module contains the heart of the snapshot testing functionality including strategies for image, text, data (e.g. JSON, plist) as well as diffing logic.
- InlineSnapshotTesting Module: Found under “Sources/InlineSnapshotTesting”. This module provides support for inline snapshots, which is an alternative assertion style.
- Documentation & Guides: Documentation is included as DocC files (see “Documentation.docc” in both modules) and related Articles. Although not part of runtime, they inform the design and usage.
- Test Suite: The “Tests” directory contains unit tests for both inline and standard snapshot testing functions, ensuring that each component behaves as expected.
- Build & CI Configuration: Files such as Package.swift, Makefile, and the GitHub workflows (in “.github/workflows”) indicate the project’s integration with CI/CD and its use as a Swift Package.
- Utility and Internal Helpers: Within “Sources/SnapshotTesting/Common” and “Sources/SnapshotTesting/Internal”, you find helper components—for diffing, encoding, and view handling. These support the core strategies and engine.

##### Relationships and Interactions
- The core SnapshotTesting module provides the main API (e.g. assertSnapshot, assertInlineSnapshot) that client test code calls.
- Diff logic sits as a helper component beneath the strategies, taking the recorded snapshot and comparing it to a new rendering.
- The InlineSnapshotTesting module works closely with the core testing API, adding specialized functionality to record inline assertions.
- The tests exercise all these components, ensuring that they function together. A separate “Tests” component should be drawn to illustrate testing flows.
- Build scripts and configuration files (e.g. Package.swift, Makefile) are external to the runtime modules but critical for building and continuous integration.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into distinct modules (SnapshotTesting and InlineSnapshotTesting) demonstrates clear modularization.
- Extensibility: The library supports dozens of snapshot strategies and allows users to add their own. Represent this by noting “custom strategies” or “extensibility” points that feed into the core snapshot engine.
- Testability: With a dedicated test suite and minimal configuration required, the design is test-driven.
- Decoupling: Helper utilities (e.g., diffing, encoders) are placed in subdirectories to support the main functionalities, ensuring that each part is focused and easier to maintain.

##### Relevant Technologies, Frameworks, or Libraries
- Swift and Swift Package Manager: Since the project is managed via Package.swift and integrated with Xcode and SwiftPM.
- XCTest: As seen in the example usage and tests (found in the “Tests” directory).
- GitHub Actions: For continuous integration (the GitHub workflows illustrate build, format, and release workflows).
- Optional: Integration with custom plug-ins and external tools (e.g., diff viewers like Kaleidoscope).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    A["SnapshotTesting Core Module"]:::core
    B["InlineSnapshotTesting Module"]:::module

    %% Snapshot functionality
    C["Snapshot Strategies (Image/Text/JSON etc)"]:::core
    D["Diff Engine"]:::core

    %% Utility Helpers
    E["Utility & Helpers: Common"]:::helper
    F["Utility & Helpers: Internal"]:::helper

    %% Documentation Nodes
    G["Documentation: SnapshotTesting"]:::doc
    H["Documentation: InlineSnapshotTesting"]:::doc

    %% Test Suite
    I["Test Suite"]:::test

    %% Build & CI Configuration Subgraph
    subgraph "Build & CI Configuration"
        J["Package.swift"]:::ci
        K["Makefile"]:::ci
        L[".github/workflows"]:::ci
    end

    %% Connections between components
    A -->|"calls"| C
    C -->|"compares"| D
    A -->|"uses"| E
    A -->|"integrates"| F
    A ---|"cooperates"| B
    I -->|"verifies"| A
    I -->|"verifies"| B
    G ---|"docs-for"| A
    H ---|"docs-for"| B

    %% Click Events
    click A "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/Sources/SnapshotTesting"
    click B "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/Sources/InlineSnapshotTesting"
    click G "https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Sources/SnapshotTesting/Documentation.docc"
    click H "https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Sources/InlineSnapshotTesting/Documentation.docc"
    click I "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/Tests"
    click E "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/Sources/SnapshotTesting/Common"
    click F "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/Sources/SnapshotTesting/Internal"
    click J "https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Package.swift"
    click K "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/Makefile"
    click L "https://github.com/pointfreeco/swift-snapshot-testing/tree/main/.github/workflows"

    %% Styles
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef module fill:#aaf,stroke:#333,stroke-width:2px;
    classDef helper fill:#cfc,stroke:#333,stroke-width:2px;
    classDef doc fill:#ffc,stroke:#333,stroke-width:2px;
    classDef test fill:#f9c,stroke:#333,stroke-width:2px;
    classDef ci fill:#cff,stroke:#333,stroke-width:2px;
```
