Frontend Architecture: How to Build a Zoo?

A presentation at Webinale 2023 in May 2023 in Berlin, Germany by Thomas Gossmann

Slide 1

Slide 1

Frontend Architecture: How to Build a Zoo? Thomas gossi Gossmann unistyler gossi gos.si

Slide 2

Slide 2

What is Software Architecture? - Architecture is a skill, not (just) a role - The ability to design a system, reason about tradeoffs and understand the design - Flow of decisions (instead of upfront design work) - “Software architecture is the stuff that’s expensive to change” Examine this while building a zoo Disclaimer: I’m not a domain expert for a zoo. This is all made up.

Slide 3

Slide 3

Part 1 Strategic Design Level 1 Zoo

Slide 4

Slide 4

What does this product do? (1)

Slide 5

Slide 5

What does this product do? (2)

Slide 6

Slide 6

What does this product do? (3)

Slide 7

Slide 7

Identify the Domain ● Why do People come to the Zoo? ○ ○ ○ ○ Animals (Fauna) ? Plants (Flora) ? Info-/Entertainment ? Food & Drinks ?

Slide 8

Slide 8

Identify the Domain Core Supporting Generic Animals Plants Food & Drinks Info-/Entertainment Restrooms

Slide 9

Slide 9

Identify the Domain Core Supporting Generic Animals Plants Food & Drinks Info-/Entertainment Restrooms

Slide 10

Slide 10

Distilling the Domain https://www.zoo-berlin.de

Slide 11

Slide 11

Distilling the Domain Themed Areas Aviary Savanna Antarctica Asia Mountains Africa Predators Aquarium Oceania

Slide 12

Slide 12

Bounded Contexts ● ● ● ● ● Multiple models can co-exist in a big project Contexts need explicit boundaries Model strictly consistent within the context Clear definitions communicate the purpose Context gives autonomy

Slide 13

Slide 13

Bounded Contexts Option 1: Compounds Reasons: ● ● ● Picture from: https://www.glmv.com/work/zoo-boise-master-plan/ They have natural boundaries Can react to outside events Autonomous inside

Slide 14

Slide 14

Bounded Contexts Option 2: Separate by Functional Staff Reasons: Zookeeper Medical Staff - Anthropometry - Blood samples - Excrements

  • Food - Water - Clean compound Gardener - Which plants are growing? - What are toxic plants to an animal? ● ● Functional teams Ubiquitous language by discipline

Slide 15

Slide 15

Bounded Contexts Option 3: Areas Reasons: ● ● ● Cross-Functional teams per area Follows the team’s communication structure (Conway’s law) Keeps communication paths short

Slide 16

Slide 16

Bounded Contexts Compounds Reasons: ● ● ● Picture from: https://www.glmv.com/work/zoo-boise-master-plan/ Natural Boundaries are a great metaphor I’m not a domain expert for Zoo at all Use themed areas for hierarchical organization

Slide 17

Slide 17

Zoom Levels Level 1 Zoo Level 2 Area Level 3 Compound Level 4 Code

Slide 18

Slide 18

C4 Model model for visualising software architecture “maps of your code” Simon Brown c4model.com

Slide 19

Slide 19

Vocabulary = Scary Generic Co nte xt M Subdom ap pin ain domain b u S g portin g in Sup ling l i t s Di ext nded Cont Bou or C De -co e mp osi n ai m Do tion nguage us La Ubiquito the a Dom

Slide 20

Slide 20

Zoom Levels You Business Level 1 Level 2 Entire Business Zoo Area Level 3 Compound Level 4 Business Capabilities Business Services Business Rules Code

Slide 21

Slide 21

Zoom Levels Level 1 Level 2 Business C4 You Area Level 3 Compound Level 4 Entire Business Business Capabilities Business Services Business Rules Context Containers Components Code Zoo Code

Slide 22

Slide 22

Zoom Levels Level 1 Level 2 Business C4 You Area Level 3 Compound Level 4 Entire Business Business Capabilities Business Services Business Rules Context Containers Components Code Zoo Code

Slide 23

Slide 23

Zoo Folder Structure Level 1 Zoo

Slide 24

Slide 24

Strategic Design Result ★ ★ ★ ★ Understand the domain Distilled the domain into manageable pieces Carved out bounded context Established a language that works across disciplines

Slide 25

Slide 25

Part 2 Tactical Design Level 2 Area Level 3 Compound

Slide 26

Slide 26

Models Expressed in Software Value Objects Repositories Aggregates Entities Events Services Factories Level 2 Area

Slide 27

Slide 27

Aggregates Aggregate Value Object Backend Value Object Entity Root Entity Frontend

Slide 28

Slide 28

Aggregates Aggregate Value Object Backend Value Object Entity Root Entity Aggregate’ Value Object’ Frontend Value Object’ Entity‘ Root Entity’

Slide 29

Slide 29

Services Backend Frontend Domain Service Business Process (eg. feeding Animals)

Slide 30

Slide 30

Services Backend Frontend Domain Service UI Business Process (eg. feeding Animals) Screens Forms Status Elements

Slide 31

