Facebook Pixel
Searching...
English
EnglishEnglish
EspañolSpanish
简体中文Chinese
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
Bahasa IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Clean Architecture

Clean Architecture

by Robert C. Martin 2017 432 pages
4.23
6k+ ratings
Listen
11 minutes
Listen

Key Takeaways

1. Software architecture is about minimizing human resources and maximizing productivity

The goal of software architecture is to minimize the human resources required to build and maintain the required system.

Architectural decisions matter. Good architecture reduces the effort required to develop, deploy, and maintain software systems. It allows teams to work independently, minimizes the impact of changes, and enables the system to evolve over time.

Key aspects of good architecture:

  • Separation of concerns
  • Dependency management
  • Abstraction of implementation details
  • Flexibility to accommodate future changes

By focusing on these aspects, architects can create systems that are easier to understand, modify, and extend, ultimately leading to increased productivity and reduced costs over the system's lifetime.

2. Clean architecture separates business rules from external details

The center of your application is not the database. Nor is it one or more of the frameworks you may be using. The center of your application is the use cases of your application.

Business rules are the core. Clean architecture organizes code into concentric circles, with business rules at the center and implementation details at the outer layers. This separation allows the core business logic to remain unaffected by changes in external factors such as databases, user interfaces, or frameworks.

Key layers in clean architecture:

  • Entities: Enterprise-wide business rules
  • Use Cases: Application-specific business rules
  • Interface Adapters: Convert data between use cases and external agencies
  • Frameworks and Drivers: External tools and technologies

By adhering to this structure, developers can create systems that are:

  • More flexible and adaptable to change
  • Easier to test and maintain
  • Less dependent on specific technologies or frameworks

3. SOLID principles guide the creation of flexible, maintainable systems

The SOLID principles tell us how to arrange our functions and data structures into classes, and how those classes should be interconnected.

SOLID enhances modularity. These five principles provide guidelines for creating software systems that are more understandable, flexible, and maintainable. They help developers design code that is resistant to changes and easy to extend.

The SOLID principles are:

  • Single Responsibility Principle: A class should have only one reason to change
  • Open-Closed Principle: Software entities should be open for extension but closed for modification
  • Liskov Substitution Principle: Objects of a superclass should be replaceable with objects of its subclasses without affecting the program's correctness
  • Interface Segregation Principle: Many client-specific interfaces are better than one general-purpose interface
  • Dependency Inversion Principle: High-level modules should not depend on low-level modules; both should depend on abstractions

By applying these principles, developers can create more robust and scalable software architectures that can adapt to changing requirements over time.

4. Components are the building blocks of a clean architecture

Components are the units of deployment. They are the smallest entities that can be deployed as part of a system.

Modular design enables flexibility. Components in clean architecture are independently deployable and developable parts of the system. They encapsulate related functionality and have well-defined interfaces, allowing for easier maintenance and modification of the system.

Key characteristics of well-designed components:

  • High cohesion: Related functionality grouped together
  • Low coupling: Minimal dependencies between components
  • Clear interfaces: Well-defined methods of interaction
  • Independent deployability: Can be updated or replaced without affecting other parts of the system

By organizing systems into components, architects can:

  • Facilitate parallel development by different teams
  • Enable easier testing and debugging
  • Allow for incremental updates and improvements to the system
  • Improve overall system scalability and maintainability

5. Boundaries define and protect the core business logic

At each architectural boundary, we are likely to find the Humble Object pattern lurking somewhere nearby.

Boundaries protect the core. Architectural boundaries in clean architecture separate different areas of concern, particularly between business logic and implementation details. These boundaries help maintain the independence of the core business rules from external changes.

Key aspects of architectural boundaries:

  • Use of interfaces to define interactions between layers
  • Dependency inversion to ensure that dependencies point inward
  • Data transfer objects to pass information across boundaries
  • Humble objects to separate testable behavior from hard-to-test components

By establishing clear boundaries, architects can:

  • Minimize the impact of changes in external systems or technologies
  • Facilitate easier testing of core business logic
  • Enable the replacement of implementation details without affecting the core system
  • Improve overall system flexibility and adaptability

6. Clean architecture facilitates test-driven development and independent deployability

A good architecture makes the system easy to change, in all the ways that it must change, by leaving options open.

Testability and flexibility are key. Clean architecture promotes practices that make systems easier to test and deploy independently. By separating concerns and managing dependencies, it becomes simpler to write unit tests for core business logic and to deploy different components of the system separately.

Benefits of clean architecture for testing and deployment:

  • Core business rules can be tested without UI, database, or external dependencies
  • Different components can be deployed independently, allowing for easier updates
  • Changes in one area of the system have minimal impact on others
  • New features can be added with less risk of breaking existing functionality

These characteristics lead to:

  • Faster development cycles
  • Reduced risk in deployments
  • Improved system reliability
  • Greater flexibility in adopting new technologies or changing existing ones

7. Frameworks and databases are implementation details, not architectural elements

Frameworks are tools to be used, not architectures to be conformed to.

