# airbnb/swift architecture

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

## Overview

##### Project Type and Purpose
- This is an open-source Swift Package Manager (SPM) plugin and CLI tool (“Airbnb Swift Format Tool”) that enforces the Airbnb Swift style guide by invoking SwiftFormat and SwiftLint on any Swift package.
- It’s not a web service or microservice architecture, but a developer tool that integrates into SPM (via a command plugin) and into CI (via GitHub Actions).

##### File‐Tree Analysis
- Top­-level build & metadata files:
- Package.swift / Package.resolved → defines the SPM package, its executable and plugin targets
- Gemfile / Rakefile → Ruby scripts for auxiliary tasks (e.g. release automation)
- .github/actions & .github/workflows → CI definitions using GitHub Actions
- Plugins/FormatSwift → code for the SwiftPM plugin (Plugin.swift, CommandContext.swift) that hooks into `swift package format`
- Sources/AirbnbSwiftFormatTool → the executable target implementing the “format” command:
- AirbnbSwiftFormatTool.swift + Command.swift → entrypoint and command dispatch
- Configuration assets (airbnb.swiftformat, swiftlint.yml)
- Tests/AirbnbSwiftFormatToolTests → unit tests exercising the CLI logic
- resources/xcode_settings.bash → auxiliary script to bootstrap Xcode settings

##### README Insights
- The README is both the style guide and user manual: it documents usage of the SPM command plugin (`swift package format`) and the underlying philosophy of the style rules.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors
    Developer["Developer"]:::developer
    CI["GitHub Actions CI"]:::ci

    %% Core Flow
    Developer -->|"runs `swift package format`"| SPMHost["SPM Plugin Host"]:::plugincli
    SPMHost -->|"loads command plugin"| PluginModule["Plugin Module"]:::plugincli
    PluginModule -->|"instantiates CommandContext"| CLI["CLI Module"]:::plugincli
    CLI -->|"reads configs"| ConfigFiles["Configuration Files"]:::config
    CLI -->|"invokes"| ExternalTools["External Tools: SwiftFormat & SwiftLint"]:::external
    ExternalTools -->|"formats & lints"| CLI
    CLI -->|"exit code"| SPMHost
    CLI -->|"tested by"| Tests["Tests (unit)"]:::test

    %% CI Flow
    CI -->|"checkout code"| CICheckout["Checkout"]:::ci
    CICheckout --> CIRunTests["Run Tests"]:::ci
    CIRunTests -->|"runs `swift package format --lint`"| CLI
    CI -->|"uses plugin"| PluginModule

    %% Documentation and Scripts
    Developer -->|"reads"| README["README.md"]:::doc
    Auxiliary["Auxiliary Release Scripts"]:::script
    Auxiliary --> Gemfile["Gemfile & Gemfile.lock"]:::script
    Auxiliary --> Rakefile["Rakefile"]:::script

    %% Configuration Files grouping
    subgraph "Configuration Assets"
        ConfigFiles
        SwiftFormatConfig["airbnb.swiftformat"]:::config
        SwiftLintConfig["swiftlint.yml"]:::config
        XcodeScript["xcode_settings.bash"]:::config
    end
    ConfigFiles --> SwiftFormatConfig
    ConfigFiles --> SwiftLintConfig
    ConfigFiles --> XcodeScript

    %% Click Events
    click PackageMetadata "https://github.com/airbnb/swift/blob/master/Package.swift"
    click PackageMetadata "https://github.com/airbnb/swift/blob/master/Package.resolved"
    click Gemfile "https://github.com/airbnb/swift/tree/master/Gemfile"
    click Gemfile "https://github.com/airbnb/swift/blob/master/Gemfile.lock"
    click Rakefile "https://github.com/airbnb/swift/tree/master/Rakefile"
    click CICheckout "https://github.com/airbnb/swift/blob/master/.github/workflows/main.yml"
    click CIRunTests "https://github.com/airbnb/swift/blob/master/.github/actions/setup/action.yml"
    click PluginModule "https://github.com/airbnb/swift/blob/master/Plugins/FormatSwift/Plugin.swift"
    click PluginModule "https://github.com/airbnb/swift/blob/master/Plugins/FormatSwift/CommandContext.swift"
    click CLI "https://github.com/airbnb/swift/blob/master/Sources/AirbnbSwiftFormatTool/AirbnbSwiftFormatTool.swift"
    click CLI "https://github.com/airbnb/swift/blob/master/Sources/AirbnbSwiftFormatTool/Command.swift"
    click SwiftFormatConfig "https://github.com/airbnb/swift/blob/master/Sources/AirbnbSwiftFormatTool/airbnb.swiftformat"
    click SwiftLintConfig "https://github.com/airbnb/swift/blob/master/Sources/AirbnbSwiftFormatTool/swiftlint.yml"
    click XcodeScript "https://github.com/airbnb/swift/blob/master/resources/xcode_settings.bash"
    click Tests "https://github.com/airbnb/swift/blob/master/Tests/AirbnbSwiftFormatToolTests/AirbnbSwiftFormatToolTests.swift"
    click README "https://github.com/airbnb/swift/blob/master/README.md"

    %% Styles
    classDef developer fill:#f9f,stroke:#333,stroke-width:1px
    classDef ci fill:#ccf,stroke:#333,stroke-width:1px
    classDef plugincli fill:#cfc,stroke:#333,stroke-width:1px
    classDef config fill:#ffc,stroke:#333,stroke-width:1px
    classDef external fill:#fcc,stroke:#333,stroke-width:1px
    classDef test fill:#eef,stroke:#333,stroke-width:1px
    classDef doc fill:#ddd,stroke:#333,stroke-width:1px
    classDef script fill:#efe,stroke:#333,stroke-width:1px
```
