DEV Community

Cover image for 🧠 From Chaos to Clean Code: My Java Refactor Journey - Part 1 of 6
Gabriela Goudromihos Puig
Gabriela Goudromihos Puig

Posted on

🧠 From Chaos to Clean Code: My Java Refactor Journey - Part 1 of 6

I wanted to challenge myself to apply Clean Architecture and Domain-Driven Design (DDD) from the ground up β€” not in a greenfield project, but starting from total mess.

So I built Spaghetti API: a deliberately chaotic Spring Boot project, full of bad practices, no architecture, and zero tests.

It looks like this πŸ‘‡

src/main/java/com/example/spaghetti
β”œβ”€β”€ ControllerService.java     // controller acting as service
β”œβ”€β”€ ModelRepoController.java   // model + repo + controller in one
β”œβ”€β”€ Utils.java                 // weird helpers
β”œβ”€β”€ MainConfig.java            // useless bean
β”œβ”€β”€ SpaghettiApplication.java

Enter fullscreen mode Exit fullscreen mode

🧩 Why?

Because most real-life projects don’t start clean β€” they evolve from chaos. I wanted to document how I bring order, step by step.

πŸ› οΈ My refactoring path

  • Separate responsibilities (controller, service, repo, model)
  • Introduce Clean Architecture layers
  • Apply DDD concepts with proper domain modeling
  • Add DTOs, validations, global error handling
  • Implement unit and integration tests

βœ… Technologies

  • Java 17
  • Spring Boot 3
  • Maven

πŸ”— Source Code

πŸ‘‰ github.com/gabrielapuig/spaghetti-api

If you're dealing with a messy legacy codebase 🧹, or want to level up your architecture skills in Java β˜•οΈ, follow along β€” I’ll be sharing each refactor stage πŸ”„ and breaking it down step-by-step.

Ever worked on a project like this? πŸ€” I'd love to hear how you handled it!

Top comments (3)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

this is extremely impressive seeing someone work through a real mess instead of just showing a polished demo makes it way more useful for me you think starting with chaos actually speeds up learning or just adds extra pain

Collapse
 
gabrielapuig profile image
Gabriela Goudromihos Puig

Thanks! I do think starting with chaos is harder, but it teaches way more. You're forced to really understand what’s going on instead of just following steps.

Painful? Yes. Worth it? Definitely. πŸ˜…

Collapse
 
carolina_puig profile image
Carolina Goudromihos Puig

Very interesting idea!! I’ll join this Spaghetti journey☺️🍝