Clean Swift Architecture: File & Folder Organization

Alise
2 min readJun 13, 2023

--

Fundamentals

Clean Architecture is a code organization approach that enhances testing, maintenance, and scalability by separating an application into layers. File & Folder Organization is crucial in Clean Architecture. Its components include Use Case, Repository, and View Model.

Overall Structure

Before diving into the specific components, let me show you an example of a folder structure for a Clean Architecture-based Swift application:

Use Cases

  1. Use Cases are responsible for handling the app’s business logic and managing its operations.
  2. These components define specific actions or high-level features that are tied to user actions. Use Cases also coordinate the flow of data and interactions between other components.
*placed within each feature module

Repositories

  1. Repositories are responsible for data access and abstracting the underlying data sources, such as databases, web services, or local storage.
  2. Provide a clean API for fetching and storing data, shielding the rest of the application from the implementation details of the data sources.
*placed within each feature module

View Models

  1. View Models act as the intermediaries between the UI and the rest of the application.
  2. They encapsulate the presentation logic, transform raw data into a form suitable for the UI and handling user interactions. View Models should be independent of the UI framework, allowing for easier testing.
*placed within each feature module

Conclusion

Proper file and folder organization is crucial for maintaining a clean architecture. By following the recommended structure, you can achieve a modular and maintainable codebase.

Remember, the folder structure presented in this post is just a guideline and can be adapted to fit your specific application and team preferences.

--

--

Alise
Alise

Written by Alise

iOS dev & Product Manager

Responses (1)