Clean Architectures in Python - presented by Leonardo Giordani

EuroPython Conference
2 Nov 202247:48

Summary

TLDRIn this insightful talk, the speaker explores the concept of 'Clean Architecture' in Python, emphasizing the principles of durability, utility, and beauty in system design. Drawing from Vitruvius and modern interpretations, the presentation delves into the layered approach of software structuring, advocating for clear separation of concerns to enhance testability and customization. The speaker contrasts this with the 'Jungle Architecture' of Django, highlighting the trade-offs between out-of-the-box solutions and customizable systems. The talk concludes with practical advice on adopting clean architecture incrementally and the speaker's personal reflections on the beauty of well-organized code.

Takeaways

  • 📚 The speaker emphasizes the importance of considering code as an architecture, needing to be durable, useful, and beautiful, drawing parallels with the classical architectural principles of Vitruvius.
  • 🤔 The talk provokes thought on how often developers consider the longevity and aesthetics of their code, alongside its utility, challenging the audience to view coding through a broader architectural lens.
  • 🏗️ Clean architecture is introduced as a concept by Robert C. Martin, promoting a layered approach to software design that enhances maintainability and testability, with a focus on business logic at the core.
  • 🔄 The principle of clean architecture involves a unidirectional dependency rule, where inner layers define simple structures and outer layers implement interfaces, to prevent tangled dependencies.
  • 🛠️ The speaker illustrates the clean architecture with a Python example, demonstrating the separation of concerns between the use cases, entities, and external systems like databases or web frameworks.
  • 🔍 The benefits of clean architecture include improved testability due to the isolation of components, allowing for unit testing of business logic without reliance on external systems.
  • 🛑 The speaker advises against a complete rewrite to adopt clean architecture, recommending incremental changes and leveraging existing infrastructure to avoid the risks associated with full-scale overhauls.
  • 📈 The potential for customization and flexibility in clean architecture is highlighted, as it allows for different storage solutions and front-end presentations without affecting the core business logic.
  • 🤝 The talk concludes with a comparison between clean architecture and other architectures like Django's, suggesting that the choice of architecture should be informed by specific project requirements rather than a one-size-fits-all approach.
  • 🎨 The concept of beauty in code is discussed as a personal and subjective experience, related to the elegance and harmony of how components interact within the architecture.
  • 📚 The speaker mentions offering a free book on clean architecture, indicating a resource for those interested in learning more about the principles and their application in Python.

Q & A

  • What is the main theme of the talk titled 'Clean Architectures in Python: A Tale of Durability, Utility, and Beauty'?

    -The main theme of the talk is to explore the concept of clean architecture in Python, emphasizing the importance of creating systems that are durable, useful, and beautiful, inspired by the principles of the Roman architect Vitruvius.

  • What are the three key attributes of architecture as defined by Vitruvius?

    -Vitruvius defined the three key attributes of architecture as firmitas (durability), utilitas (utility), and venustas (beauty).

  • Why is the concept of 'engineer' relevant to the discussion of architecture in software design?

    -The concept of 'engineer' is relevant because it originates from 'ingenuity' in Latin, highlighting the importance of clever problem-solving in software architecture, not just mechanical aspects.

  • What are the two definitions of architecture provided by the speaker, and how did they merge them into a single definition?

    -The two definitions are: 1) The art and science of designing and making buildings, and 2) The internal organization of computer components with a focus on data transmission. The speaker merged them into 'the art and science in which the components of a computer system are organized and integrated'.

  • What is the significance of the example of the Samoan bridge in the context of software architecture?

    -The Samoan bridge example illustrates the idea that just as the bridge's design enhances the journey, software architecture should not only serve its functional purpose but also improve the overall experience, possibly by making the code more maintainable or enjoyable to work with.

  • What does the speaker mean by 'messages' in the context of object-oriented programming and distributed systems?

    -In the context of object-oriented programming, 'messages' refer to method calls on objects. The speaker suggests that viewing these method calls as messages can change one's perspective on code, considering it as part of a distributed system where objects exchange messages.

  • What is the 'clean architecture' as introduced by Robert Martin, and how does it differ from traditional software architecture?

    -Clean architecture, introduced by Robert Martin, is a layered approach to structuring software projects where components can only depend on inner layers. It differs from traditional architectures by enforcing strict separation of concerns and reducing dependencies, making the system more maintainable and scalable.

  • What is the 'Golden Rule' of clean architecture, and how does it apply to the components of a system?

    -The 'Golden Rule' of clean architecture is to 'talk inward with simple structures, outwards through interfaces.' This means that components within the system should communicate using simple data structures and rely on interfaces to interact with external components or systems.

  • How does the speaker define 'testability' in the context of clean architecture, and why is it an advantage?

    -Testability in the context of clean architecture refers to the ability to isolate and test components independently of the rest of the system. It is an advantage because it allows developers to verify the correctness of business logic without relying on external systems or databases.

  • What is the difference between the 'clean architecture' and the 'jungle architecture' as exemplified by Django?

    -The 'clean architecture' focuses on strict layering and separation of concerns, allowing for greater flexibility and testability. In contrast, the 'jungle architecture' of Django tightly couples the web framework with the business logic and database, making it less flexible but potentially simpler for rapid development of web applications.

  • What advice does the speaker give for transitioning to a clean architecture, and why?

    -The speaker advises against a complete rewrite of existing systems when transitioning to clean architecture. Instead, they recommend making incremental changes, starting with small, isolated parts of the system. This approach minimizes risk and allows for quick rollback if needed, following the example of Netscape's failed attempt to rewrite their browser from scratch.

Outlines

00:00

🏛 Introduction to Clean Architecture in Python

The speaker begins by expressing gratitude for the audience's presence and introduces the topic of 'Clean Architectures in Python,' focusing on the principles of durability, utility, and beauty. They aim to share insights on system design and engage with those interested in the field. The speaker is a developer and blogger who writes about Python, TDD, OOP, cryptography, and infrastructure. They delve into the meaning of architecture, referencing Vitruvius's concepts of firmitas, utilitas, and venustas, and question how often we consider our code in terms of these attributes. The speaker also discusses the etymology of the word 'engineer' and provides a modern definition of architecture, emphasizing the art and science of organizing and integrating computer system components.

05:03

🌉 The Importance of Aesthetics and Longevity in Code

The speaker continues the discussion by questioning the need for code to be useful, durable, and beautiful, using the example of the Samuel Beckett Bridge in Dublin to illustrate the enhancement of user experience through design. They highlight the Unix operating system, designed over 50 years ago, as an example of lasting design. The speaker recommends five key books on system design, emphasizing the importance of understanding the challenges and solutions in system architecture. They also touch on the concept of object-oriented programming as a form of messaging and the significance of considering code as a form of art.

10:03

🔍 Defining Clean Architecture and Its Components

