The Trinity
Architecture
Christos Tsakostas
DDD Greece, May 10th 2019, e-food, Athens
Agenda
- Introduction
- Brief overview of architectural patterns
- Formation of Trinity
- Conclusions & More
Introduction
What is Architecture? (Fowler, 2002)
1. Breakdown of a system into its
parts
2. Subjective decisions about the
form & structure of parts
Architecture Classifications
System
Enterprise
SecuritySecurity
Solution
Event-Driven
Data-centric
Cloud Persistence
BusinessApplication
Monolith
Microservices
...
...
...
...
...
...
...
...
4+1 Architectural View Model (Kruchten, 1995)
The term Architecture in this context
Enterprise (microservice)
applications architecture
The Architecture Problem
- Choice of pattern
- Structure of parts
- Consistent
- Long-lasting
- Scalability
- Interchangeable parts
What are teams doing now?
- Little or no architectural design (i.e. start-ups, side-projects etc.)
- The majority uses layered architectures
- Some teams use modern architectures (such as Ports-Adapters)
Intentions of the Trinity Architecture
- Agile
- Consistent
- Recognizable
Brief Overview
of Popular
Architectural
Patterns
Timeline of Applications Architecture
- Optimizations of data structures and algorithms (50’s/60’s-80’s)
- Multi-Tier (90’s)
- Multi-Layered (90’s - today)
- DIP*-Based (2000’s - today)
- Less popular patterns, such as Data - Context - Interaction / DCI (2000’s)
*: Dependency Inversion Principle
The
Multi-Layered
Architecture
Layered: Most Prevalent Architecture of All Times
- 3-Layers (i.e. Martin Fowler 2002)
- 4-Layers (i.e. Eric Evans 2003)
- Some teams use more than 10 layers!
Typical 3-Layers Architecture (Fowler, 2002)
Typical 4-Layers Architecture (Evans, 2003)
Benefits of Layered Architectures
- Simplicity
- Consistency
- Separation of Concerns
Drawbacks of Layered Architectures
- Lack of inbuilt scalability
- Hidden use cases
- Business Logic may spread out from UI to Database
- Frameworks & Technologies not easily interchangeable
- Complex Testing Processes
- Risk of too many, unnecessary, layers
What is the “Dependency Inversion Principle”?
The Dependency Inversion Principle (DIP)
DIP Example
DIP Layered Architecture (Vaughn Vernon, 2013)
The DIP-based
Architectures
DIP-Based Architectures
- Hexagonal Ports-Adapters by Alistair Cockburn, 2005
- Onion by Jeffrey Palermo, 2008
- Clean Architecture by Robert C. Martin, 2012 / 2017
Hexagonal Ports-Adapters
Onion
Clean Architecture
Benefits of DIP-Based Architectures
- Independent of the UI
- Independent of the database and other external systems
- Independent of technology specific libraries and frameworks
- Interchangeable infrastructure modules
- Arbitrary number and types of clients
- Testable
Drawbacks of DIP Architectures
- Complexity
- Vague Terminology (at least for DDD)
- Lack of project structure templates (except Onion)
- Therefore, vulnerable to erroneous dependencies and modules structure
- How to choose a pattern?
Formation of
Trinity
Architecture
The Steps to Build Trinity
- Start from Typical 4-Layers and define Generic vs Specific Layers
- Define Strict and Relaxed Dependencies
- Apply DIP
- Include Application Module
- Finalize
1: Define Generic vs Specific Layers
2: Define Strict & Relaxed Dependencies
3: Apply DIP
4: Include Application (APP) Module
5: Rotate and form the Trinity Architecture
Alternative Circular View of Trinity
Sample API Clients
Sample Auxiliary Details
Sample Domain Details
Demo Project Layout
Comparisons
Hexagonal Ports-Adapters
Comparison to Hexagonal Ports-Adapters
Conclusions
Balances Consistency with Agility
Consistency:
- Eight top modules
- Rigorous module dependencies
Agility:
- Numerous API Clients
- Numerous Auxiliary Details
- Numerous Domain Details
Frameworks Agnostic Core
- API, Auxiliary & Domain do not
depend on Frameworks
- Framework specific annotations
may optionally be used
- Testable
Frameworks Outside Core
- An arbitrary number of API
Clients, AUX & Domain Details
- Interchangeable Details
Agile. Better allocation of team members
- I.e. group working on Domain
- I.e. group working on domain
Persistence
- I.e. group working on integration
to Payment Gateways
Other Features
- Single Entry-Point
- Rigorous modules dependencies
- Domain model does not leak to API Clients
- Reusable AUX Details
Recognizable. 1:1 theory and practice
Fits smoothly to DDD
Trinity is in accordance to the rules of
Tactical Techniques for DDD
Related Tools
Trinity Demo in Java
Demo microservice application structured according to the Trinity Architecture.
https://github.com/oregor-projects/trinity-demo-java
Trinity Scaffolder for Java Projects
Scaffolder for Java applications based on the Trinity Architecture.
https://github.com/oregor-projects/trinity-scaffolder-java
trinity4j
A set of Domain-Driven Design Libraries for Java Applications:
https://github.com/oregor-projects/trinity4j
Related Work
DDD: “Focus on the Domain”. But, there is more...
https://polygenesis.io
Thank you!
Christos Tsakostas
https://www.linkedin.com/in/tsakostas
ct@oregor.com

The Trinity Architecture