inflearn logo

Toby's Clean Spring - Domain Model Pattern and Hexagonal Architecture Part 2

Toby's Clean Spring is a course designed to let you experience the process of developing a fast, stable, flexible, and maintainable system by following clean code and Spring development principles step-by-step. It follows a format similar to real-world work within a fictional startup development team that builds and operates an online education service called Splearn.

(5.0) 2 reviews

73 learners

Level Basic

Course period Unlimited

Java
Java
Spring
Spring
Spring Boot
Spring Boot
JPA
JPA
Refactoring
Refactoring
Java
Java
Spring
Spring
Spring Boot
Spring Boot
JPA
JPA
Refactoring
Refactoring

What you will gain after the course

  • How to structure the inside of a Hexagonal Architecture with application components

  • Strategies for safely implementing and evolving complex domain logic using the Domain Model pattern

  • Practical experience in reviewing design trade-offs and improving existing designs through refactoring

  • Developing test fixtures using random data and methods for efficient test writing

  • How to verify dependency rules between components with ArchUnit

  • Design techniques for resolving bidirectional dependency issues using DIP

In an era of delegating code to AI,
the judgment and design skills developers need

If you simply leave development to AI, it is easy to end up with the most average Spring code, or even code mixed with anti-patterns.

Even if AI writes the code, the final review and responsibility lie with the developer. It is up to the developer to decide on trade-offs for what is best, and to create domain model design documents, development guides, and architecture tests that will serve as a harness for the AI.

Ultimately, the power to control AI comes from architecture, domain models,
and the ability to design maintainable code.




Building Competency 1. A Developer's Judgment

Join Toby's team to build
a Spring service.

<Toby's Clean Spring> is a course where you develop a fictional online education service called 'Splearn' together, experiencing the entire process from planning and design to implementation and refactoring as if it were a real-world project.

You will become a team with Toby to complete a single service together. At each stage, you will follow the thought process of a developer with 31 years of experience, learning what to consider and what decisions to make. Through this process, you will develop the ability to understand the context of "when and why a certain technology is needed" and "why it was designed with this structure."

<Toby's Clean Spring> Roadmap
This is a series of lectures for mastering clean code and Spring development principles. It covers the growth process of Spring applications across 7 lectures, from domain modeling to MSA and observability. (
View Roadmap>>)


Building Competency 2. Code Design Skills


Clean Spring for Sustainable Code

Clean Spring is the core principle we focus on throughout this entire process.

Clean Spring is a practical strategy for applying 'Clean Code' principles to Spring development. The goal is not just to have code that looks good, but to simultaneously boost team productivity and long-term code quality. Kent Beck's phrase "Clean Code That Works" perfectly illustrates this core philosophy.

Maintainability and productivity are prerequisites for each other. Code must be easy to change to be easy to maintain, and the ability to change it quickly is what increases productivity. Refactoring is essential to create this structure, and the prerequisite for that is test code.

And once you have a grasp of these standards, it finally becomes clear what and how to instruct the AI.

Toby's Clean Spring, the first topic

Domain Model and
Hexagonal Architecture

The beginning of clean Spring development starts with a deep understanding of the problem the service aims to solve (the domain). The core strategies for reflecting this in code and designing it so that it can evolve stably even as features expand are the Domain Model pattern and Hexagonal Architecture.

In this course, we will actually apply domain models and hexagonal architecture based on the latest Spring, Web, and JPA technologies, and together solve core practical concerns encountered in the early stages of a project, such as establishing project structure, module separation, collaboration methods, and testing strategies. In this process, you can experience the flow of developing domain models through refactoring.

<Domain Model and Hexagonal Architecture> consists of two parts: Part 1 and Part 2.


Part 1. Focusing on member functions, we will practice building the foundation of the domain model and architecture, designing core logic, structuring, and development methods based on test code. (Go to Part 1 >)

Part 2. Handle complex requirements and redesign models, applying in-depth design, various refactoring techniques, and test support tools required for practical work. ✔️ This course


Domain Model and Hexagonal Architecture Part 2

Learning Content

Part 1 Feedback and Design Refactoring

We will review the existing design based on feedback and questions from those who took Part 1. We will examine the exact meaning of design trade-offs and perform a design change to separate domain value objects from application DTOs using Martin Fowler's method of safe, incremental refactoring. You can learn how to carry out refactoring while ensuring that tests always remain in a passing state.

Designing Hexagonal Ports to Reveal Communication Intent

Ports capture the intention of how an application interacts with the outside world. Instead of cramming all methods into a single massive service interface, how to organize ports by communication intent according to the Interface Segregation Principle (ISP) will be practiced through the development of a member authentication port. By writing port tests based on interfaces, we will cover how to make them resilient to refactoring and how to formalize the team's design conventions into development guide documentation.

