When I first stepped into backend development, I believed programming was only about one thing:
“If the output comes, the job is done.”
I bundled everything into one giant file — controllers, logic, database access.I didn’t understand why Spring insisted on layers or why DI, IoC, and annotations were so important. The project structure looked overwhelming, and everything felt abstract.
Everything changed the day I decided to trace my first Spring Boot request and watch how a simple API call traveled through the system. Suddenly, what looked like scattered pieces turned into a well-designed, meaningful architecture. It didn’t just teach me Spring Boot — it changed the way I think about writing software.
What I Used to Think Backend Development WasIn the beginning, this was my reality:
It was like trying to build a house without knowing what bricks, beams, or foundations were.
The Turning Point: Tracing My First RequestOne day, I opened my console logs and started following the journey of an incoming request:
That visual flow — even just in the logs — changed everything for me.
I realized:
Architecture became a living system, not a theory.
Controller → Service → Repository: The Flow That Made Everything ClickController — The Entry PointThe controller receives the request, interacts with the service, and returns the appropriate response or view.
@Controller@RequestMapping("/employees")public class EmployeeController { private EmployeeService employeeService; public EmployeeController(EmployeeService theEmployeeService) { employeeService = theEmployeeService; } @GetMapping("/list") public String listEmployees(Model theModel) { List<Employee> theEmployees = employeeService.findAll(); theModel.addAttribute("employees", theEmployees); return "employees/list-employees"; }}
Controllers should be small and focused — no business logic inside them.
Service — The Logic LayerThis is where business decisions happen. It protects the repository from being accessed directly.
public interface EmployeeService { List<Employee> findAll(); Employee findById(int theId); void save(Employee theEmployee); void deleteById(int theId); boolean existsByEmailId(Employee theEmployee);}
Implementation:
@Servicepublic class EmployeeServiceImpl implements EmployeeService { private EmployeeRepository employeeRepository; @Autowired public EmployeeServiceImpl(EmployeeRepository theEmployeeRepository) { employeeRepository = theEmployeeRepository; } @Override public List<Employee> findAll() { return employeeRepository.findAllByOrderByLastNameAsc(); }}
The service layer keeps your application clean, secure, and maintainable.
Repository — Where Database Interactions HappenWith Spring Data JPA, repositories become incredibly simple:
public interface EmployeeRepository extends JpaRepository<Employee, Integer> { boolean existsByEmail(String email); List<Employee> findAllByOrderByLastNameAsc();}
The framework generates most queries automatically.
Entity — Mapping Java Objects to Database TablesEntities act as a bridge between the database and your Java application.
@Entity@Table(name="employee")public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @NotBlank private String firstName; @NotBlank private String lastName; @NotBlank private String email; // constructors, getters, setters}
Spring (plus Jackson) takes care of converting between JSON Java Database.
When MVC Finally Made SenseMoving into full MVC with Thymeleaf gave me clarity:
The project structure stopped looking like a burden and became something I respected. The flow felt natural and powerful.
A Simple CRUD Example That Made It RealThe moment everything clicked was when I saw this flow in my own CRUD app:
Suddenly the architecture wasn’t an academic concept — it was working in front of me.
Here is the GitHub repository of the CRUD app I used in this article:
https://github.com/MAffanG/employee-crud-api
What This Taught Me About CodingUnderstanding the request flow transformed everything about my approach:
This experience didn’t just teach me Spring Boot — it changed the way I respect software design as a whole.
The post How Understanding Request Flow in Spring Boot Changed the Way I Code appeared first on JVM Advent.