Core logic should be framework-agnostic. Clean architecture treats frameworks and databases as external details that should not influence the core business logic. This approach allows for greater flexibility in changing or updating these external elements without affecting the system's core functionality.

Key principles for handling frameworks and databases:

  • Treat them as plugins to the core business logic
  • Use dependency inversion to keep core logic independent
  • Create abstractions for database operations
  • Delay framework and database decisions as long as possible

Benefits of this approach:

  • Easier to change or upgrade frameworks and databases
  • Core business logic remains stable despite external changes
  • Reduced vendor lock-in
  • Improved testability of core system components

8. The web is just another delivery mechanism in clean architecture

The web is a delivery mechanism, and your application architecture should treat it as such.

Business logic is delivery-agnostic. In clean architecture, the web is treated as an external detail, similar to databases or frameworks. This perspective allows the core business logic to remain independent of the specific delivery mechanism, whether it's a web application, desktop app, or API.

Key considerations for web applications in clean architecture:

  • Separate web-specific code from core business logic
  • Use interface adapters to convert between web formats and internal data structures
  • Treat web frameworks as plugins to the core system
  • Design use cases to be independent of web-specific concerns

Benefits of this approach:

  • Easier to adapt the system to different delivery mechanisms
  • Core business logic can be reused across multiple platforms
  • Simplified testing of business rules without web dependencies
  • Greater flexibility in changing or updating web technologies

9. Clean embedded architecture separates hardware concerns from business logic

Although software does not wear out, it can be destroyed from within by unmanaged dependencies on hardware.

Hardware independence is crucial. Clean embedded architecture applies the principles of clean architecture to embedded systems, separating hardware-specific concerns from core business logic. This separation allows for easier updates to hardware components and improved portability of the software.

Key elements of clean embedded architecture:

  • Hardware Abstraction Layer (HAL) to isolate hardware-specific code
  • Device-independent business logic
  • Clear interfaces between hardware and software components
  • Use of dependency inversion to manage hardware dependencies

Benefits of this approach in embedded systems:

  • Easier to port software to new hardware platforms
  • Simplified testing of core logic without hardware dependencies
  • Reduced impact of hardware changes on overall system
  • Improved maintainability and longevity of embedded software

10. Microservices and service-oriented architectures can benefit from clean architecture principles

The architecture of a system is defined by boundaries that separate software elements from one another, and restrict those on one side from knowing about those on the other.

Clean principles apply at all scales. While clean architecture is often discussed in the context of monolithic applications, its principles can be effectively applied to microservices and service-oriented architectures. These principles help maintain the independence and testability of individual services while managing the complexity of distributed systems.

Applying clean architecture to microservices:

  • Treat each microservice as a bounded context with its own clean architecture
  • Use well-defined interfaces for inter-service communication
  • Apply dependency inversion between services
  • Maintain independent deployability of services

Benefits of clean architecture in microservices:

  • Improved modularity and scalability of the overall system
  • Easier to understand and maintain individual services
  • Greater flexibility in evolving and replacing services
  • Reduced coupling between services, leading to more robust systems

Last updated:

FAQ

What's Clean Architecture about?

  • Focus on Software Structure: Clean Architecture by Robert C. Martin emphasizes creating systems that are easy to develop, maintain, and deploy through effective software architecture.
  • Timeless Principles: It outlines principles like SOLID, applicable across various programming paradigms, to guide developers in writing clean, maintainable code.
  • Separation of Concerns: The book advocates for separating business rules from technical details, enhancing flexibility and adaptability in software design.

Why should I read Clean Architecture?

  • Improve Software Design Skills: The book enhances understanding of software architecture, providing practical advice for real-world projects.
  • Timeless Knowledge: Its principles are not tied to specific technologies, ensuring relevance throughout your career.
  • Real-World Examples: Martin shares insights from his extensive experience, offering relatable examples and case studies to simplify complex concepts.

What are the key takeaways of Clean Architecture?

  • Architecture is a Shape: Software architecture is defined by component division and communication, facilitating development and maintenance.
  • Decouple Business Rules: Emphasizes separating business rules from technical details for easier changes and adaptations.
  • Leave Options Open: Good architecture defers technical decisions, allowing flexibility to adapt to changing requirements.

What are the SOLID principles mentioned in Clean Architecture?

  • Single Responsibility Principle (SRP): A class should have one reason to change, reducing complexity and easing maintenance.
  • Open-Closed Principle (OCP): Software entities should be open for extension but closed for modification, minimizing bug risks.
  • Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without altering program correctness.

What is the Dependency Inversion Principle (DIP) in Clean Architecture?

  • High-Level Modules: DIP states high-level modules should not depend on low-level modules; both should depend on abstractions.
  • Abstractions Over Details: Depending on abstractions rather than concrete implementations makes systems easier to modify and extend.
  • Use of Interfaces: Encourages using interfaces to define contracts between components, enhancing testing and maintenance.

How does Clean Architecture define good software architecture?

  • Support for Use Cases: Good architecture must support intended use cases, making them clear and visible within the structure.
  • Minimize Human Resources: It should minimize resources required for development, deployment, and maintenance through careful design.
  • Leave Options Open: A well-designed architecture keeps options open for future changes, crucial for long-term success.

