SlideShare a Scribd company logo
Clean Architectures
with
PyConES 2021
October 3rd, 2021
We quickly and effectively detect and eliminate online piracy for digital assets
(movies, series, books) and counterfeited products offered in marketplaces,
search engines, social media platforms and apps
Smart Protection is a technological company
committed to fighting online piracy
User Portal
● A portal to interact with all
the services for a customer
● Need to be able to
communicate with different
data sources
● A scalable team and product
● Be agile, speed and iteration
are must
User Portal
The Product
User Portal
Presented today by
Alvaro del Castillo
alvaro.delcastillo@smartprotection.com
Clean
Architectures
● Main components (software artifacts) of the system (structure)
● The relationships (structural and behaviour) between the components
Similar to traditional architecture for buildings but software ones must be
designed for change
Clean Architectures
Software Architectures
«A client-server software architecture pattern in which the
user interface (presentation), functional process logic
(domain) and data access and storage are developed and
maintained as independent modules (Wikipedia).» The
dependency goes from top to bottom each layer just
depending on its bottom one.
What’s wrong with these layers? The data layer becomes
the core of the architecture (database model, tech …)
Clean Architectures
Classical Approach: Layered Architecture
Clean Architectures
Clean Architecture
The domain (policies) is in the core and
it does not depend on external layers. It
won’t change if something external
changes. Outer layers depend on Inner
layers.
Outer layers (mechanisms)
communicates with the core using
in/out ports (interfaces). FastAPI is
mechanism for us: it can be changed
without affecting the domain.
● The outer layers should point to the inner
layers
● The Business logic should not know about
the technology implementations of the
outer layers
● The ports are interfaces and the adapter
implementations
Clean Architectures
Hexagonal Architecture
Using in the
Infrastructure of an Hexagonal
Architecture
● ASGI (WSGI with async) based on Starlette
● Data validation (path, query params, body) with Pydantic
● Work with any web server with ASGI support like uvicorn
You define the endpoints of your remote APIs and link to the logic that
implements them. These are the routes. In the routes you have data models to
receive and deliver the data.
FastAPI
Web framework for building remote APIs
Based on the Scarlette ASGI framework, its performance is one of the
fastest Python frameworks available, and it is comparable with NodeJS.
From Scarlette it also inherits WebSocket support, GraphQL support,
in-process background tasks, session and cookie support
(middleware in general),
CORS, HTTP2 and others.
FastAPI
Async nature: Performance
Pydantic enforces type hints (Python) at runtime, and provides user friendly
errors when data is invalid. And it is fast compared to other validation libraries.
class User(BaseModel):
id: int
name = "Lisa Perez"
signup_ts: Optional[datetime] = None
friends: List[int] = []
class Config:
extra = 'forbid'
external_data = {
"id1": 1,
"id": 1,
"signup_ts": "2021-01-10 10:00",
"friends": []
}
user = User(**external_data)
The payload, path params and query params are validated and converted to
Python models automatically.
FastAPI
Pydantic Data Validation
Real time documentation in different
formats, like OpenAPI, using type hints
and default values and ranges!
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int = Path(None,
example="item_id_value"),
q: str = Query("query")):
return {"item_id": item_id, "q": q}
if __name__ == '__main__':
uvicorn.run('basic:app', host='0.0.0.0', reload=True)
FastAPI
Automatic documentation
"Dependency Injection" means, in programming, that there is a way for your
code (in this case, your path operation functions) to declare things that it
requires to work and use: "dependencies".
The dependencies, which can be nested, are resolved before calling the path
operation function. For example, for authorization before calling the endpoint:
router.add_api_route(path='/save/',
name='save',
methods=['POST'],
endpoint=certificates_api.save,
dependencies=[Depends(get_certificates_jwt_authorizer)],
status_code=status.HTTP_200_OK)
FastAPI
Dependency Injection
And ASGI introduces new features like Background Tasks!
Methods executed once the request is sent to the client.
async def save(
self,
request: Request,
background_tasks: BackgroundTask) -> None:
...
background_tasks.add_task(send_notification_use_case.execute,
notification_command)
FastAPI
Background Tasks
The routes call the path methods. All this logic is part of the API framework.
But the path methods calls the use cases, with the data from the requests
converted to the domain models. These use cases are in the application layer,
which works directly with the domain layer (all of them business logic).
The use cases returns data with domain models, which is converted with
Pydantic to a JSON payload which is sent to the client.
FastAPI
Inside the Hexagon Architecture
Showcase: User Portal
Reports
Assets
Content
Showcase: User Portal
Domains detection
Reports
Infrastructure
Application
Domain FastAPI
External
API
SQL
DB
User
Service
Repository
API
Showcase: User Portal
Hexagonal Architecture
● Team and product scalability
● Ready for change
● Technology independent
Clean Architectures
Benefits
The hexagonal architecture born as an evolution of layered architectures with the goal
of improving the isolation between policies (domain) and mechanisms (db). The
policies (business logic) became the core of the architecture and it does not depend in
how it is used (thanks to the dependency inversion).
FastAPI is an easy to use web framework for creating remote APIs, based on the
newest standards and reusing actual frameworks like Starlette and Pydantic. With it
you can create APIs pretty fast and ready to be moved to production.
Integrating FastAPI in our Hexagonal Architectures is pretty natural: it is just the
mechanism to offer remote APIs based on the domain business logic.
Using FastAPI in the Infrastructure of Hexagonal Architecture
Takeaways
Questions?
Thanks for attending!

