Skip to main content
Breeze uses modern Swift and SwiftUI patterns to create a maintainable, scalable, and thread-safe application.

Core Architectural Patterns

MVVM

Model-View-ViewModel for clear separation of concerns

Actor Pattern

Thread-safe service layer using Swift actors

Declarative UI

SwiftUI for reactive, declarative interfaces

Async/Await

Modern concurrency for clean async code

MVVM Pattern

Breeze implements the Model-View-ViewModel pattern for clear separation between UI and business logic.

Architecture Flow

ViewModel Example

The DashboardViewModel demonstrates the MVVM pattern:
Key MVVM Characteristics:
  • @Published properties for reactive state updates
  • @MainActor ensures UI updates on main thread
  • Business logic separated from UI
  • Computed properties for derived state

View Observing ViewModel

Views observe the ViewModel using @ObservedObject. When published properties change, SwiftUI automatically re-renders affected views.

Actor Pattern for Services

All services use Swift’s actor pattern for thread-safe API communication.

Why Actors?

Actors ensure only one task can access mutable state at a time, preventing data races.
Swift automatically manages synchronization - no manual locks or dispatch queues needed.
The compiler enforces safe concurrent access patterns at compile time.

Service Actor Example

Actor Benefits:
  • actor keyword makes the entire class thread-safe
  • Methods are implicitly async when called from outside
  • Shared singleton pattern (static let shared) is safe
  • No manual synchronization needed

Calling Actor Methods

Actor methods require await when called from outside:
Calling Actors
Actor methods can only be called with await because the actor may need to synchronize access. This prevents blocking the main thread.

Async/Await Pattern

Breeze uses Swift’s modern concurrency with async/await for clean asynchronous code.

Parallel vs Sequential Fetching

Pattern Choice:
  • Use sequential (await) when data depends on previous results
  • Use parallel (Task {}) for independent data fetching
  • Balance between performance and data dependencies

SwiftUI Declarative Patterns

Breeze embraces SwiftUI’s declarative approach for building UIs.

Property Wrappers

Conditional Rendering

View Composition

Breeze breaks down complex views into smaller components:
View Composition
Each component is self-contained and reusable, making the code easier to test and maintain.

Model Pattern

Models are simple, immutable data structures conforming to Codable.
  • Value semantics (copying instead of referencing)
  • Thread-safe by default
  • No reference counting overhead
  • Perfect for immutable data
  • Automatic JSON encoding/decoding
  • Type-safe API responses
  • Custom key mapping with CodingKeys

Pattern Summary

MVVM

  • ViewModels manage state
  • Views observe and render
  • Models represent data
  • Clear separation of concerns

Actor Pattern

  • Thread-safe services
  • Compiler-enforced safety
  • No manual synchronization
  • Singleton pattern with static let

Async/Await

  • Clean asynchronous code
  • Parallel and sequential fetching
  • Error handling with try/catch
  • Task-based concurrency

SwiftUI

  • Declarative UI syntax
  • Reactive data binding
  • View composition
  • State-driven rendering

Best Practices

1

Keep ViewModels focused

One ViewModel per major screen. Extract shared logic into separate services or utilities.
2

Use actors for shared state

Any service that manages shared mutable state should be an actor for thread safety.
3

Prefer async/await over callbacks

Modern concurrency is clearer and less error-prone than completion handlers.
4

Keep views small

Break down complex views into smaller, reusable components.
5

Use @MainActor for ViewModels

Ensures all UI updates happen on the main thread automatically.

Next Steps

Project Structure

Understand the file organization

Services Reference

Explore service implementations