Clean iOS Architecture pt.6: VIPER – Design Pattern or Architecture?
Tags: swift, ios, discuss, learning
Published: 2018-09-27 06:40:58

---
title: Clean iOS Architecture pt.6: VIPER – Design Pattern or Architecture?
published: true
tags: swift, ios, discuss, learning
canonical_url: https://www.essentialdeveloper.com/articles/clean-ios-architecture-pt-6-viper-design-pattern-or-architecture
cover_image: http://static1.squarespace.com/static/5891c5b8d1758ec68ef5dbc2/58921b5a6b8f5bd75e20b0f4/5b8d01e2352f53facc2ad4c0/1535970075067/thumbnail.png?format=1000w
---

{% youtube CkylrfKvf1A %} [Watch on YouTube](https://www.youtube.com/watch?v=CkylrfKvf1A&list=PLyjgjmI1UzlSWtjAMPOt03L7InkCRlGzb)

Today we're going to analyze the VIPER iOS Architecture and decide if we can call it a Software Architecture or a Design Pattern like the MVC, MVVM and MVP design patterns we talked about [in the previous video](https://dev.to/essentialdeveloper/clean-ios-architecture-pt5-mvc-mvvm-and-mvp-ui-design-patterns-5ha5-temp-slug-7121127).

[VIPER was introduced to the world in 2014](https://mutualmobile.com/resources/meet-viper-fast-agile-non-lethal-ios-architecture-framework), and the main goals for the architecture were Testability and to fix the Massive View Controller problem. Later on, [a more detailed article](https://www.objc.io/issues/13-architecture/viper/) was released in one of the objc.io Issues.

The detailed article explains the motivations for using VIPER:

- Testability
- Fixing the Massive View Controller issues
- Application Design based on Use Cases
- Fitting well with Platform Frameworks (like UIKit)
- Building features as Independent Modules

So can we consider VIPER a Software Architecture or just a Design Pattern?

The VIPER diagram defines a structure which seems like an architecture but may create a limited outlook of the application. Even though VIPER is presented as an architecture to solve the "MVC" limitations (where components can only be seen as Models, Views or Controllers), VIPER may have the same limitations (where components can only be seen as Views, Interactors, Presenters, Entities, or Routers).

In reality, the authors say that VIPER is "mainly" divided into those types, but can have less or even more layers of separation, as needed. Unfortunately, many developers end up trying to follow the "acronym template" (like it happens with the MVC design pattern).

VIPER can solve the Massive View Controller problem and make your code more Testable, but it doesn't solve the "Software Architecture" problem. By following the VIPER template, we may end up with Clean Code, but Spaghetti Architecture!

For example, let's have a look at the [Todo List sample project](https://github.com/mutualmobile/VIPER-SWIFT) dependencies diagram.

 ![Todo List sample project class and module dependencies diagram.](https://static1.squarespace.com/static/5891c5b8d1758ec68ef5dbc2/t/5b8d029d21c67c87037fea62/1535970073504/diagram-1.png?format=1000w)

[Todo List sample project](https://github.com/mutualmobile/VIPER-SWIFT) class and module dependencies diagram.

As you can see, there are arrows pointing everywhere. Even crossing module boundaries. Dependencies look out of control, so changes to the software can break multiple modules (and of course, multiple tests).

VIPER was introduced as an iOS implementation of [Uncle Bob’s Clean Architecture](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html). If we compare the two, they have similarities, especially in their layers names. However, a closer look shows that, at least by analyzing the VIPER Todo List example, they don’t share the same structure and goals. In Uncle Bob’s Clean Architecture, the Frameworks and Drivers (e.g. UIKit and CoreData) are just “details” or “plugins” to the Business Logic Layer. Instead, in common VIPER implementations, the frameworks end up at the center of the application. (There are also crucial data flow differences that [Paul Stringer explains in this article](https://medium.com/stringer-s-theory/the-clean-er-architecture-for-ios-apps-96379577d9dd).)

  ![VIPER Todo sample project “Onion Layers” diagram separate by features and dependencies with the frameworks at the center](https://static1.squarespace.com/static/5891c5b8d1758ec68ef5dbc2/t/5b8d02ff40ec9a2651e86d8c/1535968086482/diagram-3.png?format=1000w)

VIPER Todo sample project “Onion Layers” diagram separate by features and dependencies with the frameworks at the center.

  

We believe that software architecture is less about your responsibilities and more about how the components communicate with each other and how they depend on each other. What is coupled and why? What is decoupled and why? What is hard to change and why? What is easy to change and why? How is the data flowing between layers – is the data going in one direction? two directions? multiple directions? Can we support short and long-term business goals?

Regardless if we're following or not some sort of named architecture like VIPER, our software is structured in many components that can be coupled or decoupled. This software structure or the components structure is our architecture.

Our codebases are like living organisms, and they're changing all the time. So does the architecture. It's constantly changing. And It can move in a positive or negative direction.

Modularity, for example, is a good architecture trait, but not all architectures are modular. If we don't have modularity in our systems, it doesn't mean we don't have an architecture. However, we might quickly find out that the lack of modularity prevents us from moving fast and prevents us from achieving key business metrics. For example:

- Deployment Frequency
- Estimation Accuracy
- Lead Time for Changes
- Mean Time to Recover

At Essential Developer, our main drives are Empathy, Integrity, and Economics. Business metrics are part of Economics. When we make decisions such as the system architecture, we must care about Economics. And we do believe that Software Architecture has a strong correlation with Product Success. Product Longevity. Product Sustainability.

In our experience, MVC, MVP, MVVM, and VIPER are good design patterns when used with care. However, they are not enough to define the “Software Architecture” of our systems.

For more, visit [the Clean iOS Architecture Playlist](https://www.youtube.com/watch?v=PnqJiJVc0P8&list=PLyjgjmI1UzlSWtjAMPOt03L7InkCRlGzb).

[Subscribe now to our Youtube channel](https://www.youtube.com/essentialdeveloper?sub_confirmation=1) and catch **free new episodes every week.**

* * *

Originally published at [www.essentialdeveloper.com](https://www.essentialdeveloper.com/articles/clean-ios-architecture-pt-6-viper-design-pattern-or-architecture).

We’ve been helping dedicated developers to get from low paying jobs to **high tier roles – sometimes in a matter of weeks!** To do so, we continuously run and share free market researches on how to improve your skills with **Empathy, Integrity, and Economics** in mind. If you want to step up in your career, [access now our latest research for free](https://www.essentialdeveloper.com/courses/career-and-market-strategy-for-professional-ios-developers).


## Let’s connect
If you enjoyed this article, visit us at [https://essentialdeveloper.com](https://essentialdeveloper.com) and get more in-depth tailored content like this.

Follow us on: [YouTube](https://youtube.com/essentialdeveloper) • [Twitter](https://twitter.com/essentialdevcom) • [Facebook](https://facebook.com/essentialdeveloper) • [GitHub](https://github.com/essentialdevelopercom)