The speaker defines 'clean architecture,' a concept introduced by Robert C. Martin, as a layered approach to structuring software projects. They describe the traditional four layers: entities, use cases, gateways, and external systems, and the rule that components can only depend on inner layers. The speaker explains the importance of avoiding circular dependencies and the principle of 'talk inward with simple structures outwards through interfaces.' They introduce the idea of interfaces in the context of dependency injection and the role of simple structures like data types in clean architecture.

15:07

🛠️ Implementing Clean Architecture with Python Example

The speaker presents a simple Python example to illustrate clean architecture, starting with a use case function in the use cases layer and defining entities in the entities layer. They discuss the use of a web framework, such as Flask, in the external systems layer to handle HTTP requests and translate them into function calls. The speaker emphasizes the importance of the business logic being separate from the web framework and the use of simple structures like dictionaries for communication between layers.

20:09

🗃️ The Role of Repositories and Databases in Clean Architecture

The speaker explains the concept of a repository in clean architecture, which acts as a source of data and can be more than just a database, such as a web API or a set of text files. They stress that the repository is in the external systems layer because it is not part of the core business logic. The speaker also discusses the importance of separating the use case from the database through a database interface, which allows for the use case to be independent of the specific database implementation.

25:12

🔄 The Data Journey in a Clean System and Dependency Injection

The speaker outlines the journey of data in a clean system, from the web framework to the use case and then to the database interface, emphasizing the use of dependency injection to pass instances of database interfaces to the use case. They discuss the importance of the database interface converting database values into entities and the use case adding business logic to these entities. The speaker also highlights the separation of concerns between the business logic and the details of data storage and retrieval.

30:14

📈 Advantages of Clean Architecture: Testability and Customization

The speaker discusses the advantages of clean architecture, particularly its impact on testability and customization. They explain how clean architecture allows for the easy isolation and testing of business logic, web frameworks, and database interfaces. The speaker also touches on the flexibility of clean architecture to accommodate different database systems and front-end presentations without altering the core business logic.

35:16

🌐 Comparing Clean Architecture with Other Architectures like Django

The speaker compares clean architecture with other architectures, specifically calling out Django's 'jungle architecture.' They highlight the differences in how Django's models are tightly coupled with the database and the framework's views are connected to URLs, making it challenging to test and customize without the framework's built-in components. The speaker emphasizes that while Django is a powerful framework, it represents a different approach with its own set of trade-offs.

40:17

🛑 Transitioning to Clean Architecture and Avoiding Rewriting Pitfalls

The speaker advises against a complete rewrite when transitioning to clean architecture, referencing the downfall of Netscape as a cautionary tale. They recommend incrementally applying clean architecture principles to small parts of an existing system and using load balancers to manage the transition. The speaker also suggests considering the specific requirements of a project when choosing an architecture.

45:18

❓ Q&A Session and Addressing Concerns about Duplication and Beauty

The speaker concludes with a Q&A session where they address concerns about potential duplication in clean architecture and the elusive nature of beauty in software design. They clarify that while there may be some duplication, particularly in the definition of models and database interfaces, the separation is beneficial for maintaining a clear distinction between business logic and data storage. The speaker also shares their personal perspective on the beauty of a well-organized system where components interact harmoniously.

Mindmap

Keywords

💡Clean Architecture

Clean Architecture is a software design pattern introduced by Robert C. Martin that emphasizes separation of concerns, making the system more understandable, flexible, and maintainable. In the video, the concept is linked to the principles of firmitas (durability), utilitas (utility), and venustas (beauty) as defined by Vitruvius, suggesting that a well-architected system should not only be robust and functional but also elegant. The speaker uses this concept to guide the audience through the principles of creating a system that is easy to maintain and extend over time.

💡Durability

Durability, as mentioned by Vitruvius and referenced in the video, is one of the three core principles of architecture, alongside utility and beauty. In the context of software, durability refers to the longevity and resilience of the system, its ability to withstand changes over time without needing complete overhauls. The speaker reflects on how often software developers might neglect durability in favor of short-term solutions, using the example of Unix, which has lasted for decades, to illustrate the importance of creating long-lasting systems.

💡Utility

Utility in architecture and software design refers to the practicality and usefulness of a system. The video emphasizes that while developers often focus on creating useful software, the principles of clean architecture can enhance this utility by ensuring the system serves its purpose effectively and efficiently. The speaker uses the term to highlight the need for systems that are not just functional but also designed to meet user needs and business requirements.

💡Beauty

Beauty, in the context of the video, is used metaphorically to describe the aesthetic quality of code and system design. It is suggested that just as physical architecture can be beautiful, so too can software be elegant and pleasing in its structure. The speaker encourages developers to consider the beauty of their code, implying that well-structured, clean code can be as satisfying to create and maintain as a beautifully designed building.

💡System Design

System design is the process of defining the architecture, components, modules, and data flows of a system. The video discusses the importance of system design in creating software that is durable, useful, and beautiful. The speaker shares their views on system design and provides insights into how considering architectural principles can lead to more sustainable and adaptable software solutions.

💡Dependency Injection

Dependency injection is a software design pattern that allows for the separation of concerns by injecting dependencies (like database interfaces) into a class or function at runtime rather than hard-coding them within the class itself. In the video, the speaker explains how dependency injection is used in clean architecture to make the system more modular and testable, by allowing components to receive instances of their dependencies from outside.

💡Use Cases

In the context of the video, use cases refer to specific actions or behaviors that a system should support. The speaker discusses the use cases layer in clean architecture, which encapsulates the business logic of the application. Use cases are central to the design, as they define how the system responds to user interactions and other stimuli, and they should be isolated from the details of data storage and presentation.

💡Entities

Entities in the video are used to represent the core business data or concepts within the system. They are the building blocks of the business logic and are distinct from the data storage mechanisms. The speaker explains that entities in clean architecture are known to all other components and are used to encapsulate the data that is relevant to the business domain.

💡Gateways

Gateways in the clean architecture model refer to the components that handle external interactions, such as database access or communication with web services. The video script mentions gateways as part of the outer layers of the architecture, which are responsible for translating between the internal system components and external systems or data sources.

💡Testability

Testability is a measure of how easily a piece of software can be tested. The video emphasizes the importance of testability in clean architecture, as it allows for the isolation of components such as use cases and gateways for individual testing. The speaker argues that clean architecture enhances testability by separating business logic from external details, enabling developers to test core functionalities independently of external systems.

💡Integration Test

An integration test is a type of software testing that checks the interfaces between units/modules to ensure they work together as expected. In the video, the speaker mentions integration tests in the context of testing the repository interface with a database, which is necessary to ensure that the system components work correctly when combined, even though it might be a slower process due to the involvement of actual database operations.

Highlights

The concept of clean architecture in Python is introduced, emphasizing durability, utility, and beauty in system design.

Vitruvius' principles of architecture are related to modern software design, suggesting that code should be durable, useful, and beautiful.

The speaker's background as a developer and blogger is shared, focusing on topics like Python, TDD, and infrastructure.

