Swift Package
為 Server-Side Swift 打造的 Domain-Driven Design + Event Sourcing 框架。
swift-ddd-kit 把 Domain-Driven Design 的戰術模式(Aggregate、Domain Event、Repository、 Use Case)與 Event Sourcing 結合成一套專為 Server-Side Swift 打造的 Swift 6 框架, 並以 KurrentDB 作為事件儲存。Swift 後端生態日益成熟,但 production 等級 DDD 架構的 建構元件——aggregate root、event sourcing repository、CQRS projector、事件 migration—— 一直缺席;swift-ddd-kit 補上這塊。它提供分層的 protocol 抽象、build-time 的程式碼生成 plugin,以及 CQRS 讀模型投影機制——讓你把注意力放在 domain 邏輯,而不是基礎設施。
框架由數個 target 組成,DDDKit 是把它們重新導出的 umbrella module:
核心 DDD 協定:Entity、DomainEvent、AggregateRoot、DomainEventBus、Usecase。
抽象的 event sourcing 模式:EventStore、EventSourcingRepository、EventSourcingProjector、ReadModel。
KurrentDB 轉接層:KurrentStorageCoordinator、EventTypeMapper。
記憶體內的事件匯流排實作。
事件結構演進 / schema migration 框架。
YAML → Swift 的程式碼生成函式庫。
對 KurrentDB 做整合測試的輔助工具。
讓事件 conform DomainEvent,或從 event.yaml 生成。
用 when(happened:) handler 從事件變更狀態。
把 KurrentDB 的 RecordedEvent 反序列化回型別化的事件結構。
EventSourcingRepository 由 KurrentStorageCoordinator 撐起。
repository.save(aggregateRoot:) 把未提交事件附加到 KurrentDB。
repository.find(byId:) 重播事件、重建 aggregate 狀態。