More Related Content

What's hot

Integrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesIntegrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetes
Claus Ibsen
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
Adam Paxton
 
Serving ML easily with FastAPI
Serving ML easily with FastAPIServing ML easily with FastAPI
Serving ML easily with FastAPI
Sebastián Ramírez Montaño
 
Kafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryKafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema Registry
Jean-Paul Azar
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Amazon Web Services
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
OpenTelemetry For Developers
OpenTelemetry For DevelopersOpenTelemetry For Developers
OpenTelemetry For Developers
Kevin Brockhoff
 
Security Patterns for Microservice Architectures
Security Patterns for Microservice ArchitecturesSecurity Patterns for Microservice Architectures
Security Patterns for Microservice Architectures
VMware Tanzu
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
Yevgeniy Brikman
 
OpenStack Introduction
OpenStack IntroductionOpenStack Introduction
OpenStack Introduction
openstackindia
 
Building a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDBBuilding a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDB
MongoDB
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
Spring Boot
Spring BootSpring Boot
Spring Boot
koppenolski
 
OpenStack Keystone
OpenStack KeystoneOpenStack Keystone
OpenStack Keystone
Deepti Ramakrishna
 
Policy Enforcement on Kubernetes with Open Policy Agent
Policy Enforcement on Kubernetes with Open Policy AgentPolicy Enforcement on Kubernetes with Open Policy Agent
Policy Enforcement on Kubernetes with Open Policy Agent
VMware Tanzu
 
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
Open Source Consulting
 
Spring boot Under Da Hood
Spring boot Under Da HoodSpring boot Under Da Hood
Spring boot Under Da Hood
Michel Schudel
 
Secret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s VaultSecret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s Vault
AWS Germany
 

What's hot (20)

Integrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesIntegrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetes
 
Designing APIs with OpenAPI Spec
Designing APIs with OpenAPI SpecDesigning APIs with OpenAPI Spec
Designing APIs with OpenAPI Spec
 
Serving ML easily with FastAPI
Serving ML easily with FastAPIServing ML easily with FastAPI
Serving ML easily with FastAPI
 
Kafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryKafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema Registry
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
OpenTelemetry For Developers
OpenTelemetry For DevelopersOpenTelemetry For Developers
OpenTelemetry For Developers
 
Security Patterns for Microservice Architectures
Security Patterns for Microservice ArchitecturesSecurity Patterns for Microservice Architectures
Security Patterns for Microservice Architectures
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
OpenStack Introduction
OpenStack IntroductionOpenStack Introduction
OpenStack Introduction
 
Building a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDBBuilding a High-Performance Distributed Task Queue on MongoDB
Building a High-Performance Distributed Task Queue on MongoDB
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
OpenStack Keystone
OpenStack KeystoneOpenStack Keystone
OpenStack Keystone
 
Policy Enforcement on Kubernetes with Open Policy Agent
Policy Enforcement on Kubernetes with Open Policy AgentPolicy Enforcement on Kubernetes with Open Policy Agent
Policy Enforcement on Kubernetes with Open Policy Agent
 
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
 
Spring boot Under Da Hood
Spring boot Under Da HoodSpring boot Under Da Hood
Spring boot Under Da Hood
 
Secret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s VaultSecret Management with Hashicorp’s Vault
Secret Management with Hashicorp’s Vault
 

Similar to Clean architectures with fast api pycones

Web Oriented Architecture at Oracle
Web Oriented Architecture at OracleWeb Oriented Architecture at Oracle
Web Oriented Architecture at Oracle
Emiliano Pecis
 
GaurabDey_UFL_CV_fulltime (1)
GaurabDey_UFL_CV_fulltime (1)GaurabDey_UFL_CV_fulltime (1)
GaurabDey_UFL_CV_fulltime (1)
Gaurab Dey
 