Architecture is defined as the art and science of organizing and integrating computer system components.

The importance of considering code as an art form, alongside science, is discussed to encourage better design practices.

Examples given from traditional architecture and the Unix system illustrate the principles of useful, durable, and beautiful design.

Five influential books on system design are recommended, with an emphasis on understanding the patterns and challenges in system architecture.

The idea that object-oriented programming is about objects exchanging messages is related to distributed systems and microservices.

Clean architecture is explained as a layered approach to structuring software, with rules on dependencies and component visibility.

The 'talk inward with simple structures, outwards through interfaces' rule is introduced as a key principle of clean architecture.

A simple Python example demonstrates the application of clean architecture principles in code.

The separation of business logic from external systems like databases and web frameworks in clean architecture is highlighted.

The advantages of clean architecture, particularly in terms of testability and customization, are discussed.

A comparison is made between clean architecture and other architectures like Django's, noting the differences in approach and philosophy.

The importance of incremental changes when adopting clean architecture is stressed to avoid the pitfalls of rewriting systems from scratch.

The speaker offers a free book on clean architecture in Python, demonstrating the concepts with practical examples and TDD.

Questions from the audience address concerns about potential duplication in clean architecture and the elusive nature of beauty in software design.

Transcripts

play00:05

thank you for being here so the title of

play00:09

my talk today is clean architectures in

play00:11

Python A Tale of durability utility and

play00:15

beauty

play00:16

and my goal today is so I'm here because

play00:19

I want to share my views on system

play00:22

design

play00:24

and give you an example of what I

play00:26

discovered and what I learned and maybe

play00:28

meet people who are interested in system

play00:31

design as well

play00:33

so this is me well not a picture of me

play00:38

but you know I'm a developer and a

play00:41

blogger you are welcome to visit my blog

play00:43

I usually write about python obviously

play00:46

tdd object oriented cryptography and

play00:50

infrastructure these are the main things

play00:52

I like to write about

play00:56

so today it's a talk about the clean

play00:59

architecture and I want to start

play01:02

with a question thinking a bit about

play01:05

what architecture is

play01:07

we mentioned architecture many times the

play01:10

architecture of a system or what is it

play01:13

what is it definition

play01:15

so I found this in a book that has been

play01:19

around for a while the architecture it

play01:22

means about architecture

play01:24

it's been written a couple of thousands

play01:27

years ago

play01:29

the two views who was a Roman architect

play01:33

and engineer

play01:35

says that architecture is about firmitas

play01:39

utilitas and venustas which translated

play01:42

in Modern English is durability

play01:46

utility and beauty

play01:48

so Vitruvius says that architecture is

play01:52

about things that are durable something

play01:56

that has to last

play01:58

has to be useful has to be beautiful

play02:02

and for me this was very interesting

play02:04

because how many times

play02:07

do you think about your code as

play02:10

something that has to be useful

play02:12

beautiful and durable

play02:15

useful yes nobody wants to write

play02:18

something that is useless

play02:20

but what about durable

play02:23

we change framework every two years now

play02:26

right every six months I don't know so

play02:28

having something that lasts

play02:30

and beautiful that's the thing I'm

play02:33

mostly concerned about

play02:36

it's interesting let me mention this

play02:38

that vituvius was an engineer and an

play02:41

architect

play02:43

and

play02:44

these two professions don't go together

play02:47

that much nowadays um it's interesting

play02:50

to think that engineer the word comes

play02:53

from engine

play02:54

but engine comes we we when we discuss

play02:58

about engines we think about something

play03:00

mechanical

play03:01

but engine actually comes from

play03:04

um Ingenuity in Latin it's from

play03:08

cleverness

play03:09

so it's less about mechanical things is

play03:12

more about solving a problem in a clever

play03:15

way

play03:16

anyway I went on and I checked also on

play03:20

the dictionary Modern English dictionary

play03:22

and I found these two interesting

play03:24

definitions of architecture

play03:27

one is the Art and Science of Designing

play03:29

and making buildings

play03:31

and the second one is more

play03:33

concerned with computers and it says the

play03:36

internal organization of computers

play03:38

components with particularly the

play03:40

reference to the way in which data is

play03:42

transmitted I like these two definitions

play03:44

I wanted to come up with something a bit

play03:46

more compact

play03:47

so I try to merge them into this which

play03:51

is the Art and Science

play03:53

in which the components of a computer

play03:55

system are organized and integrated

play04:00

I want to stress

play04:01

Art and Science

play04:04

how many times do you think about what

play04:06

you do daily as Art and Science

play04:10

as science yes data science computer

play04:13

science

play04:14

mechanical path right

play04:16

what about art

play04:19

when do you look at your code and think

play04:21

this is art

play04:22

why is it not data art it's not computer

play04:25

art not as in you know painting

play04:28

something with the computer but our code

play04:31

is beautiful or it can be

play04:33

and the other two interesting words here

play04:36

are organized and integrated because a

play04:39

system architecture when we when it

play04:41

comes to computer science is all about

play04:43

where components of the system are and

play04:47

how data flows between them

play04:51

so this is the integration part

play04:54

cool now that I defined architecture

play04:58

the following question is do we need it

play05:02

so do we need things our code to be

play05:06

useful durable and beautiful

play05:10

and this is up to you I positive about

play05:13

this otherwise it wouldn't be here

play05:15

but I want to give you a couple of

play05:17

examples and one comes from the

play05:21

traditional architecture and it's the

play05:24

page that is in front of this building

play05:26

the Samoa backup page

play05:29

it's interesting I was looking at it

play05:31

these days and I thought

play05:33

does this bridge have to be shaped like

play05:36

an heart

play05:39

if the requirement of the page is just

play05:42

to take cars from one side to the other

play05:45

it doesn't have you just need a plain

play05:48

Bridge right something that I could

play05:50

design because I don't know anything

play05:51

about which design

play05:54

but if the requirement is to make your

play05:57

journey better

play05:59

well being shaped like a hub in Dublin

play06:03

is a nice thing to have

play06:05

so this is Food For Thought maybe you

play06:09

know like what is the requirement of

play06:11

your code what what is it that you are

play06:13

creating when you create a library do

play06:15

you just create some Machinery or do you

play06:16

create something to make the journey

play06:18

better

play06:19

the other example I have it's about

play06:21

something lasting a long time

play06:24

um

play06:25

the Unix system it's an operating system

play06:28

was designed in 71 so 50 years ago

play06:31

and it was well thought

play06:35

not everything in a unique system is

play06:38

perfect okay sometimes it's far from it

play06:41

but it was well thought

play06:44

so well designed that I am running a

play06:47

Linux machine and Linux is a clone of

play06:49

Unix and many of you use Mac OS which is

play06:53

a derivative of Unix 50 years

play06:57

so again how many times do you look at

play07:00

your code the code that you write and

play07:02

you think

play07:03

