# dogo/sketchkit architecture

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

- Interactive diagram: https://gitdiagram.com/dogo/sketchkit
- Repository: https://github.com/dogo/sketchkit

## Overview

##### Project Type and Purpose
- Type: Open-source Swift library (not a client app), distributed via CocoaPods, SPM, Carthage.
- Purpose: Provide a lightweight, pure-Swift DSL (“domain-specific language”) wrapper around Apple’s Auto Layout APIs, making constraint creation more concise and type-safe.

##### File Structure
- Top-level configuration & metadata
– CI/CD: .github/workflows/{Testing.yml, PublishDocumentation.yml}
– Linting & formatting: .swiftlint.yml, .jazzy.yaml, .tool-versions, Dangerfile
– Packaging: Package.swift, SketchKit.podspec, Gemfile
- Sources/SketchKit
– Constrainable.swift: protocol bridging UIView/UILayoutGuide to the DSL
– Extensions/: anchor definitions and safe-area helpers
– KeyboardLayoutGuide.swift: custom layout guide for keyboard avoidance
– SketchKitDSL.swift: entry point & internal DSL execution engine
- Tests/SketchKitTests
– Organized by feature (Anchors, Addons, SafeArea, Helpers) verifying each extension and protocol

##### README for Additional Insights
- Core functionality description
- Usage example showing:
– UIView.layout.applyConstraint { view in … }
– Generation of NSLayoutConstraint under the hood
- Supported platforms (iOS, tvOS, macOS) and Swift versions
- Publication targets (CocoaPods, SPM, Carthage)

##### Main Components & Their Interactions
a. Client App
– Your view code calls `import SketchKit` and uses `view.layout.applyConstraint { … }`.
b. SketchKit DSL Engine
– SketchKitDSL: orchestrates the collection and activation of constraints.
c. Constrainable Protocol & Extensions
– Adapts UIView/UILayoutGuide to the DSL API.
– Provides anchor methods (centerXAnchor(equalTo:…), leadingAnchor(equalTo:…), etc.).
d. Anchor Types & Safe-Area Add-ons
– Extension modules implement specific anchors and safe area relatives.
e. Underlying Auto Layout API
– Apple’s NSLayoutAnchor & NSLayoutConstraint
– Activation (`constraint.isActive = true`) managed by the DSL engine.
f. KeyboardLayoutGuide
– Custom UILayoutGuide to handle keyboard appearance/disappearance.