Slide 31

User Interfaces

Slide 32

Slide 32

User Interfaces

Slide 33

Slide 33

User Interfaces

Slide 34

Slide 34

Component Classification Areas Use for housing multiple compounds (Screens/Routes/Pages) Pathways The same walking infrastructure for visitors of a zoo

Slide 35

Slide 35

Component Classification Compounds A component representing a compound Interior Custom tailored interior for one compound Carryables Elements that can be moved around (from one compound to another)

Slide 36

Slide 36

Models Expressed in Software Value Objects Repositories Aggregates Entities Events Services Factories Level 2 Area

Slide 37

Slide 37

Event Storming Event Command Read Model System Policy Actor Collaborative exploration of complex business domains Alberto Brandolini eventstorming.com

Slide 38

Slide 38

Models Expressed in Software Value Objects Repositories Level 2 Area Aggregates Entities Commands Events Services Factories

Slide 39

Slide 39

OOUX Object Contents Actions Metadata Object Oriented UX Object-Oriented UX offers a better way to break up complexity, allowing us to work iteratively and holistically Sophia Prater ooux.com

Slide 40

Slide 40

An OOUX Animal Animal Watch Name Feed Fur Pet Family Genus Diet

Slide 41

Slide 41

Backend + Frontend Level 2 Area Repositories Backend Value Objects Events Frontend Factories Entities Aggregates Commands Services

Slide 42

Slide 42

Backend + Frontend Level 2 Area Repositories Backend Factories Value Objects Events Aggregates Entities Commands Services Objects Content Frontend Metadata Actions UI

Slide 43

Slide 43

Backend + Frontend (Communication) Repositories Backend Area Factories Value Objects Events Level 2 Aggregates Entities Commands Services Objects Content Frontend Metadata Actions UI

Slide 44

Slide 44

Backend + Frontend (Organization) Repositories Backend Area Factories Value Objects Events Level 2 Aggregates Entities Commands Services Objects Content Frontend Metadata Actions UI

Slide 45

Slide 45

Separate UI and Business Logic Business Logic ● ● ● Visual Representation Aggregates / Entities / Value Objects (Nouns) Actions (Verbs) Policies & Rules Communicate System State Offer Behavior ● ● Benefits ● ● ● ● Maintainability Readability The feeling of “home” Fast feature development

Slide 46

Slide 46

Area Folder Structure Theme Area Bounded Context Business Logic UI Bounded Context

Slide 47

Slide 47

Tactical Design Result ★ ★ ★ Frontend Modeling = Backend + Design Separate UI and Business Logic Component Classification that follows the established language

Slide 48

Slide 48

Part 3 Code Level 4 Code

Slide 49

Slide 49

Aggregate / Reactivity ● Plain JS/TS (Framework Agnostic) ● Connect to your Reactivity System (UI / State Management)

Slide 50

Slide 50

What’s your choice? Aggregate / Reactivity ● ● Plain JS/TS (Framework Agnostic) Connect to your Reactivity System (UI / State Management) Classes ● ● (de)serialization (re)hydration Functional ● ● DTO transforms

Slide 51

Slide 51

CQS: Command & Query Separation Methods to either be commands that perform an action or queries that respond data, but neither both! Queries - Questions: Ask facts about the system Abilities/Authorization: Control access Actions & Commands - Command Design Pattern Commands: Used in Backend to perform business logic Actions: Used in Frontend to connect vocabulary with designers and probably call commands in the backend

Slide 52

Slide 52

Queries Questions: Abilities: Ask facts about the system? Control access Expect to have hundreds of these

Slide 53

Slide 53

Queries Abilities: Control access Picture from: https://www.glmv.com/work/zoo-boise-master-plan/

Slide 54

Slide 54

Queries ❌ DO NOT ✅ DO Inline conditionals (in templates) Extract into function

Slide 55

Slide 55

Actions Cause side-effects / Invoke commands on the backend

Slide 56

Slide 56

Connect to your UI UI Code is reduced to its essentials Connecting UI elements with your existing business logic

Slide 57

Slide 57

Deterministic Behavior and State Management Example: Using a Statechart to control the mood of monkey Deterministic behavior Use existing business logic

Slide 58

Slide 58

Pure Core ● Extract core into plain JS/TS ○ ○ ○ ● ● ● ● Aggregates / Entities / Value Objects Actions Abilities & Questions Framework agnostic Control your app through core High and excellent test coverage Use folders as signposts

Slide 59

Slide 59

Use folders as signposts Three examples for core/ Files + Folder give a home Choose based on your needs

Slide 60

Slide 60

Code Result ★ ★ ★ ★ ★ ★ Core layer in plain JS/TS Unit testing for your business logic Connect them to your reactivity system Connect core to UI, machines and other parts Use CQS design pattern Use folders as signposts

Slide 61

Slide 61

Summary ★ ★ ★ ★ Use available methodologies (EventStorming, OOUX, Atomic Design) Extract and apply the essence Establish your own language bound to your product Let the code speak your product

Slide 62

Slide 62

Thank you Thomas gossi Gossmann unistyler gossi gos.si