What is the significance of boundaries in Clean Architecture?

  • Separation of Concerns: Boundaries separate system components, ensuring changes in one area don't adversely affect others.
  • Control Over Dependencies: Managing dependencies across boundaries prevents disruptions, leading to a stable system.
  • Facilitate Independent Development: Boundaries allow teams to work independently, enhancing productivity and reducing conflicts.

What is the "Screaming Architecture" concept in Clean Architecture?

  • Architecture Reflects Intent: "Screaming Architecture" means the system's architecture should clearly communicate its purpose and functionality.
  • Use Case Driven: Good architecture is driven by use cases, maintaining clarity and purpose throughout development.
  • Avoid Framework Dependency: Architecture should be centered around business needs, not dictated by frameworks or tools.

How does Clean Architecture address testing?

  • Testable Architectures: Emphasizes architectures that allow unit testing of business rules without external systems running.
  • Humble Object Pattern: Separates hard-to-test code from testable code, focusing on logic without UI or framework complexities.
  • Testing API: Suggests creating a testing API to bypass security constraints, enhancing the ability to test various scenarios.

How does Clean Architecture differentiate between the web and the architecture of a system?

  • Web as a Delivery Mechanism: The web is viewed as a delivery mechanism, not a defining aspect of system architecture.
  • Decoupling Delivery from Logic: Treating the web as a detail allows designing systems agnostic to delivery methods.
  • Focus on Business Logic: Prioritizes business logic and use cases over web delivery specifics, ensuring core functionality remains intact.

What are the risks of using frameworks according to Clean Architecture?

  • Tight Coupling: Frameworks can lead to tight coupling, making technology switches difficult.
  • Overhead and Complexity: Heavy reliance on frameworks can introduce unnecessary complexity and hinder performance.
  • Loss of Control: Over-reliance on frameworks can lead to a rigid system, making changes and adaptations challenging.

What are the best quotes from Clean Architecture and what do they mean?

  • "Your architecture should tell readers about the system, not about the frameworks you used in your system.": Emphasizes architecture reflecting business domain and use cases, not technologies.
  • "Frameworks are tools, not ways of life.": Reminds developers to maintain control over architecture, not be overly reliant on frameworks.
  • "A good architecture makes it unnecessary to decide on Rails, or Spring, or Hibernate, or Tomcat, or MySQL, until much later in the project.": Highlights deferring technology decisions until architecture is established, promoting flexibility.

Review Summary

4.23 out of 5
Average of 6k+ ratings from Goodreads and Amazon.

Clean Architecture: A Craftsman's Guide to Software Structure and Design receives mixed reviews. Many praise its focus on SOLID principles and decoupling, while others find it repetitive and lacking practical examples. Some readers appreciate the historical context and anecdotes, while others feel they detract from the core content. The book is generally seen as helpful for understanding high-level architectural concepts, but opinions vary on its usefulness for beginners versus experienced developers. Several reviewers note that the book's content could have been conveyed more concisely.

Your rating:

About the Author

Robert Cecil Martin, known as Uncle Bob, is a prominent software engineer and advocate for Agile development methods. As President of Object Mentor Inc., he leads a team of consultants specializing in Object-Oriented Design, Patterns, UML, and Agile Methodologies. Martin has extensive experience in the software industry, having served as Editor in Chief of the C++ Report from 1996 to 1999. He is a sought-after speaker at international conferences and trade shows, sharing his expertise on software development best practices. Martin's influence extends beyond consulting, as he has authored several influential books on software craftsmanship and clean coding practices.

Other books by Robert C. Martin

Download PDF

To save this Clean Architecture summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.28 MB     Pages: 13

Download EPUB

To read this Clean Architecture summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 3.00 MB     Pages: 11
0:00
-0:00
1x
Dan
Andrew
Michelle
Lauren
Select Speed
1.0×
+
200 words per minute
Create a free account to unlock:
Requests: Request new book summaries
Bookmarks: Save your favorite books
History: Revisit books later
Ratings: Rate books & see your ratings
Try Full Access for 7 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
All summaries are free to read in 40 languages
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
❤️ Unlimited Bookmarks
Free users are limited to 10
📜 Unlimited History
Free users are limited to 10
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 73,530 books. That's 12,000+ hours of audio!
Day 4: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 7: Your subscription begins
You'll be charged on Feb 27,
cancel anytime before.
Consume 2.8x More Books
2.8x more books Listening Reading
Our users love us
50,000+ readers
"...I can 10x the number of books I can read..."
"...exceptionally accurate, engaging, and beautifully presented..."
"...better than any amazon review when I'm making a book-buying decision..."
Save 62%
Yearly
$119.88 $44.99/year
$3.75/mo
Monthly
$9.99/mo
Try Free & Unlock
7 days free, then $44.99/year. Cancel anytime.
Settings
Appearance
Black Friday Sale 🎉
$20 off Lifetime Access
$79.99 $59.99
Upgrade Now →