Webinar september 2013
Webinar september 2013Webinar september 2013
Webinar september 2013
Marc Gille
 
Archonnex at ICPSR
Archonnex at ICPSRArchonnex at ICPSR
Archonnex at ICPSR
Harshakumar Ummerpillai
 
Nasdanika Foundation Server
Nasdanika Foundation ServerNasdanika Foundation Server
Nasdanika Foundation Server
Pavel Vlasov
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Getting value from IoT, Integration and Data Analytics
 
Resume_Brad_Johnson
Resume_Brad_JohnsonResume_Brad_Johnson
Resume_Brad_Johnson
Bradlee Johnson
 
Using Istio to Secure & Monitor Your Services
Using Istio to Secure & Monitor Your ServicesUsing Istio to Secure & Monitor Your Services
Using Istio to Secure & Monitor Your Services
Alcide
 
Technology Overview
Technology OverviewTechnology Overview
Technology Overview
Liran Zelkha
 
ColbyBackesPortfolio_HighRes
ColbyBackesPortfolio_HighResColbyBackesPortfolio_HighRes
ColbyBackesPortfolio_HighRes
Colby Backes
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Beat Signer
 
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership OverviewCloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
CAST
 
Apache Airavata SGCI Webinar 8 April 2020
Apache Airavata SGCI Webinar 8 April 2020Apache Airavata SGCI Webinar 8 April 2020
Apache Airavata SGCI Webinar 8 April 2020
Marlon Pierce
 
Dojo - from web page to web apps
Dojo - from web page to web appsDojo - from web page to web apps
Dojo - from web page to web apps
yoavrubin
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
Prateek Maheshwari
 
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
Ontico
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
tdc-globalcode
 
OpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio Tavilla
OpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio TavillaOpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio Tavilla
OpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio Tavilla
Lorenzo Carnevale
 
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App EngineJava Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
IMC Institute
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
Shubhra Kar
 

Similar to Clean architectures with fast api pycones (20)

Web Oriented Architecture at Oracle
Web Oriented Architecture at OracleWeb Oriented Architecture at Oracle
Web Oriented Architecture at Oracle
 
GaurabDey_UFL_CV_fulltime (1)
GaurabDey_UFL_CV_fulltime (1)GaurabDey_UFL_CV_fulltime (1)
GaurabDey_UFL_CV_fulltime (1)
 
Webinar september 2013
Webinar september 2013Webinar september 2013
Webinar september 2013
 
Archonnex at ICPSR
Archonnex at ICPSRArchonnex at ICPSR
Archonnex at ICPSR
 
Nasdanika Foundation Server
Nasdanika Foundation ServerNasdanika Foundation Server
Nasdanika Foundation Server
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
 
Resume_Brad_Johnson
Resume_Brad_JohnsonResume_Brad_Johnson
Resume_Brad_Johnson
 
Using Istio to Secure & Monitor Your Services
Using Istio to Secure & Monitor Your ServicesUsing Istio to Secure & Monitor Your Services
Using Istio to Secure & Monitor Your Services
 
Technology Overview
Technology OverviewTechnology Overview
Technology Overview
 
ColbyBackesPortfolio_HighRes
ColbyBackesPortfolio_HighResColbyBackesPortfolio_HighRes
ColbyBackesPortfolio_HighRes
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
 
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership OverviewCloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
 
Apache Airavata SGCI Webinar 8 April 2020
Apache Airavata SGCI Webinar 8 April 2020Apache Airavata SGCI Webinar 8 April 2020
Apache Airavata SGCI Webinar 8 April 2020
 
Dojo - from web page to web apps
Dojo - from web page to web appsDojo - from web page to web apps
Dojo - from web page to web apps
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
 
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
События, шины и интеграция данных в непростом мире микросервисов / Валентин Г...
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
OpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio Tavilla
OpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio TavillaOpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio Tavilla
OpenStack Identity - Keystone (kilo) by Lorenzo Carnevale and Silvio Tavilla
 
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App EngineJava Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 

Recently uploaded

Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 

Recently uploaded (20)

Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 

