A lightweight, scalable and modern iOS architecture template based on Clean Architecture principles and SwiftUI.
This template provides a clean and maintainable architecture for iOS apps with clear separation of concerns, dependency injection, and SwiftUI integration.
- 🏗 Clean Architecture implementation
- 📦 Modular design
- 🔄 Async/await support
- 💉 Simple dependency injection
- 🧪 Testable by design
- 📱 SwiftUI first
- 🎯 iOS 15+ & macOS 13+
- 🧩 Easy to extend
ModernCleanSwiftUI/
├── Sources/
│ ├── Domain/
│ │ ├── Entity.swift
│ │ ├── Repository.swift
│ │ └── ViewState.swift
│ ├── Infrastructure/
│ │ ├── Network/
│ │ └── Storage/
│ └── Presentation/
│ └── Views/
└── Tests/
- Add the package to your Xcode project:
dependencies: [
.package(url: "https://github.com/NSFuntik/SwiftModernArchitecture", from: "1.0.0")
]
- Import the modules you need:
import Domain
import Presentation
import Infrastructure
struct User: Entity {
let id: UUID
let name: String
}
final class UsersFeature: Feature {
typealias Input = UserRequest
typealias Output = [User]
func execute(_ input: Input) async throws -> Output {
// Implementation
}
}
struct UsersView: View {
var body: some View {
LoadableView(source: usersFeature, input: .all) { users in
List(users) { user in
Text(user.name)
}
}
}
}
Entity
: Base protocol for domain modelsRepository
: Data access abstractionFeature
: Combined repository and business logic
APIClient
: Network communicationStorageService
: Data persistence
LoadableView
: Data loading containerResourceView
: State handlingPaginatedView
: Pagination support
-
Keep layers separate and dependencies clean:
- Domain has no dependencies
- Infrastructure depends on Domain
- Presentation depends on Domain
-
Use dependency injection:
@Inject private var feature: UsersFeature
- Handle states properly:
LoadableView(source: feature, input: input) { data in
// Success state
}
- Write tests for each layer:
class FeatureTests: XCTestCase {
func testFeature() async throws {
// Test implementation
}
}
- ✅ Clear separation of concerns
- ✅ Highly testable architecture
- ✅ Modern Swift features
- ✅ SwiftUI integration
- ✅ Minimal dependencies
- ✅ Easy to understand and extend
- ✅ Production ready
Contributions are welcome! Please read our contributing guidelines and submit pull requests.
- iOS 15.0+
- macOS 13.0+
- Xcode 14.0+
- Swift 5.9+
This project is available under the MIT license.