in 50 years people are still we will

play07:05

still use this code or at least these

play07:08

ideas

play07:10

anyway I'm not the only one who thinks

play07:13

that system design is an interesting

play07:15

thing

play07:16

um there are much smarter people than me

play07:18

who wrote a lot of books there are vast

play07:21

literature about this I selected five

play07:24

books that I read which I believe are

play07:27

interesting about the topic

play07:30

some of these are door stoppers pretty

play07:34

thick okay so if you are not up for the

play07:36

challenge I recommend retrieving at

play07:39

least the two in Orange so design

play07:41

patterns and Enterprise Integration

play07:43

patterns at least

play07:46

read the introduction

play07:49

and I'm not joking the introduction to

play07:52

these two books the two introductions

play07:54

are short

play07:56

but they give you a narrative of the

play07:59

challenges and some of the solutions

play08:01

that you might have when you design a

play08:04

system

play08:05

and I was

play08:07

um I was really

play08:08

you know flabbergasted when I read the

play08:12

introduction to design patterns because

play08:14

it was like Hey I faced these issues

play08:17

every day

play08:20

I want to mention another thing about

play08:21

Enterprise Integration patterns this is

play08:24

a book about messaging message based

play08:27

systems more about distributed systems

play08:30

if you want

play08:32

but it's interesting that message based

play08:35

systems microservices for example

play08:38

this software design and languages they

play08:43

are all in the same league they share a

play08:46

common trait

play08:48

which is messages

play08:52

object oriented programming and you can

play08:54

quote me on this is supposed to be

play08:57

about objects that exchange messages

play09:02

so every time you call a method on an

play09:04

object you are sending a message to

play09:06

something

play09:07

so it sees a distributed system

play09:10

and if you if you think about that if

play09:12

you when you code in Python if you think

play09:14

about messages this might not change the

play09:16

code itself because you are still

play09:18

calling methods but it will definitely

play09:21

change the way you think about your code

play09:24

it's a bunch of objects it's a

play09:27

distributed system and I'm exchanging

play09:29

messages anyway this might be for

play09:32

another talk another time now that I

play09:34

defined architecture and I decided for

play09:37

you that we need it

play09:40

let me Define clean because this is

play09:43

about a clean architecture

play09:45

um I found it

play09:47

easy to define the opposite of clean the

play09:51

picture in the background if you look at

play09:53

that system

play09:54

you can definitely say this is not clean

play09:57

it's not tidy good luck maintaining

play10:00

something like that okay they said pull

play10:03

the green cable yeah good luck okay this

play10:07

is an extreme example probably but

play10:11

sometimes our code looks like that right

play10:14

you change something and suddenly

play10:16

everything crashes nothing works anymore

play10:19

instead in a clean system with a tidy

play10:21

system if you want you have these

play10:26

characteristics for for each component

play10:29

you know the three W's right you know

play10:33

where it is it's easy to find the

play10:35

component in the system it's isolated

play10:38

you know what it is from the name for

play10:41

example and you know why it is in the

play10:43

system you can say why it's been

play10:46

included in the pictures in the

play10:48

background there are two just you know

play10:49

hardware systems um and they are tidy

play10:52

it's easy to trace where our cable goes

play10:55

some are color coded so it's easy to

play10:59

understand you know why they are there

play11:00

what they are what they are doing

play11:05

okay now that I Define the claim

play11:07

architecture in terms of the words let's

play11:10

go for the concept for an example

play11:14

so what is the clean architecture

play11:18

it is a concept that was introduced by

play11:20

Robert Martin uh some years ago Herbert

play11:22

Martin is a system engineer system and

play11:25

designer you know a developer and I'm

play11:27

not here to advertise Robert Martin's

play11:30

work mostly because Robert Martin is

play11:33

very good at advertising himself you

play11:36

know so

play11:38

um but I'm gonna use the same name uh

play11:41

it's it's important for me to stress

play11:43

that the concepts that Robert Martin

play11:46

dubbed the clean architecture uh predate

play11:50

his work so they have been around for a

play11:53

long while

play11:55

so let's call it the clean architecture

play11:57

but it's a set of Concepts such and that

play12:00

predates what Robert Martin did what is

play12:03

it it's a layered approach so it's a way

play12:07

to structure your software

play12:10

um project right you your code it's

play12:13

layered and it's circular

play12:16

so in the traditional

play12:18

[Music]

play12:19

say definition we have four layers you

play12:23

can have more of them but this these are

play12:25

the traditional ones entities use cases

play12:28

gateways and external systems

play12:31

what happens is that when you create

play12:33

something in a clean architecture this

play12:36

something this component will belong to

play12:39

one of these layers and there are rules

play12:42

there is actually one simple rule one

play12:46

rule at least

play12:48

which is that your component can see

play12:54

I'm going to Define what C is can see

play12:57

only what has been defined in an inner

play12:59

layer

play13:00

so if you create something in the use

play13:02

cases layer or ring

play13:06

you can see everything that has been

play13:08

defined in the same layer use cases and

play13:10

everything that has been defined in

play13:12

entities you are not allowed to use to

play13:15

access anything that has been defined

play13:17

outside

play13:19

and that that has to do with

play13:21

dependencies

play13:23

the problem of unclean systems remember

play13:26

the cables before is dependencies

play13:30

between

play13:31

components when you have a component

play13:33

that depends on other components and

play13:36

these other components depends on other

play13:37

components and you can't trace these

play13:40

dependencies and sometimes they are

play13:41

circular dependencies

play13:43

in a clean architecture there are no

play13:45

circular dependencies

play13:46

the Golden Rule I'm going to introduce

play13:49

it now and then show you an example that

play13:51

clarifies it is that you talk inward

play13:54

with simple structures outwards through

play13:56

interfaces what does it mean simple

play13:59

structures

play14:01

are data types that have been defined

play14:06

in inside so for example again something

play14:09

in use cases can use data types and I

play14:12

mean data types in Python for example

play14:15

you can instantiate them if they have

play14:17

been defined in use cases and if they

play14:20

have been defined in entities

play14:22

if something has been defined in

play14:24

external systems you don't see it you

play14:27

can't instantiate it

play14:30

interfaces interfaces have to do

play14:34

um so they they are related to

play14:36

dependency injection which is something

play14:38

I will introduce later

play14:40

what is an interface

play14:43

um going back to what I said about

play14:44

objects and sending messages when you

play14:47

send a message to something you expect

play14:49

it to be able to receive that message

play14:51

when you call a method on an object you

play14:54

expect that object to well have that

play14:57

method right otherwise you'll get an

play14:59

exception in Python we don't have an

play15:02

explicit way to State infrastructure in

play15:06

interfaces okay to create them even

play15:09

though we have now protocols we have

play15:12

abstract based classes there are many

play15:14

ways to work with interfaces and we can

play15:17

discuss about this another time because

play15:18

there is no enough time today anyway I'm

play15:21

