# tranhuycong/space-saver architecture

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

- Interactive diagram: https://gitdiagram.com/tranhuycong/space-saver
- Repository: https://github.com/tranhuycong/space-saver

## Overview

##### Main Components

A. User Interface Layer
- SwiftUI Views (found in /Views directory)
- Key components:
- ContentView (main container)
- HomeView (primary interface)
- SpaceDetail (workspace details)
- AppWidget (widget component)

B. Core Application Layer
- Application Services (/Services directory)
- Models (/Models directory)
- Helpers (/Helpers directory)

C. System Integration Layer
- macOS Desktop Space Integration
- Window Management System
- File System Storage

**┌─────────────────────────────────────────┐**
- Presentation               │
- ┌─────────────┐  ┌─────────────────┐  │
- Views     │  │     Widgets     │  │
- ┘  └─────────────────┘  │
- ┤
- Business Logic               │
- ┌─────────────┐  ┌─────────────────┐  │
- Models    │  │    Services     │  │
- ┘  └─────────────────┘  │
- ┤
- System Integration             │
- ┌─────────────┐  ┌─────────────────┐  │
- macOS API  │  │  File Storage   │  │
- ┘  └─────────────────┘  │
- ┘

##### Key Relationships to Highlight

A. Data Flow
- User interaction → Views → Services
- Services → Models → Storage
- System APIs ↔ Window Management

B. Component Dependencies
- Views depending on Models (SpaceInfo, WindowInfo)
- Services managing system integration
- Helpers providing utility functions

##### Implementation Details

- Use standardized UML notation where appropriate
- Clear labels for all components
- Version information and update flow
- Configuration dependencies (AppConfig.swift)

##### Notes

- Keep the focus on the core functionality of workspace management
- SwiftUI-based architecture
- Clear separation between UI and system integration layers
- Error handling and state restoration flows

Remember to include version control integration and testing components (SpaceSaverTests and SpaceSaverUITests) in a separate testing layer or as overlapping concerns across all layers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Presentation
        ContentView["ContentView"]:::ui
        HomeView["HomeView"]:::ui
        SpaceDetail["SpaceDetail"]:::ui
        AppWidget["AppWidget"]:::ui
        
        ContentView --> HomeView
        HomeView --> SpaceDetail
        HomeView --> AppWidget
    end

    subgraph "Business Logic"
        SpaceInfo["SpaceInfo Model"]:::model
        WindowInfo["WindowInfo Model"]:::model
        SpaceList["SpaceList Model"]:::model
        AppService["Application Service"]:::service
        
        SpaceInfo --> WindowInfo
        SpaceList --> SpaceInfo
        AppService --> SpaceList
    end

    subgraph "System Integration"
        AppConfig["App Configuration"]:::system
        Updater["Update Mechanism"]:::system
        UserDefaults["User Preferences"]:::system
        MacOSAPI["macOS Window API"]:::external
        FileStorage["File System Storage"]:::external
        
        AppConfig --> MacOSAPI
        Updater --> MacOSAPI
        UserDefaults --> FileStorage
    end

    subgraph Testing
        UnitTests["Unit Tests"]:::test
        UITests["UI Tests"]:::test
    end

    %% Cross-layer relationships
    HomeView --> AppService
    SpaceDetail --> SpaceInfo
    AppWidget --> WindowInfo
    AppService --> MacOSAPI
    AppService --> UserDefaults
    MacOSAPI --> FileStorage

    %% Component click events
    click ContentView "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Views/ContentView.swift"
    click HomeView "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Views/HomeView.swift"
    click SpaceDetail "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Views/SpaceDetail.swift"
    click AppWidget "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Views/AppWidget.swift"
    click AppService "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Services/AppService.swift"
    click SpaceInfo "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Models/SpaceInfo.swift"
    click WindowInfo "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Models/WindowInfo.swift"
    click SpaceList "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Models/SpaceList.swift"
    click AppConfig "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Config/AppConfig.swift"
    click Updater "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Helpers/Updater.swift"
    click UserDefaults "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaver/Helpers/UserDefaultsHelper.swift"
    click UnitTests "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaverTests/SpaceSaverTests.swift"
    click UITests "https://github.com/tranhuycong/space-saver/blob/main//SpaceSaverUITests/SpaceSaverUITests.swift"

    %% Styling
    classDef ui fill:#2196F3,stroke:#1565C0,color:white
    classDef model fill:#4CAF50,stroke:#2E7D32,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef system fill:#FF9800,stroke:#EF6C00,color:white
    classDef external fill:#9E9E9E,stroke:#616161,color:white
    classDef test fill:#673AB7,stroke:#4527A0,color:white

    %% Legend
    subgraph Legend
        UI["UI Component"]:::ui
        Model["Model"]:::model
        Service["Service"]:::service
        System["System Component"]:::system
        External["External System"]:::external
        Test["Test Component"]:::test
    end
```
