# dropbox/rxpublished architecture

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

- Interactive diagram: https://gitdiagram.com/dropbox/rxpublished
- Repository: https://github.com/dropbox/rxpublished

## Overview

##### Project type and purpose
- Project type: Swift Package Manager library, open-source tool.
- Purpose: Provide an `@RxPublished` property wrapper that plugs into SwiftUI’s `ObservableObject` ViewModels, replacing Combine’s `@Published` with RxSwift under the hood.

##### File structure
- Top-level:
– Package.swift (defines the Swift package, targets, dependencies)
– Sources/RxPublished/RxPublished.swift (core implementation)
– Tests/RxPublishedTests/RxPublishedTests.swift (unit tests)
- No separate “frontend” / “backend” – it’s purely a library.
- Key patterns: property-wrapper, binding to external Observables, use of RxSwift subjects/observables.

##### Mine the README for additional insights
- Describes usage patterns:
– Annotate view-model properties with `@RxPublished`
– Bind external `Observable<T>` to underscored accessor (`_property`)
– Subscribe to projected value (`$property`)

##### Main components
a. Consumer SwiftUI ViewModel
b. `@RxPublished` Property Wrapper (in RxPublished.swift)
c. Underlying RxSwift primitives (Subject / Observable / DisposableBag)
d. SwiftUI Binding system (reads/writes via projected value `$`)
e. Optional external Observable (binds into `_property`)
f. Test harness (unit tests target, RxPublishedTests)

##### Relationships and data flows
- Initialization: ViewModel declares `@RxPublished var example` → wrapper creates a `BehaviorSubject` or `PublishSubject`.
- Writing: setting `example = newValue` → wrapper pushes newValue into subject → SwiftUI views observing `$example` update.
- Reading: SwiftUI Binding reads current subject value.
- External binding: external `Observable<T>` → `.bind(to: _example)` → subject value updates.
- Subscription: user code subscribes to `$example` to observe changes → events flow out via RxSwift subscription.

##### Architectural patterns and design principles
- Property-wrapper pattern (Swift feature)
- Reactive Programming (RxSwift)
- Separation of concerns: ViewModel logic stays Rx-based, SwiftUI remains unaware of Combine.
- Testable units: property wrapper behavior verified in RxPublishedTests.

- Component labels: exactly match code names (e.g., `@RxPublished`, `_example`, `$example`)
- A note on tests: “RxPublishedTests validates subject emissions and subscription behavior”

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Package"
        PM("Package.swift"):::doc
        LOCK("Package.resolved"):::doc
        README("README.md"):::doc
    end

    subgraph "Consumer Code"
        VM("SwiftUI ViewModel"):::consumer
        View("SwiftUI View / Binding"):::consumer
        ExtObs("External Observable Source"):::consumer
    end

    subgraph "Library Code"
        RP("@RxPublished Wrapper"):::library
        Subject("RxSwift Subject / Observable"):::rx
    end

    subgraph "Tests"
        TestDir("RxPublishedTests Directory"):::test
        TestFile("RxPublishedTests.swift"):::test
    end

    PM -->|"defines library target"| RP
    README -->|"usage patterns"| VM
    VM -->|"declares @RxPublished"| RP
    RP -->|"creates subject on init"| Subject
    Subject -->|"emits via $example"| View
    ExtObs -->|".bind(to:_example)"| RP
    Subject -->|".subscribe in tests"| TestFile
    TestDir -->|contains| TestFile

    click RP "https://github.com/dropbox/rxpublished/blob/main/Sources/RxPublished/RxPublished.swift"
    click PM "https://github.com/dropbox/rxpublished/blob/main/Package.swift"
    click README "https://github.com/dropbox/rxpublished/blob/main/README.md"
    click TestFile "https://github.com/dropbox/rxpublished/blob/main/Tests/RxPublishedTests/RxPublishedTests.swift"
    click TestDir "https://github.com/dropbox/rxpublished/tree/main/Tests/RxPublishedTests"
    click LOCK "https://github.com/dropbox/rxpublished/blob/main/Package.resolved"

    classDef library fill:#D0E8FF,stroke:#000
    classDef rx fill:#FFE0B2,stroke:#000
    classDef consumer fill:#C8FACC,stroke:#000
    classDef test fill:#E0E0E0,stroke:#000
    classDef doc fill:#F0F0F0,stroke:#000
```