coming back to this slide later when

play15:24

after the example

play15:27

the example today is simple

play15:30

the code I will show is python it's

play15:33

valid python but I stripped all the you

play15:36

know error checking a lot of things that

play15:38

are not useful for now obviously they're

play15:40

real the real code is a bit more

play15:43

complicated

play15:44

my use case is to retrieve a list of

play15:48

items is very simple

play15:50

when do we want to achieve a list of

play15:52

items I don't know you have a social

play15:54

network and you want to retrieve a list

play15:56

of posts right or you are Amazon you

play15:59

want to send Using to show a list of

play16:01

proper items that you are selling

play16:05

in this example my use case is just a

play16:08

simple function it exists in the use

play16:10

cases layer

play16:12

and for the time being it doesn't do

play16:15

anything

play16:17

then I Define some entities entities are

play16:20

models okay they represent real items

play16:25

that are in my business logic

play16:27

so in this case for example something

play16:29

with a code and a price okay just a

play16:31

simple class that captures data

play16:34

encapsulates data

play16:37

the entities leave in the entities layer

play16:40

and they are known to all other

play16:42

components

play16:45

it's 2022 so we probably want to build a

play16:49

web application but this is not required

play16:52

okay it's just an example

play16:54

the web application

play16:56

requires a web framework because I don't

play16:59

want to implement you know the logic to

play17:01

deal with HTTP requests and all these

play17:04

things there are smarter people who did

play17:06

for me

play17:07

in this case I'm using flask

play17:09

but I can use any other web framework

play17:11

the web framework exists in the external

play17:14

systems and I want to say a couple of

play17:17

things about this

play17:18

um

play17:20

I mentioned business logic before the

play17:23

business logic is what you Market

play17:26

is the core of your application

play17:29

the web framework is not generally

play17:32

speaking part of your business logic you

play17:35

are not marketing Django you're not

play17:38

marketing flask you are marketing a

play17:41

social network your marketing items

play17:43

delivery whatever right

play17:45

so it's reasonable for the web framework

play17:49

to be in a very external layer where we

play17:52

use it but we don't manipulate it

play17:56

the core

play17:58

um the most important thing in a clean

play18:00

architecture I would say in any

play18:02

architecture is the business logic this

play18:04

is what 99 of your time should go

play18:08

anytime you every time you spend you

play18:11

know configuring external systems it's

play18:14

not wasted but it's not given to the

play18:16

core of your business

play18:18

anyway this is the web application the

play18:22

web framework

play18:25

now what is the task of the web

play18:27

framework

play18:29

the web framework is there because it

play18:31

wants it has to translate HTTP requests

play18:36

into course

play18:38

this is all a web framework has to do

play18:41

granted it's not an easy task okay there

play18:43

are many things involved but this is

play18:46

what the web framework should do get an

play18:49

HTTP request and transform it into a

play18:52

call for example for a python function

play18:54

in this case this is exactly what I'm

play18:56

doing I'm calling the use case which is

play19:00

a function

play19:02

here you see that the web framework

play19:05

communicates with the use case with

play19:08

simple structures what does it mean in

play19:11

this case I'm using request args for the

play19:13

sake of you know Simplicity it's just a

play19:16

dictionary

play19:17

and it's a simple structure because it

play19:19

has been defined in the in the language

play19:21

right so it it might be an entity or it

play19:25

might be something that the language

play19:26

defines all these things exist in Python

play19:30

so whatever is defined in python as a

play19:32

core language is available

play19:34

so I'm sending to um the use case as

play19:40

simple structure something that the use

play19:42

case can understand

play19:44

for example I shouldn't send anything

play19:46

that is defined in the web framework

play19:48

some structure that has been defined

play19:51

there a type that flask uses to manage

play19:54

an HTTP request because the use case

play19:56

doesn't do anything doesn't know

play19:58

anything about HTTP request and it

play20:01

shouldn't know anything

play20:05

okay then we have to retrieve items and

play20:09

data data is stored usually in a

play20:13

repository and we are used to think

play20:15

about the repository as a database which

play20:17

is what I have in the example here

play20:19

but I want to stress that a repository

play20:22

is much more than a database for

play20:24

starters it doesn't have to be a

play20:26

relational database it might be no SQL

play20:30

mongodb for example or it might be

play20:33

something different for example a web

play20:36

API

play20:37

it's a source of data right you code the

play20:40

API you get data it sucks exactly what

play20:42

you do with the database

play20:44

it might be a bunch of text files which

play20:46

is a rudimentary database it might be a

play20:50

hardware sensor that is a source of data

play20:53

it's a repository okay so let's think

play20:56

about it as a database I'm going to say

play20:58

database probably a lot of times but the

play21:01

repository is the right word here

play21:06

and the database the repository exists

play21:10

in the in the external systems layer

play21:13

because again it's something that is not

play21:16

part of my core business it's not my

play21:18

business logic

play21:20

in system design we usually call the web

play21:23

framework the database everything that

play21:25

is outside as a detail we call it a

play21:28

detail and many many times it surprises

play21:31

people because they are like what

play21:33

details I mean configuring postcodes you

play21:35

know and all these things is complicated

play21:37

it's not it's not secondary it's not

play21:39

just so simple a detail means that it's

play21:44

not part of the business logic this is

play21:47

not what I'm marketing if my product

play21:49

works with postgres or works with

play21:52

mongodb

play21:53

you are not concerned you as a client

play21:55

are not concerned

play21:57

your problem is to receive a service

play21:59

so this is why it is a detail while the

play22:04

specific algorithm I use for my

play22:06

recommendation system for example is the

play22:08

core business is what you like of my

play22:11

product

play22:12

okay so this is the difference between a

play22:15

Core Business logic and a detail so the

play22:18

database is a detail even though it

play22:20

might be complicated

play22:22

however itex is in the external systems

play22:24

so as I said before the use case is not

play22:28

allowed to communicate directly with the

play22:31

database in Python terms

play22:35

um the use case is not allowed to

play22:37

instantiate anything that is

play22:40

tightly coupled with the database that

play22:43

is connected with the database directly

play22:45

because if I had code in my use case

play22:48

something which is I don't know postgres

play22:51

a library for to interact with postgres

play22:53

or to interact with mongodb I am

play22:56

coupling my use case with the

play22:58

implementation of the database

play23:00

and this is not good because at that

play23:03

point I have my core business my core

play23:05

business logic

play23:07

coupled with a detail which might change

play23:10

my mind might not be the same thing in

play23:13

time

play23:14

so I create an interface this is um in

play23:18

this case we are talking about python

play23:20

it's an object that provides a facade

play23:23

okay so a set of methods that are common

play23:26

to databases

play23:29

so the web framework instantiates the

play23:34

um

play23:36

database interface or the repository

play23:38

interface the web framework can do it

play23:40

because it's in an outer layer so the

play23:42

web frame sees can see what's in the

play23:46

gateways