##### Architectural Patterns & Design Principles
- DSL / Fluent Interface pattern: chaining anchor methods
- Protocol extension: Constrainable protocol extends UIView and UILayoutGuide uniformly
- Separation of concerns:
– DSL definitions in Extensions
– Execution & activation logic in SketchKitDSL
– Distribution definitions in Podspec/Package.swift
- Test organization mirrors extension modules to ensure complete coverage

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client / Consumer Code"
        Client_App["Client App"]:::client
    end

    %% SketchKit Module
    subgraph "SketchKit Module"
        SketchKitDSL["SketchKitDSL (applyConstraint)"]:::internal
        Constrainable["Constrainable Protocol & Extensions"]:::internal
        Anchors1["Constrainable+Anchors"]:::internal
        Anchors2["Anchors+SafeArea Extensions"]:::internal
        KeyboardGuide["KeyboardLayoutGuide"]:::internal
    end

    %% Apple Auto Layout Framework
    subgraph "Apple Auto Layout Framework"
        NSLayoutAnchor["NSLayoutAnchor & NSLayoutConstraint"]:::apple
    end

    %% Build & Distribution
    subgraph "Build & Distribution"
        subgraph "CI/CD Workflows"
            CI_Testing["Testing Workflow"]:::orange
            CI_Docs["PublishDocumentation Workflow"]:::orange
        end
        subgraph "Lint & Formatting"
            SwiftLint[".swiftlint.yml"]:::orange
            Jazzy[".jazzy.yaml"]:::orange
            Tools[".tool-versions"]:::orange
            Danger["Dangerfile"]:::orange
        end
        subgraph "Packaging & Distribution Specs"
            Package["Package.swift"]:::orange
            Podspec["SketchKit.podspec"]:::orange
            Gemfile["Gemfile"]:::orange
        end
        subgraph "Tests"
            UIViews["UIView/LayoutGuide tests"]:::orange
            UILayoutGuides["UILayoutGuide tests"]:::orange
            SafeAreaTests["Safe-Area tests"]:::orange
            Addons["Addons tests"]:::orange
            Helpers["Helpers tests"]:::orange
            LinuxMain["LinuxMain.swift & XCTestManifests.swift"]:::orange
            LintTests[".swiftlint.yml (Tests)"]:::orange
        end
    end

    %% Connections
    Client_App -->|calls| SketchKitDSL
    Client_App -->|imports| Package
    Client_App -->|imports| Podspec
    Client_App -->|imports| Gemfile

    SketchKitDSL -->|orchestrates| Constrainable
    Constrainable -->|provides anchors| Anchors1
    Constrainable -->|provides safe-area| Anchors2
    SketchKitDSL -->|activates| NSLayoutAnchor
    Anchors1 -->|generates constraints| NSLayoutAnchor
    Anchors2 -->|generates constraints| NSLayoutAnchor
    KeyboardGuide -->|integrates with| Constrainable

    CI_Testing -->|runs tests| UIViews
    CI_Testing -->|runs tests| UILayoutGuides
    CI_Testing -->|runs tests| SafeAreaTests
    CI_Testing -->|runs tests| Addons
    CI_Testing -->|runs tests| Helpers
    CI_Testing -->|runs tests| LinuxMain
    CI_Testing -->|uses linting| SwiftLint
    CI_Testing -->|uses linting| Jazzy
    CI_Testing -->|uses linting| Tools
    CI_Testing -->|uses linting| Danger

    CI_Docs -->|generates docs| Jazzy

    %% Click Events
    click CI_Testing "https://github.com/dogo/sketchkit/blob/develop/.github/workflows/Testing.yml"
    click CI_Docs "https://github.com/dogo/sketchkit/blob/develop/.github/workflows/PublishDocumentation.yml"
    click SwiftLint "https://github.com/dogo/sketchkit/blob/develop/.swiftlint.yml"
    click Jazzy "https://github.com/dogo/sketchkit/blob/develop/.jazzy.yaml"
    click Tools "https://github.com/dogo/sketchkit/blob/develop/.tool-versions"
    click Danger "https://github.com/dogo/sketchkit/tree/develop/Dangerfile"
    click Package "https://github.com/dogo/sketchkit/blob/develop/Package.swift"
    click Podspec "https://github.com/dogo/sketchkit/blob/develop/SketchKit.podspec"
    click Gemfile "https://github.com/dogo/sketchkit/tree/develop/Gemfile"
    click Constrainable "https://github.com/dogo/sketchkit/blob/develop/Sources/SketchKit/Constrainable.swift"
    click Anchors1 "https://github.com/dogo/sketchkit/blob/develop/Sources/SketchKit/Extensions/Constrainable+Anchors.swift"
    click Anchors2 "https://github.com/dogo/sketchkit/blob/develop/Sources/SketchKit/Extensions/Anchors+SafeArea.swift"
    click SketchKitDSL "https://github.com/dogo/sketchkit/blob/develop/Sources/SketchKit/SketchKitDSL.swift"
    click KeyboardGuide "https://github.com/dogo/sketchkit/blob/develop/Sources/SketchKit/KeyboardLayoutGuide.swift"
    click UIViews "https://github.com/dogo/sketchkit/tree/develop/Tests/SketchKitTests/UIView/LayoutGuide/*"
    click UILayoutGuides "https://github.com/dogo/sketchkit/tree/develop/Tests/SketchKitTests/UILayoutGuide/*"
    click SafeAreaTests "https://github.com/dogo/sketchkit/tree/develop/Tests/SketchKitTests/UIView/SafeArea/*"
    click Addons "https://github.com/dogo/sketchkit/tree/develop/Tests/SketchKitTests/Addons/*"
    click Helpers "https://github.com/dogo/sketchkit/tree/develop/Tests/SketchKitTests/Helpers/*"
    click LinuxMain "https://github.com/dogo/sketchkit/blob/develop/Tests/LinuxMain.swift"
    click LinuxMain "https://github.com/dogo/sketchkit/blob/develop/Tests/SketchKitTests/XCTestManifests.swift"
    click LintTests "https://github.com/dogo/sketchkit/blob/develop/Tests/.swiftlint.yml"

    %% Styles
    classDef client fill:#AED6F1,stroke:#1F618D
    classDef internal fill:#ABEBC6,stroke:#1D8348
    classDef apple fill:#D5D8DC,stroke:#808B96
    classDef orange fill:#F9E79F,stroke:#B7950B
```
