How useradgents/slab works
Project Type & Purpose
• Slab is a Swift Package (library) that overlays and extends Apple’s Foundation and CoreGraphics frameworks with convenience methods, custom collections, general tools, networking helpers, property wrappers, and two build‐time/run‐time tools (Version Wizard & Environment Manager).
• It ships as a modular SPM package plus a set of shell scripts that integrate into Xcode build phases (Localise.biz fetcher, VersionWizard, ConfCryptor).
High‐Level Components
A. Slab Library (Sources/Slab)
• CoreGraphics Extensions
• Foundation Extensions
• Custom Collections
• General Tools (logging, QR codes, device info, date math, etc.)
• Networking Helpers (async wrappers)
• Property Wrappers
B. External Dependencies (declared in Package.swift)
• RNCryptor – AES encryption/decryption
• KeychainSwift – Keychain access
• Reachability.swift – network reachability
C. Helpers (Helpers/…) – build‐time tooling
• ConfCryptor.sh – encrypt JSON environment files
• Localise.biz.sh – fetch Localizable.strings remotely
• VersionWizard.sh & VersionWizard2.sh – sync CFBundle version & build numbers
• versionWizard‐src – Swift CLI that can also set versions via URLRequest
D. Environment Manager (runtime component)
• Reads encrypted .json.aes files at launch
• Decrypts them via RNCryptor
• Provides EnvironmentManager API to retrieve keys & switch environments
E. Tests (Tests/SlabTests)
• Unit tests for core extensions & tools
Relationships & Data Flows
• SPM/Xcode reads Package.swift → fetches Slab + its dependencies → compiles Sources/Slab → builds a .swiftmodule.
• In your Xcode project, three custom Run Script build phases reference the Helpers’ shell scripts:
1. Localise.biz (pull translations before resources copy)
2. Encrypt Environments (ConfCryptor.sh before resources copy)
3. Version Wizard (VersionWizard2.sh after resource copy, install builds only)
• ConfCryptor.sh takes plaintext env_*.json → outputs AES‐encrypted env_*.json.aes → bundled with app.
• At runtime, EnvironmentManager uses RNCryptor to decrypt .aes files → populates Environment structs → client code calls EnvironmentManager APIs.
• VersionWizard scripts read/write Xcode build settings (VW_APP_ID, CFBundleVersion) via agvtool or its own Swift CLI.
Architectural Patterns & Principles
• Modular packaging: each category of extensions lives in its own subfolder → clear separation of concerns.
• Layering:
• Foundation/CoreGraphics base layer (extensions)
• Utility layer (collections, tools, networking)
• Runtime/configuration layer (EnvironmentManager)
• Build‐time tooling layer (shell scripts + Swift CLI)
• Single Responsibility: each helper script handles one task; each Swift file extends one protocol/class.
• Dependency injection at runtime via EnvironmentManager for configuration.
• Use of SPM for versioning, dependency resolution, and integration.
2. “Slab Package” module cluster at center, sub‐divided into folders (CoreGraphics, Foundation, Collections, General Tools, Networking, Property Wrappers).