In my talk at QtGreece 2023, I introduce the ports-and-adapters or hexagonal architecture for embedded HMI. I look at this architecture from a production, testing and team perspective.
4. Slow: Finding Your Best Architecture
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 4
All architectures
Good architectures:
Technically sound
Right architectures:
Meeting needs
Successful architectures:
Delivering value
• Takes years
• Needs lot of experience
and trial & error
5. Fast: De-Facto Standard Architecture
Ports & Adapters
Architecture
Start with de-facto standard
architecture and adapt it!
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 5
• Start using now
• Lots of experience built in
• Known to be good, right
and successful
6. Ports-and-Adapters
Architecture
• De-Facto Standard Architecture
• Motivation: USB Adapters
• Production Perspective
• Testing Perspective
• Team Perspective
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 6
7. Fast: De-Facto Standard Architecture
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 7
Computer
USB Port USB Adapter (W)LAN
CAN
BLE
RS232
LTE/5G
Port hides
technology of adapter
from computer
• USB Port: standard interface
• Many USB-to-X adapters
• Different companies build
adapters
8. Ports-and-Adapters
Architecture
• De-Facto Standard Architecture
• Motivation: USB Adapters
• Production Perspective
• Testing Perspective
• Team Perspective
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 8
10. Definitions
10
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com)
Port Interface between Core (inside)
and Adapters (outside)
1 Port has 1 or more adapters
Adapter uses or implements a port
Product Adapter used in product
Test Adapter used for testing only
Core implements the rules of the
business domain
a.k.a. business logic
Adapter Port
depends on
Adapter
communicates with
System
Adapter
interacts with
Person
11. Responsibilities
11
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com)
Application
Core
J1939 Machine
MQTT Machine
CANOpen Machine
Machine
UI
GUI
Voice UI
Application
Core
• Ports hide technology (Qt, SQL, J1939,
etc.) used in adapters from core
• No adapter code in core
• No core code (business rules) in adapters
• Ports make core I/O-free
• Great for testing
• Easily exchange adapters in future
• Core & other adapters won’t notice
• Core drives definition of ports
• Raise abstraction level of ports
• Ports belong to core, not vice versa
• Adapters depend on ports and core:
Never the other way round!
• Apply dependency inversion
12. Ports-and-Adapters
Architecture
• De-Facto Standard Architecture
• Motivation: USB Adapters
• Production Perspective
• Testing Perspective
• Team Perspective
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 12
14. I/O-Free Acceptance Tests for Core
14
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com)
Application
Core
Machine
Double
Machine
UI
Acceptance
Tests
• Replace product by test adapters
• Test doubles for driven ports
• Test cases for driving ports
• Tests mimick how user interacts with
application
• Tests similar to CLI
• Port is bad interface, if tests duplicate
code from product adapter:
• Abstraction level of port to low
• Core depends on adapter code
• I/O-free acceptance tests for core
• Develop core independently from
adpaters – in different teams
15. I/O-Based Tests for System Parts
15
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com)
Application
Core
Machine
UI
Acceptance
Tests
DB Double
J1939 Machine
[CAN] Machine
Double
Application
Core
Machine
UI
Acceptance
Tests
J1939 Machine
[CAN] Machine
Double
Local DB
[WLAN] Accounting
Double
• Replace test by product
adapters
• Reduce complexity by keeping
some test doubles
For system simulation:
Introduce simulation
adapters
16. Ports-and-Adapters
Architecture
• De-Facto Standard Architecture
• Motivation: USB Adapters
• Production Perspective
• Testing Perspective
• Team Perspective
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com) 16
17. Ideal Team Structure
17
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com)
• Conways Law:
The software architecture always
mirrors the team structure.
• Inverse Conway Manoeuvre:
• First, define the software architecture.
• Then, define the team structure as mirror
of the software architecture.
Map software architecture
1:1 to team structure
Core Team
UI
Team
Machine
Team
Accounting
Team
• Team responsibilities:
• Core team defines ports and owns them
• UI team is primary driver
• Adapter teams implement ports
• Adapter teams build end-to-end solutions
• Accounting: client and server
• Machine: J1939 adapter layer for all ECUs
18. Supplier
Manufacturer
Team Structures Shaped by Reality
18
Copyright 2023, Burkhard Stubert (burkhard.stubert@embeddeduse.com)
• Not enough developers for 4 teams
• First: merge UI into Core team
• Then: Accounting team
• Avoid merging Machine team
Machine
Team
• Other end developed by external team
• Introduce interface on comms link
defined and owned by manufacturer
• Other end doubled for testing
Internal
Machine
Team
Extended
Core Team
[J1939/CAN]
External
Machine
Team
Extended
Core Team
Architecture shaped by its surrounding ecosystem
How does the right architecture look?
Lead with questions:
Question are the same for QtEmSys, but answers differ and have differerent priorities
Questions from different perspectives unearth requirements (= answers)
Ignoring architecture leads to BBoM
You see my learning process over the last 25 years.
Start with hexagonal architecture as de-facto standard architecture (presumptive architecture).
=> Reduces the search space!
Fairbanks: “Presumptive architectures are usually successful.”
Good = efficient
Right = effective
Lets transfer the hardware idea into software
Legend for previous slide: Just as reminder for presenter and as reference for audience
Core is your core competence and your compettitive advantage! Core is your business!!
Adapters support the domain. Never core business!
No core code in adapters (business rules leaking into adapter):
When the ignition is on, an accounting job must be running so that the agency can bill the farmer for the work; job stored in DB. -> More than one adapter involved
When the motor is running and the driver is not on the seat, the cutting knives must not rotate or the motor must stop. -> differs from OEM to OEM
When the ad-blue level is far too low, the UI must show a warning that the motor will automatically be turned off within 10 seconds.
Lets transfer the hardware idea into software
If not enough developers, use double for some adapters and replace it by product adapter later.
Other end = other ECUs of machine, cloud server for accounting