Clean architectures with fast api pycones

  • 2. We quickly and effectively detect and eliminate online piracy for digital assets (movies, series, books) and counterfeited products offered in marketplaces, search engines, social media platforms and apps Smart Protection is a technological company committed to fighting online piracy
  • 4. ● A portal to interact with all the services for a customer ● Need to be able to communicate with different data sources ● A scalable team and product ● Be agile, speed and iteration are must User Portal The Product
  • 5. User Portal Presented today by Alvaro del Castillo alvaro.delcastillo@smartprotection.com
  • 7. ● Main components (software artifacts) of the system (structure) ● The relationships (structural and behaviour) between the components Similar to traditional architecture for buildings but software ones must be designed for change Clean Architectures Software Architectures
  • 8. «A client-server software architecture pattern in which the user interface (presentation), functional process logic (domain) and data access and storage are developed and maintained as independent modules (Wikipedia).» The dependency goes from top to bottom each layer just depending on its bottom one. What’s wrong with these layers? The data layer becomes the core of the architecture (database model, tech …) Clean Architectures Classical Approach: Layered Architecture
  • 9. Clean Architectures Clean Architecture The domain (policies) is in the core and it does not depend on external layers. It won’t change if something external changes. Outer layers depend on Inner layers. Outer layers (mechanisms) communicates with the core using in/out ports (interfaces). FastAPI is mechanism for us: it can be changed without affecting the domain.
  • 10. ● The outer layers should point to the inner layers ● The Business logic should not know about the technology implementations of the outer layers ● The ports are interfaces and the adapter implementations Clean Architectures Hexagonal Architecture
  • 11. Using in the Infrastructure of an Hexagonal Architecture
  • 12. ● ASGI (WSGI with async) based on Starlette ● Data validation (path, query params, body) with Pydantic ● Work with any web server with ASGI support like uvicorn You define the endpoints of your remote APIs and link to the logic that implements them. These are the routes. In the routes you have data models to receive and deliver the data. FastAPI Web framework for building remote APIs
  • 13. Based on the Scarlette ASGI framework, its performance is one of the fastest Python frameworks available, and it is comparable with NodeJS. From Scarlette it also inherits WebSocket support, GraphQL support, in-process background tasks, session and cookie support (middleware in general), CORS, HTTP2 and others. FastAPI Async nature: Performance
  • 14. Pydantic enforces type hints (Python) at runtime, and provides user friendly errors when data is invalid. And it is fast compared to other validation libraries. class User(BaseModel): id: int name = "Lisa Perez" signup_ts: Optional[datetime] = None friends: List[int] = [] class Config: extra = 'forbid' external_data = { "id1": 1, "id": 1, "signup_ts": "2021-01-10 10:00", "friends": [] } user = User(**external_data) The payload, path params and query params are validated and converted to Python models automatically. FastAPI Pydantic Data Validation
  • 15. Real time documentation in different formats, like OpenAPI, using type hints and default values and ranges! app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} @app.get("/items/{item_id}") def read_item(item_id: int = Path(None, example="item_id_value"), q: str = Query("query")): return {"item_id": item_id, "q": q} if __name__ == '__main__': uvicorn.run('basic:app', host='0.0.0.0', reload=True) FastAPI Automatic documentation
  • 16. "Dependency Injection" means, in programming, that there is a way for your code (in this case, your path operation functions) to declare things that it requires to work and use: "dependencies". The dependencies, which can be nested, are resolved before calling the path operation function. For example, for authorization before calling the endpoint: router.add_api_route(path='/save/', name='save', methods=['POST'], endpoint=certificates_api.save, dependencies=[Depends(get_certificates_jwt_authorizer)], status_code=status.HTTP_200_OK) FastAPI Dependency Injection
  • 17. And ASGI introduces new features like Background Tasks! Methods executed once the request is sent to the client. async def save( self, request: Request, background_tasks: BackgroundTask) -> None: ... background_tasks.add_task(send_notification_use_case.execute, notification_command) FastAPI Background Tasks
  • 18. The routes call the path methods. All this logic is part of the API framework. But the path methods calls the use cases, with the data from the requests converted to the domain models. These use cases are in the application layer, which works directly with the domain layer (all of them business logic). The use cases returns data with domain models, which is converted with Pydantic to a JSON payload which is sent to the client. FastAPI Inside the Hexagon Architecture
  • 22. ● Team and product scalability ● Ready for change ● Technology independent Clean Architectures Benefits
  • 23. The hexagonal architecture born as an evolution of layered architectures with the goal of improving the isolation between policies (domain) and mechanisms (db). The policies (business logic) became the core of the architecture and it does not depend in how it is used (thanks to the dependency inversion). FastAPI is an easy to use web framework for creating remote APIs, based on the newest standards and reusing actual frameworks like Starlette and Pydantic. With it you can create APIs pretty fast and ready to be moved to production. Integrating FastAPI in our Hexagonal Architectures is pretty natural: it is just the mechanism to offer remote APIs based on the domain business logic. Using FastAPI in the Infrastructure of Hexagonal Architecture Takeaways