play23:47

and passes the so it sends the in

play23:52

instance of the possible in this case to

play23:55

the use case this is called dependency

play23:58

injection if you are not familiar with

play24:00

the concept I have a slide for that

play24:02

later but look at it

play24:05

the use case the code of my use case

play24:08

doesn't have postgres or apple

play24:10

hard-coded in it I'm receiving an object

play24:13

that provides methods that might be an

play24:16

object of postgres repo mongodb repo

play24:19

type whatever the important thing is the

play24:22

interface

play24:25

or the set of methods that are that

play24:27

thing provides

play24:30

cool now internally I'm in the use case

play24:33

now and I have finally my business logic

play24:36

okay this is where my brain comes into

play24:40

play right I have to write something

play24:42

that implements the recommendation

play24:44

system the whatever filtering you want

play24:48

eventually sooner or later I have to use

play24:50

the database interface to retrieve the

play24:53

data so in this case I'm calling repo

play24:55

list okay passing the parameters that I

play24:58

received from the HTTP request

play25:00

or from outside I should say right where

play25:04

they come from is not important

play25:06

the business logic might be for example

play25:09

to prepare the parameters to add some

play25:12

filtering you know or to do something

play25:13

else

play25:16

anyway back to the database interface

play25:19

I'm calling repo list okay here right

play25:22

police so I'm in the database interface

play25:24

now and the database interface is

play25:27

tightly coupled with the database that

play25:30

is postgres repo so it's it has been

play25:33

designed to work with postgres okay it's

play25:37

in the name

play25:38

so the two

play25:40

um communicate with a specific language

play25:42

in this case I'm using SQL Alchemy it's

play25:46

an object or additional mapper but

play25:48

eventually I'm in um in a mindset of

play25:53

querying a relational database this is

play25:56

what I'm doing here okay I'm I'm

play25:58

committed to relational databases at

play26:02

this point and this is what I'm doing so

play26:04

the two things are tightly coupled

play26:07

or the database interface does is to as

play26:10

I said the query the database and then

play26:12

it transforms the output of the database

play26:15

the database just sends me values right

play26:17

it's it's SQL so just standard types

play26:22

known to SQL databases

play26:25

the database interface has the task to

play26:28

convert those values into entities

play26:31

because at this point everybody can see

play26:34

entities as a layer it's a very inner

play26:37

layer so the database interface can say

play26:40

okay these SQL values that I get become

play26:44

items

play26:46

as in items that I defined

play26:49

and these items are sent back to the use

play26:52

case as a result of the repo list at

play26:56

this point I can add more business logic

play26:58

okay just to say that obviously if you

play27:00

want to if you have to call your

play27:04

repository you can do it at any time and

play27:06

your business logic is around that code

play27:08

is where you augment these results okay

play27:12

with your algorithms with your

play27:14

cleverness

play27:16

your product

play27:18

at this point the use case has the

play27:21

results and it can send it back to the

play27:26

web framework or to whatever called it

play27:30

and the web framework so this is again

play27:32

sorry entities the web framework can

play27:35

knows about entities so this can still

play27:39

be

play27:40

um

play27:41

an entity a model that I created

play27:45

the web framework again has one task

play27:49

that of converting the entities which

play27:52

are specific models of my business into

play27:56

something that is understandable outside

play27:58

for example Json

play28:02

okay this is the task of the web

play28:05

framework my use case doesn't know

play28:07

anything about Json it doesn't care

play28:09

because the use case is okay with

play28:11

entities it's part of my business

play28:15

this is the Journey of the data in a

play28:18

clean system at least in this example

play28:21

in a clean architecture

play28:23

I want to go back quickly to

play28:27

um

play28:27

the initial slide about the Golden Rule

play28:31

right talk inwards through simple

play28:34

structures and outwards through

play28:36

interfaces have a look at this code

play28:38

these are two different possible

play28:40

implementations of a use case the second

play28:43

one is the one I used the first one is

play28:45

the incorrect one if you want

play28:48

why is it incorrect it works okay first

play28:51

of all so it's not incorrect from that

play28:54

point of view

play28:55

but these Calpers my code the code of my

play28:59

use case

play29:00

with the postgres rifle it means that I

play29:04

can't use anything else or if I want to

play29:07

use something else I have to touch the

play29:10

use case but the use case is your

play29:12

business logic and it shouldn't be

play29:14

touched because you change something

play29:15

which is a detail where you store data

play29:19

okay the second one instead and this is

play29:22

a good example I I hope of dependency

play29:24

injection

play29:25

is when you create something outside

play29:29

and then you pass an instance of it the

play29:32

instance has been instantiated outside

play29:35

so the part of the code that is coupled

play29:39

with a type the postcode so I put it

play29:42

outside in this case is the web

play29:43

framework

play29:45

your use case just receives an instance

play29:49

something that can accept a certain set

play29:52

of messages does it make sense I hope so

play29:55

this is what happens in a clean

play29:58

architecture simple structures inside

play30:00

interfaces outside

play30:03

cool

play30:05

um I want to tell you about the

play30:08

advantages of the clean architecture why

play30:10

should I go through all this pain

play30:14

and there are two specific things I want

play30:16

to mention

play30:17

um the first one probably the most

play30:19

important one for me is testability

play30:23

a clean architecture a software designed

play30:25

with a clean architecture can be tested

play30:28

very well

play30:30

what do I mean by that

play30:32

um look at the use case

play30:34

I can easily isolate the use case from

play30:38

the web framework and from the database

play30:40

interface it's just an object that

play30:43

receives a repo

play30:45

and some parameters and returns some

play30:48

results

play30:49

so what I can do is to pass a dictionary

play30:51

you know of parameters

play30:53

a mock database interface so something

play30:55

that pretends to be the database

play30:57

interface but is not connected with any

play30:59

database it's just you know amok it

play31:01

returns a fixed set of data

play31:04

and check that my business logic Works

play31:07

given that input gives some output

play31:11

this allows me to test my business logic

play31:14

in isolation I don't need the database

play31:18

to test my business logic I don't need

play31:20

the web framework because these are

play31:22

details my business logic is not about

play31:24

details

play31:26

at the same time I can test the details

play31:29

because yeah details but they are part

play31:32

of the implementation so I have to test

play31:34

that my web Frameworks

play31:37

and the web framework can be detached

play31:39

from the use case

play31:41

because the web framework the only task

play31:43

is not a simple task again but the only

play31:45

task of the web framework is to accept

play31:47

HTTP requests convert them into calls

play31:52

get the result of this code and convert

play31:55

it back to an HTTP response as I said

play31:58

it's not simple I have to test that this

play32:00

works and I can do it in isolation

play32:04

and last I have to test I can test my

play32:07

repository interface this requires

play32:11

the database because this is an

play32:13

integration test okay I'm testing that

play32:15

my the facade of the database works so I

play32:19

need a database running this might be a

play32:22

slow test you know that you might run

