# compnerd/swift-win32 architecture

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

- Interactive diagram: https://gitdiagram.com/compnerd/swift-win32
- Repository: https://github.com/compnerd/swift-win32

## Overview

##### Main Components

a) Core Framework Layer:
- SwiftWin32 (Main Framework)
- SwiftWin32UI (SwiftUI-style Interface)
- Platform Integration Components

b) Key Architectural Components:
- Application Layer (App and Environment)
- UI Component Layer (Views and Controls)
- Platform Bridge Layer (Win32 API Integration)
- Auto Layout System
- Event Handling System

##### Component Relationships

**┌─────────────────────────────────────────────────────────┐**
- Application Layer                    │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Scene    │  │  Application │  │WindowScene    │   │
- Management │  │   Lifecycle  │  │  Delegation   │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┤
- UI Component Layer                    │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Views &      │  │   Controls   │  │  Animation   │   │
- Controllers  │  │              │  │    System    │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┤
- Core Services Layer                   │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Auto Layout │  │Event Handling│  │  Drawing &   │   │
- Engine    │  │    System    │  │   Graphics   │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┤
- Platform Bridge Layer                  │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Win32 API  │  │ Windows SDK  │  │Native System │   │
- Wrappers   │  │  Integration │  │   Services   │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┘

##### Important Details

a) Framework Integration:
- How SwiftWin32UI integrates with SwiftWin32
- COM integration points
- Windows SDK dependency boundaries

b) Key Subsystems:
- Auto Layout System (using Cassowary constraint solver)
- Event Handling Pipeline
- View Hierarchy Management
- Window Management

c) External Dependencies:
- Swift Collections
- Swift COM
- Swift Log
- Cassowary Constraint Solver

##### Implementation Notes

- Use standard UML notation where appropriate
- Notes for key architectural decisions
- Version-specific features (Swift 5.4+)

Remember to include the example applications (Calculator and UICatalog) as reference implementations showing how the components work together in practice.

This architecture should be represented in a way that clearly shows the layered approach while highlighting the framework's main goal of providing a Swift-friendly wrapper around Win32 APIs.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef application fill:#e1d5e7,stroke:#9673a6
    classDef ui fill:#dae8fc,stroke:#6c8ebf
    classDef core fill:#d5e8d4,stroke:#82b366
    classDef platform fill:#ffe6cc,stroke:#d79b00
    classDef external fill:#f5f5f5,stroke:#666666

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        Scene["Scene Management"]
        AppLife["Application Lifecycle"]
        WinScene["WindowScene Delegation"]
    end

    %% UI Component Layer
    subgraph UILayer["UI Component Layer"]
        Views["Views & Controllers"]
        Controls["Controls"]
        Animation["Animation System"]
    end

    %% Core Services Layer
    subgraph CoreLayer["Core Services Layer"]
        AutoLayout["Auto Layout Engine"]
        EventSystem["Event Handling System"]
        Graphics["Drawing & Graphics"]
    end

    %% Platform Bridge Layer
    subgraph PlatformLayer["Platform Bridge Layer"]
        Win32API["Win32 API Wrappers"]
        WinSDK["Windows SDK Integration"]
        NativeServices["Native System Services"]
    end

    %% External Dependencies
    subgraph External["External Dependencies"]
        SwiftCollections["Swift Collections"]
        SwiftCOM["Swift COM"]
        SwiftLog["Swift Log"]
        Cassowary["Cassowary Solver"]
    end

    %% Relationships
    AppLayer --> UILayer
    UILayer --> CoreLayer
    CoreLayer --> PlatformLayer
    PlatformLayer --> External

    %% Component Relationships
    Scene --> Views
    Views --> AutoLayout
    Controls --> EventSystem
    Animation --> Graphics
    Graphics --> Win32API
    EventSystem --> WinSDK
    AutoLayout --> Cassowary

    %% Click Events
    click Scene "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/App and Environment/Scenes/"
    click Views "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/Views and Controls/"
    click Animation "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/Animation and Haptics/"
    click AutoLayout "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/AutoLayout/"
    click EventSystem "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/Touches, Presses, and Gestures/"
    click Graphics "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/CoreGraphics/"
    click Win32API "https://github.com/compnerd/swift-win32/tree/main/Sources/SwiftWin32/Platform/"

    %% Style Applications
    class Scene,AppLife,WinScene application
    class Views,Controls,Animation ui
    class AutoLayout,EventSystem,Graphics core
    class Win32API,WinSDK,NativeServices platform
    class SwiftCollections,SwiftCOM,SwiftLog,Cassowary external
```
