Architecture
Metadata
Lecture equivalent | Duration |
---|---|
5 | 3h 45min |
At the end of this task, students
- have analysed and deepened their knowledge on microservices
- have re-visited and iterated their diagrams from the C4 ExMan task - weaving in the new architecture knowledge
- have added a three-layer scaffolding to their spring-starter - let us name it small monolith
Deepen microservice knowledge
We will not apply microservices in this lecture. The overhead they generate is only acceptable if certain other requirements are fulfilled. None the less it is important to be familiar with the concept.
Task
Read Hexagonal Architecture.
Iterate the diagrams
You have enjoyed 90 minutes about architecture
. Funnel this knowledge now into your two diagrams from C4 ExMan.
Task
- Book a time slot with a fellow student of 30 min
- Revisit your diagrams from C4 ExMan, challenge them both ways with your colleague and iterate over them, applying your latest knowledge onto them
- Write down the findings
- Correct the findings and document them properly
We are again not aiming for the perfect diagram, we are learning once more one of our principles: Iterate - this time with a buddy!
To complete this task you are expected to hand in:
- Name of your review buddy
- List of changes/challenges you and your colleague discussed (e.g. questions she/he asked)
- Diagram before and after (both container and component diagram)
- Feedback on changes you made after receiving the feedback
Example
This is an example how to do it (the form) not the example solution (the result)!
Before
After
See C4 ExMan Sample - also I do not DRY.
Changes
Interview Buddy: Peter Pettigrew ๐
Challenge | Changes applied |
---|---|
What user groups are there defined? Manager seems quite generic | Added more than one actor as the requirements mention at least 3 user groups |
How does a human access the system? This is only an API | Split App into an API Application and a FrontEnd to separate backend from frontend and allow separate development |
Does it make sense to develop the user management ourselves? There seem to be quite good SaaS or OpenSource solutions out there | Switched internal user store for an external identity provider in order to increase security and focus development efforts |
Inspiration
Attention explorers
It is allowed to take your thoughts for a ride and go wild. While I did chose a monolithic sample solution it is also possible to already split up your design into more than one service. Just reason it well ๐ค
๐
It is super unlikely that two individually drafted designs come up equal. Just saying...
Scaffold
When you build a house, you might start with a dream. Then you get an architect and some rough plans. But one day comes the delve of spade
- some lines will be carved into the ground, some strings braced across the lawn to start digging.
Here will be the garage ๐ Here will be the living room ๐ Oh and here will be the garden house โฒ๏ธ
Ultimately, you pave the ground for the arrival of your new home. Let us draw some lines to prepare for the arrival of our code!
Content
- We will need some presentation layer - prepare a
controller
area - There will be some kind of persistence layer needed, an abstraction of the database or underlying persistence we use - prepare a folder for them
- Like in hexagonal architecture we will need some business logic or orchestration layer - pave its ground
If you have no clue ๐ก what I talk about, have a look at Three Tier Architecture in Spring MVC Web Application - it might inspire you.
Task
Create the scaffolding with empty folders. Shape the three layers!
Wiring
Empty folders are boring, lets solder in some small placeholders (for our house this would mean to maybe add some wood planks to walk between garden house and garage - to simulate the later way).
You will need all the knowledge of spring-starter otherwise you won't come too far ๐พ
Task
Complete the following step by step guide.
Empty files
Place a new Java class into each folder you created.
It could look like this:
โฏ cd src/main/java/ch/abbts/nds/swe/swdt/starter/solder
โฏ tree
.
โโโ controller
โย ย โโโ EmptyController.java
โโโ persistence
โย ย โโโ EmptyDb.java
โโโ service
โย ย โโโ EmptyService.java
โโโ solder.http
Understand dependencies
The controller (or however you paved your presentation layer) will require
(as dependency) the service (second layer). Said service will require in turn some persistence logic (the third layer).
If you understand that. Let's continue.
Soldering wire
We need something to solder the layers together. We can do this ourselves, oooooooooooooooooooooooooooooooooooooor we let Spring and its @Annotations
do it.
The two soldering wires we will need here are:
Annotation | Usage | Function in short |
---|---|---|
@Component | in classes that provide something and shall be injected, above the class statement | Adds the class/service/thing to the ApplicationContext effectively rendering it injectable for Spring |
@Autowired | in classes that want to get dependencies injected (here components), in the class{} | Searches the ApplicationContext and finds all injectables that match this Classname . |
Of course, you also need the already learnt annotations from spring-starter ๐
Solder ๐ฅ
Try to wire the three classes together. Create an empty endpoint, add one method. Autowire
the service into the controller. Head to the service, make it a Component
and directly Autowire
the database class into it. Open the database class, make it again a component and return something from an empty method.
For starter help, here is the service class:
@Component
public class EmptyService {
@Autowired
private EmptyDb db;
public String getData(){
return db.data();
}
}
Un-protect the route
In the spring-starter you made your endpoints secure. This proofs unhandy for this second so lets exclude the controller for now:
...
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
...
.antMatchers("/empty/**").permitAll()
...
}
Go ๐
You are all set. You created your own small monolith, with three empty layers that are ready to be filled. Nice job ๐ฆ๐คฒ๐พ
Start your app and call /empty
(or whatever you named your controller) and see
For master apprentices
You are of course free trying already now to combine ExMan and our starter together, trying to manage some expeditions or similar.
Commit and Push
Task
Add the results to your git repo!
Sample solution
Here.