play32:24

just sometimes again I want to stress

play32:28

this I see it too many times when we

play32:31

when it comes to testing in particular

play32:32

with web Frameworks

play32:35

we end up testing the database

play32:38

so we store a model then we retrieve the

play32:41

model and we say hey it works thank you

play32:43

very much this means that Django or

play32:46

whatever framework you're using works

play32:49

that postgres works but this is not what

play32:51

you are supposed to test

play32:53

these are you know provided by third

play32:56

party is not part of the local business

play33:00

the second Advantage

play33:02

is about

play33:03

[Music]

play33:04

um

play33:04

customization I would say

play33:07

look at this in this case I have two

play33:10

different use cases one is to list items

play33:14

and one is two list users a phone sub

play33:16

for some reason from for example for

play33:18

performances reasons I store the users

play33:21

in a mongodb which is not relational

play33:24

okay so I can't use it with a SQL

play33:26

Alchemy for example because it's not SQL

play33:29

but this is not a problem in a clean

play33:31

architecture because my use case is

play33:34

customized it just has to receive a

play33:37

different object okay that is

play33:40

instantiated by the web framework

play33:44

um pay attention that this might happen

play33:45

inside the same use case so those use

play33:48

cases those two use cases might be the

play33:51

same and you might have some logic

play33:52

inside might be part of your business

play33:54

logic that says well in this case I go

play33:57

and fetch things from repo a in this

play34:00

case I go and fetch things from repo B

play34:04

performances for example okay but these

play34:06

repos are something that you get from

play34:08

outside as you see here I'm instantiated

play34:10

them

play34:11

in the web framework not in the use case

play34:16

and the other side of this is that the

play34:20

web framework is just one of the

play34:22

possible front ends and with front end

play34:24

now I don't mean reactors similar things

play34:26

I mean the way you present your results

play34:30

to the client it might be a common line

play34:33

interface it might be a web protocol or

play34:36

something else

play34:37

because I just need to code the use case

play34:40

and translate the output of the use case

play34:42

into something that is Meaningful for my

play34:44

front end okay HTTP request for a web

play34:47

framework something else for example

play34:49

text for a command line interface

play34:55

okay at this point

play34:57

um I want to draw a comparison with an

play35:00

architecture that we or at least many of

play35:02

you probably know which is the jungle

play35:04

architecture Django is a amazing web

play35:07

framework

play35:08

well known in the python Community it

play35:11

has a different architecture it's not

play35:14

the clean architecture this doesn't mean

play35:16

it's unclean maybe

play35:19

um well yes it's unclean from giving

play35:22

given the definition it's unclean

play35:24

of what I mean is

play35:26

I don't want to say it's bad okay I'm

play35:29

I'm coming back two days later I just

play35:30

want to draw the comparison for now

play35:33

um well Django has models these are

play35:36

similar to entities superficially

play35:38

speaking they just represent part of my

play35:40

business right I have items I have I

play35:42

don't know books you know films

play35:44

something that I'm marketing

play35:48

I have business logic obviously

play35:50

otherwise why should you use Django you

play35:53

have something to market right something

play35:54

to sell

play35:57

business logic in Django is usually

play35:59

implemented in views but it can be

play36:01

implemented in functions that are called

play36:03

in views okay so this is similar if you

play36:06

want to what I did before with the clean

play36:08

architecture

play36:11

okay for the first big difference Django

play36:14

as an uh om an object or additional

play36:17

mapper which is if you want a Gateway

play36:20

it's an interface

play36:22

because if you use

play36:25

um

play36:25

MySQL if you use postgres your views

play36:29

don't change right so you are using an

play36:31

interface you are using something that

play36:33

masks the details of the underlying

play36:36

database

play36:38

however the object relational mapper the

play36:41

name says it all it is an interface to

play36:44

relational databases and it's not easy

play36:47

to use Django with no relational

play36:50

database always something else okay a

play36:53

web API

play36:55

because of the OM is customized for

play36:58

relational databases and this is

play36:59

different in a clean architecture

play37:01

because the gateways is a more generic

play37:04

definition of interface

play37:08

last two components the database

play37:11

um which is an external system

play37:13

which is also tightly connected with

play37:16

models because Motors in Jungle can be

play37:19

saved everything from the database

play37:21

natively so the models are connected

play37:23

with the database they are aware of the

play37:25

database

play37:27

what is the drawback of these that when

play37:30

you test your Django application you

play37:33

need the database

play37:35

it is possible to test it without the

play37:37

database okay but you are sort of

play37:40

fighting against the framework you're

play37:42

doing something that the framework

play37:43

doesn't want you to do so again it might

play37:46

not be bad but it's different okay so

play37:49

there is a big connection between two

play37:51

layers one is the inner layer one is

play37:54

outside

play37:55

and the same happens for the web

play37:56

framework itself as in the part of the

play37:59

framework that deals with HTTP HTTP

play38:03

request responses

play38:04

because that is connected with the

play38:06

business logic as I said before you

play38:08

usually Implement your business logic in

play38:10

views and Views are specific things

play38:13

provided by the web framework they are

play38:15

connected with URLs right

play38:19

cool so so far this is the jungle

play38:21

architecture just to show you that there

play38:24

are different approaches to the things

play38:25

and as I said this might be a good

play38:27

approach it's not bad it's just

play38:29

different

play38:33

okay let's assume I convinced you okay

play38:36

in 40 minutes you are like yes the clean

play38:39

architecture is the way to go so I want

play38:41

to go back home and convert everything

play38:42

you know to the clean architecture well

play38:45

um don't do it

play38:48

so oh if you want to do it to do it the

play38:50

right way so I always recommend to um

play38:53

you know remember what happens to what

play38:56

happened to Netscape when they decided

play38:58

to rewrite the whole thing from scratch

play39:01

they lost everything have you heard of

play39:04

Netscape lately no you know well it

play39:06

resurrected at a certain point but you

play39:09

know uh it's a sad destiny that of

play39:12

Netscape and it's for a bad choice so

play39:16

don't do the same Choice migrations

play39:17

happen one step at a time

play39:20

so my recommendation if you want to try

play39:22

these Concepts is to isolate part of

play39:25

your system some something you know tiny

play39:27

in your system and re-implement it maybe

play39:30

with a clean architecture something that

play39:33

doesn't affect the rest of the of the

play39:36

architecture

play39:37

remember that when it comes to web

play39:39

applications you have load balancers

play39:41

they are your best friends you can

play39:44

always root a requests to another system

play39:48

okay and you can go back quickly if it

play39:50

doesn't work

play39:54

final slides is this the definitive

play39:57

architecture so

play39:58

done okay it's the perfect architecture

play40:01

we don't have to do anything else go and

play40:04

Implement everything with the clean

play40:06

architecture thank you very much

play40:09

so

play40:10

the answer to this question is in my

play40:13

opinion the answer to any computer

play40:16

science question ever and it is

