2022-10 Victor Dorneanu
Why should you chose hexagonal architecture ?
The idea of Hexagonal Architecture is to put inputs and outputs at the edges of our design. Business logic should not depend on whether we expose a REST or a GraphQL API, and it should not depend on where we get data from — a database, a microservice API exposed via gRPC or REST, or just a simple CSV file.
– Ready for changes with hexagonal architecture | netflix blog
Figure 2: Source: https://threedots.tech/post/introducing-clean-architecture/
servers
handling requests from outside to your business applicationclients
As an uploader I’d like to upload documents to some infrastructure. After successful upload I’d like to get a link I can share with my friends.
– Uploader
Easy! Some observations:
As a product manager I’d like to see how many documents each uploader uploads and how many times he/she shares the link.
– Product Manager
Also easy! Again some observations:
Figure 3: Architecture of some imaginary application which uploads some documents to a storage system
Document
)DocumentUploadService
)DocumentStorageRepository
and DocumentMetricsRepository
)DocumentUploadService
for the terminalDocumentUploadService
via HTTP
Figure 4: The business domain contains the application login and uses abstractions (interfaces) for defining interactions.
class Document (): ❶
"""A document is an entity"""
def __init__(self, path: FilePath):
self._file_path = path âť·
def meta(self):
"""Display meta information about the file"""
print("Some information")
Document
❶ as an entityclass UploadDocumentService: ❶
"""Upload a document to storage repository"""
def __init__(
self,
storage_repository: DocumentStorageRepository,
metrics_repository: DocumentMetricsRepository,
):
self._storage_repo: DocumentStorageRepository
self._metrics_repo: DocumentMetricsRepository
def upload_document(self, document: Document): âť·
self._storage_repository(document)
self._metrics_repo.send_metrics()
UploadDocumentService
upload_document(document: Document)
The repositories are basically interfaces for the secondary (driven) adapters. In our case we have:
save
documentssearch
for documentsdelete
a document