CoolLib — Native iOS Client

SwiftUI Swift 6 SwiftData R2 / S3

CoolLib is a native iOS client built with Clean Architecture to support a distributed library system. It uses Swift Concurrency (async/await) to manage data flow and integrates a direct-to-cloud Cloudflare R2 (S3-compatible) upload pipeline for media handling. The app follows an offline-first approach, persisting data locally with SwiftData and synchronizing with a Spring Boot backend.

Architectural Philosophy

CoolLib iOS is structured around Protocol-Oriented Programming (POP), using Swift protocols to define clear boundaries between layers. This approach keeps the codebase modular, testable, and easy to evolve over time.

By combining Swift Concurrency with a Cloudflare R2-backed storage layer, the system separates application logic from asset transfer, enabling efficient data synchronization while keeping backend services lightweight and secure.

Key Technical Wins

Protocol-Oriented Architecture

Applied Clean Architecture (MVVM) with Swift Protocols to enforce strict module boundaries, enabling high testability and independent component evolution.

Swift Concurrency Model

Leveraged Async/Await to orchestrate concurrent API requests and maintain predictable execution flow with structured error propagation and cancellation handling.

Offline-First Persistence

Adopted SwiftData for declarative local storage, implementing an offline-first caching layer to maintain consistency and responsiveness under network constraints.

Direct-to-Cloud Pipeline

Designed a direct-to-cloud upload architecture with R2 (S3-compatible) and presigned URLs, offloading media transfer from backend services and improving scalability.


iOS Data Flow

iOS App Architecture
graph TD %% ==================== Infrastructure ==================== subgraph I_Infra ["`**Infrastructure / DI**`"] IContainer(DI Factory) IAPI(URLSession) ISD[(SwiftData)] IRepoImpl(Repository Impl) end %% ==================== Domain ==================== subgraph I_Proto ["`**Domain (Protocols)**`"] IRepo[["BookRepository"]] end %% ==================== Presentation ==================== subgraph I_UI ["`**UI Layer (SwiftUI)**`"] direction TB IVM("HomeViewModel") IView(SwiftUI View) end %% DI Flow IContainer -.->|Create| IAPI & ISD & IRepoImpl IContainer -.->|Inject| IVM %% DIP & Data Flow IRepoImpl -.->|Conforms| IRepo IVM -->|Depends| IRepo IAPI & ISD -->|Stream| IRepoImpl IRepoImpl -->|async/await| IVM %% UDF Flow IVM -- "Observe" --> IView IView -- "Action" --> IVM %% ==================== Styling ==================== style IContainer fill:#007aff,stroke:#0056b3,stroke-width:2px,color:#ffffff style IAPI fill:#475569,stroke:#334155,stroke-width:2px,color:#ffffff style ISD fill:#334155,stroke:#1e293b,stroke-width:2px,color:#ffffff style IRepoImpl fill:#64748b,stroke:#475569,stroke-width:2px,color:#ffffff style IRepo fill:#f97316,stroke:#ea580c,stroke-width:2px,color:#ffffff style IVM fill:#059669,stroke:#047857,stroke-width:2px,color:#ffffff style IView fill:#f0fdf4,stroke:#059669,stroke-width:2px,color:#14532d style I_Infra fill:none,stroke:#007aff,stroke-width:2px,stroke-dasharray: 5 5 style I_Proto fill:none,stroke:#f97316,stroke-width:2px style I_UI fill:none,stroke:#059669,stroke-width:2px linkStyle default stroke:#64748b,stroke-width:1.5px

*Mirroring Android architecture via Protocol-Oriented Programming (POP).*

Decentralized Asset Pipeline

Data Fetching Logic
sequenceDiagram autonumber %% ==================== 参与者声明与色彩分组 ==================== participant UI as 🟢 ImagePicker (UI) participant Repo as 🔷 AssetRepository participant Web as ⚙️ Gateway (Spring) participant R2 as ☁️ Cloudflare R2 %% ==================== 上传控制流 ==================== UI->>Repo: uploadImage(UIImage) rect rgb(240, 247, 255) Note over Repo, Web: Phase 1: Authentication & Ticket Fetch Repo->>Web: GET /assets/presigned-url (fileName) Web-->>Repo: 200 OK (PUT URL + Public URL) end rect rgb(240, 253, 244) Note over Repo, R2: Phase 2: Direct Binary Pipe to Edge Repo->>R2: HTTP PUT (Binary Data + Presigned URL) R2-->>Repo: 200 OK (Upload Success) end rect rgb(254, 242, 242) Note over Repo, Web: Phase 3: Distributed Metadata Sync Repo->>Web: POST /books/reviews (imageKey) Web-->>Repo: 201 Created end Repo-->>UI: Render Remote Image

*The Repository manages the Presigned URL handshake, enabling secure, direct binary uploads to Cloudflare R2 without taxing the primary backend.*


Tech Stack

  • UI Framework: SwiftUI, Observation, SF Symbols, Core Animation
  • Logic & Concurrency: MVVM, Swift Protocols, Async/Await, Structured Concurrency
  • Data & Infrastructure: SwiftData, Cloudflare R2 (S3), Presigned URLs, URLSession

Core Features

Loan Management

Library Analytics

Advanced Search

Signature Design


Engineered with passion by Ryan Su © 2026