Skip to content

A demo project showcasing the production setup of the SwiftUI app with Clean Architecture

Notifications You must be signed in to change notification settings

miibpa/clean-architecture-swiftui

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean Architecture for SwiftUI + Combine

A demo project showcasing the setup of the SwiftUI app with Clean Architecture.

The app uses the restcountries.eu REST API to show the list of countries and details about them.

platforms Build Status coverage Dependency Status

Diagram

Key features

  • Designed for scalability. It can be used as a reference for building large production apps.
  • Vanilla SwiftUI + Combine implementation. No 3rd party dependencies
  • Programmatic navigation (deep links support)
  • Decoupled Presentation, Business Logic, and Data Access layers
  • Everything is a Struct (except for a couple of modules)
  • Centralized AppState as a single source of truth
  • Dependency injection of Interactors and AppState
  • Simple yet flexible networking layer built on Generics
  • Handling of system events (such as didBecomeActive, willResignActive)
  • Built with SOLID, DRY, KISS, YAGNI in mind.

Architecture overview

Diagram

Presentation Layer

SwiftUI views that contain no business logic and are a function of the state. AppState is injected into the view hierarchy as @EnvironmentObject

Side effects are triggered by the user's actions (such as a tap on a button) or view lifecycle event onAppear and are forwarded to the business logic layer.

Business Logic Layer

Business Logic layer is represented by Interactors.

Interactors receive requests to perform work, such as obtaining data from an external source or making computations, but they never return data back directly.

Instead, they forward the result to the AppState or to a Binding. The latter is used when the result of work (the data) is used locally by one View and does not belong to the AppState

Interactors are injected into the view hierarchy within a container as an @Environment variable.

Data Access Layer

Data Access layer is represented by Repositories.

Repositories provide asynchronous API (Publisher from Combine) for making CRUD operations on the backend or a local database. They don't contain business logic, neither do they mutate the AppState. Repositories are accessible and used only by the Interactors.

Articles related to this project


license Twitter blog

About

A demo project showcasing the production setup of the SwiftUI app with Clean Architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 90.3%
  • HTML 9.7%