play40:21

it depends okay it depends on many

play40:25

things it depends on your requirements

play40:28

for example when it comes to the clean

play40:30

architecture versus something else for

play40:32

example the jungle architecture I tend

play40:34

to show this slide you are the

play40:37

crossroads between these two options

play40:40

Lego versus Playmobil on the right you

play40:44

have something that works out of the box

play40:47

and it's it's very nice you you can play

play40:50

with it it's amazing you know I don't

play40:52

play with it nowadays but I remember I

play40:54

have fun memories

play40:56

you want a farm you get a farm it's

play40:59

customizable up to a certain point you

play41:02

can move things around okay

play41:04

on the other side on the left you can

play41:07

build whatever you want

play41:09

but you are on your own

play41:12

so it depends what are you constrained

play41:16

what do you want to achieve can you mix

play41:19

and match the two yes you can okay so

play41:22

this is my recommendation always

play41:23

whenever you design a system always stop

play41:26

and think look at the requirements don't

play41:29

go for a solution out of the box it

play41:32

might be the right solution but you have

play41:34

to be you know clear that why it is the

play41:37

right solution

play41:39

uh reading last two slides I wrote a

play41:43

book about this uh Concepts clean

play41:46

architectures in Python it's a free book

play41:48

it's available there

play41:50

the example I showed you today comes

play41:52

from the book there I implemented it

play41:55

properly with tdd all the way

play41:59

a lot of error checking so the whole

play42:02

book is about that example okay just

play42:04

write even a list of objects I

play42:05

implemented it with postgres and mongodb

play42:08

just to show that it's possible to use

play42:11

different databases

play42:12

for the Euro python so for this week and

play42:15

the next week I teamed up with some

play42:19

friends and I'm offering the book and

play42:22

other books for free it's a bundle worth

play42:24

of 60 dollars so you are free to follow

play42:29

us on Twitter and you can check the URL

play42:32

on the in Pub to get the bundle for free

play42:36

with that I'm done I hope it was useful

play42:40

thank you

play42:50

yeah thank you very much Leonardo for

play42:52

that very inspiring talk we have a few

play42:54

minutes that are available for questions

play42:57

so if anybody has a question we have a

play43:00

microphone here or just quickly go to

play43:03

that microphone and ask a question I'll

play43:06

be around for the next two hours so feel

play43:09

free to get in touch okay yes uh hello

play43:12

thank you for the really nice

play43:13

presentation and why I try to follow the

play43:17

layered architecture the one thing that

play43:20

I always struggled is with

play43:22

so if you want to really follow this

play43:25

then it seems like you have a lot of

play43:26

duplication so you have to have the

play43:28

models in the core of the business that

play43:30

your business or your cases are using

play43:32

and then you want to persist also those

play43:34

models into the database or somewhere

play43:36

else they need to have some kind of

play43:38

definition of how this happens with some

play43:40

bookkeeping data and potentially the

play43:43

duplicate the definition of the original

play43:45

data so since there's a application so

play43:48

do you have a suggestion how to avoid

play43:50

that or maybe make it less painful to

play43:53

implement the clean architecture

play43:57

I don't think there will be duplication

play43:59

we might we might talk about this later

play44:00

there is definitely a lot of message

play44:03

passing so if that is what you mean by

play44:06

duplication yes the same data is going

play44:08

around a lot which is part of the

play44:11

drawbacks of the clean architecture

play44:13

there are a lot of layers that is my

play44:15

impact performances like you don't have

play44:18

a direct access to the database

play44:20

but in terms of duplication I I'm not

play44:23

really sure what you mean so if you want

play44:24

to expand on that for example when in

play44:27

the example at the show for the jungle

play44:29

that is you define the model once and

play44:31

then this that's also the definition of

play44:33

how the table would look like and

play44:35

majority of RMS work the same way so you

play44:38

have single source of proof that defines

play44:41

basically the layout of the data in the

play44:43

database as well as the layout of the

play44:46

model that you're working with and for

play44:48

the data heavy application that's really

play44:50

convenient and very simple to like work

play44:52

with and Define your system so if you

play44:55

don't want to use that then you need to

play44:57

have I definitely see what you mean

play44:59

thank you

play45:00

um now I understand yes it's true that

play45:03

for example the model I use in entities

play45:06

correct me if I understood the wrong way

play45:08

is duplicated in the database interface

play45:12

because this is what I'm storing exactly

play45:14

it's true there is no way to avoid it

play45:17

because this is a feature

play45:20

as in I am splitting the model The

play45:25

Entity if you want as in a business

play45:26

entity and the entity has something that

play45:29

is stored in the database

play45:31

I agree this is more work

play45:35

and there is no way to avoid it because

play45:37

it's considered a good thing

play45:40

again it's part of the it depends the

play45:43

requirements you might think that in

play45:45

your business logic this separation is

play45:47

not needed or it's Overkill and you're

play45:50

free to go with a different architecture

play45:52

but the idea if we want the extreme idea

play45:57

is to split these two things because

play45:58

they might exist in the same space but

play46:01

they are not the same thing one thing is

play46:03

the business logic one thing is how I

play46:05

did the business entity if you want and

play46:07

one thing is how I store it

play46:10

okay thank you thank you very quick

play46:13

final question

play46:16

hi hi Leonardo thank you you're welcome

play46:19

I really appreciate your emphasis on

play46:21

beauty and art in terms of software

play46:25

um with clean architecture I can see the

play46:27

benefits of say durability uh utility

play46:30

how it by making a architecture clean do

play46:34

I get Beauty out of the box or is there

play46:36

something more elusive uh making

play46:39

something beautiful it might be a bit

play46:40

more elusive

play46:42

um you know beautiful beauty is to be

play46:45

defined

play46:46

to be honest when I was working on the

play46:49

book and I came up with the example and

play46:52

you know I was looking at the projects

play46:54

where components were how they were

play46:57

interacting between them a certain point

play46:59

my feeling and this is pretty personal

play47:01

it was like this is this is really

play47:03

beautiful it clicks it works and this is

play47:07

what I meant as in Beauty for me it

play47:11

might be subjective okay definitely it

play47:14

doesn't shine doesn't come in us you

play47:16

know but the beauty of that system for

play47:20

me is that it's again it's tidy I know

play47:23

where things are I'm confident that when

play47:26

I'm touching something and touching just

play47:28

the little Universe around that

play47:31

component and not other things

play47:33

this works for me and this is the beauty

play47:36

in that architecture for me thank you

play47:39

very much for the questions and let's

play47:41

have another round of applause for

play47:43

Leonardo thank you

Rate This

5.0 / 5 (0 votes)

Связанные теги
Clean ArchitecturePython DesignSystem DurabilityUtility FocusAesthetic CodeSoftware BeautyVitruvius PrinciplesTDD PracticesSoftware EngineeringDjango ComparisonIntegration Patterns
Вам нужно краткое изложение на английском?