I gave this presentation Jan 24th 2019 here:
https://www.meetup.com/BAyPIGgies/events/257819623/
The code can be found here:
https://github.com/jairvercosa/ca_auth
1. Blank Slide
Jair Vercosa
Clean Architecture with Python
https://vercosa.life
https://medium/@jairvercosa
https://github.com/jairvercosa Made in Brazil
2. Carta helps private companies, public companies, and
investors manage their cap tables, valuations,
investments, and equity plans.
On the employee side, the platform provides ways to
participate on liquidity events and exercise their stock
options.
Private, Public, Investors, and beyond!
!2
5. Clean Architecture
Universal rules of software architecture that when applied can dramatically improve developer
productivity throughout the life of any software system.
What is it?
6. !6
Rules
High-level components should avoid depending on low-level
components. The dependency is always inwards!
Dependency rule
Your system should scream your domain and not a
framework architecture.
Screaming architecture
Your system should scream your domain and not a
framework architecture.
Database, web, frameworks are all simple details
High cohesion and lower coupling in all levels (objects,
packages, systems)
Cohesion vs Coupling
16. Use Cases
Use Cases
It orchestrates the flow of data to-from entities. It has
the application business logic and manages the
different entities involved in some operation.
Definition
Entities
18. Interface Adapters
Responsible for translating the data from the database
or inputs into the format to be used by the domain.
Definition
Interfaces Adapters
Use Cases
Entities
20. Infrastructure
Infrastructure
The edges of the application, usually where you collect
the inputs, deliver the outputs, persist data, and make
communication with external systems.
Definition
Interfaces Adapters
Use Cases
Entities
24. Separation of concerns
!24
Well defined responsibilities for each layer
and clear boundaries.
Low coupling and high cohesion.
25. Better Testing
!25
The core of your business ends at the Use
Case level. Therefore you can test with simple
Python objects.
The dependency rule helps you to implement
interfaces for testing.
26. Flexibility
!26
The lower your layer, the easier becomes to
replace layers.
Depending on abstract/interfaces makes your
code way easier to work with.
28. Embrace the framework, but act as it wasn’t there
* Use interfaces/abstraction as much as you can
* Create an interface for queries, even if your ORM is nice. Specially if your ORM is nice!!
* Always have an Use Case layer for business logic
29. Build independent modules
* Your modules should care about only one thing. But it doesn’t mean only one model.
* Avoid foreign keys between modules
* Aways create a service layer for communication between modules