Application Components - Internal Structure of Hexagonal

Hexagonal architecture does not provide answers on how to organize the interior. In this lecture, we borrow the concept of UML components and propose a strategy to design a single aggregate and its surrounding application services as independent and replaceable modular units called application components. We will establish practical principles such as direct versus identifier references between aggregates, limiting units of change, and unidirectional dependencies between components, and complete four components—Instructor, Lecture, Enrollment, and Curriculum—one by one.

Test Improvement and Architecture Verification

Architectural principles should be enforced by test code, not by human attention. You will learn how to explicitly state architectural intent in code using custom stereotype composite annotations and how to use ArchUnit to automatically verify team architectural rules—such as prohibiting cyclic dependencies between slices and blocking state changes of other aggregates—at build time. Additionally, you will practice techniques to improve both the quality and efficiency of test code writing by utilizing random test data with Instancio, test fixtures, and base classes.

Aggregate Design and TDD for Complex Domains

We will model the lifecycle of a course (Draft-Review-Published-Archived) as state transitions and establish standards for using composite natural IDs, exceptions, and Optionals in enrollments. In the final curriculum component, you will experience how the discovery of a ubiquitous language resolves aggregate boundary issues, and develop complex collection-based domain logic—such as adding, moving, and deleting sections and lessons—using TDD. Furthermore, we will effectively persist aggregates using @OrderColumn and @EntityGraph, and catch N+1 problems by verifying the number of executed queries through tests using Hibernate statistics.

Solving Component Dependency Issues Using DIP

As the number of components increases, the temptation of circular dependency arises. By resolving the bidirectional dependency issue between courses and curricula, we confirm that merely depending on an interface is not enough, and that true Dependency Inversion (DIP) is achieved only when even the ownership of the interface is inverted. You will also come to understand that the required ports in Hexagonal Architecture are a practical application of DIP.

Recommended for
these people

Who is this course right for?

  • Those who have studied Clean Spring Part 1 and wish to complete the actual implementation of the remaining domains.

  • For those who are curious about how to apply the Domain Model pattern and Hexagonal Architecture to complex, real-world domains.

  • Developers who feel lost on how to divide and organize internal structures as their applications grow larger

  • Those who feel that development is slowing down because of creating tests and are looking for ways to write tests quickly and effectively.

  • A developer who wants to use code to verify and maintain architecture rules that previously only existed in documentation before falling apart.

  • Developers who want to possess the design capabilities to understand and review code created by AI coding agents.

Need to know before starting?

  • Java Language - JDK21

  • Understanding the Basic Principles of Spring

  • Experience in developing applications using Spring Boot with Web APIs and JPA

Hello
This is tobyilee

Inflearn Verified

16,212

Learners

1,109

Reviews

427

Answers

5.0

Rating

9

Courses

I am a software developer living in Australia. I have 30 years of experience developing systems and services across various fields.

I love the Spring Framework and its related technologies, and I primarily use JVM-based languages.

I founded and have been active in the Korea Spring User Group (KSUG), and I also wrote the book Toby's Spring.

I enjoy talking about various topics related to development.

I founded and was active in the Korea Spring User Group (KSUG), and I also wrote the book *Toby's Spring*. I enjoy talking about various topics related to development.

I founded and was active in the Korea Spring User Group (KSUG), and I also wrote the book *Toby's Spring*. I enjoy talking about various topics related to development.

More

Curriculum

All

48 lectures ∙ (12hr 58min)

Course Materials:

Lecture resources
Published: 
Last updated: 

Reviews

All

2 reviews

5.0

2 reviews

  • zin님의 프로필 이미지
    zin

    Reviews 3

    Average Rating 5.0

    5

    100% enrolled

    In the era of AI, Clean Spring will serve as a guide on what kind of harness we should provide to AI. This is because we must provide an environment where developers can trust and develop alongside AI, including domain model documentation, development guides, and architecture tests. In that sense, I believe this Clean Spring 1 Part 2 can help you or your development team develop in the direction you expect. This lecture is also fun. 😊 I hope many developers take this course!

    • geminikims님의 프로필 이미지
      geminikims

      Reviews 3

      Average Rating 5.0

      5

      33% enrolled

      This is a truly essential lecture, even in an era where AI writes code! It is a course well worth the purchase, as it allows you to steal a glimpse into Toby's perspective on implementation, refactoring, and test code, as well as the way he unfolds his thought process regarding development. In particular, the final summary session contains Toby's insights into the current era, making me feel that humans still need to study, learn, and train more. Beyond just the main topic of the lecture, I recommend this to any developer, regardless of their years of experience!

      tobyilee's other courses

      Check out other courses by the instructor!

      Similar courses

      Explore other courses in the same field!

      Limited time deal

      $9,016.00

      30%

      $77.00