LogoTRUONG PHAM
Home
Projects
Blogs
YouTube
Contact

Newsletter

Stay updated with technical artifacts and engineering insights.

LogoTRUONG PHAM

Building scalable software and sharing insights on technology & life.

Sitemap

  • Home
  • Projects
  • Blogs
  • YouTube
  • Contact

Connect

  • GitHub
  • LinkedIn
  • Email
  • YouTube

© 2024 TRUONG PHAM. © All rights reserved.

Privacy PolicyTerms of Service
Back
Blog #35: Clean Architecture – The Dream and the Harsh Reality
50 FRONTEND LESSONS – HARD-EARNED EXPERIENCES

Blog #35: Clean Architecture – The Dream and the Harsh Reality

When over-applying Clean Architecture turns simple changes into a cumbersome and slow series of tasks.

TP
Truong PhamSoftware Engineer
PublishedJuly 5, 2024

Closing in on a release deadline. The designer requested changing a label from "Full Name" to "Full Name" (Vietnamese context: "Full Name" -> "Tên đầy đủ") and sourcing it from a new field in the API. A task that seemed like it would take 2 minutes. But no, I was applying Clean Architecture mechanically to this project.

I opened my editor and began the journey through the layers:

  1. Domain Model, 2. Data Entity, 3. Mapper, 4. Repository, 5. Use Case, and finally 6. UI Component.

I muttered under my breath: "Why did I make this so hard for myself?". I was writing dozens of lines of repetitive code just to display a simple label.

1. What happened?

The development process stagnated because the architecture was over-engineered. Even the smallest changes required updates across many intermediate layers, increasing the risk of errors and wasting time.

2. What I thought the cause was

I assumed it was because I didn't have fancy "Code Generator" tools to automate the creation of Boilerplate. I spent time researching code generation libraries instead of looking at the core issue.

3. How I debugged it

I ran a test: Measuring the actual time to add a new data field from the API to the UI. Results showed that 80% of the time was spent re-declaring near-identical Model/Entity classes at different layers.

4. The moment of realization

I realized I was applying architecture designed for massive enterprise systems to a medium-sized web application. Clean Architecture is truly great when business logic is extremely complex and needs to be completely independent of the Framework. But for this project, it was a chain holding back the speed of the whole team.

5. The fix

  • Quick patch: Skip the Mapper in a few less critical spots and pass data directly from the API to the UI to make the deadline.
  • Real fix: Simplify the architecture. Remove intermediate layers that don't provide real value. Apply the KISS (Keep It Simple, Stupid) philosophy: only abstract when absolutely necessary.

6. Looking back

Architecture exists to serve the project, not the other way around. Don't bring out a cannon to shoot a sparrow. If I were designing it again, I would prioritize pragmatism over the purity of architectural dogma.

Series • Part 35 of 50

50 FRONTEND LESSONS – HARD-EARNED EXPERIENCES

NextBlog #36: Touching Legacy Code – When a refactor effort becomes a disaster
Blog #34: My Machine Runs Smooth, the User's Machine Smokes
30Blog #30: A giant State Object doesn't make your code cleaner31Blog #31: 1 AM and the Search for the 'Missing' File32Blog #32: Friday Afternoon, 800 Lines of Code, and a Miscalculation33Blog #33: 10 PM and the 'Infinite Loop' of Punishment34Blog #34: My Machine Runs Smooth, the User's Machine Smokes35Blog #35: Clean Architecture – The Dream and the Harsh RealityReading36Blog #36: Touching Legacy Code – When a refactor effort becomes a disaster37Blog #37: The Reusability Trap – When a 'multi-purpose' Component becomes a burden38Blog #38: Micro-frontend Reality Check – When theoretical glory meets harsh reality39Blog #39: The 'Will Fix Later' Promise and the Compound Interest of Technical Debt40Blog #40: Don't try to be smart – Write code for humans, not for machines
TP

Written by Truong Pham

Software Engineer passionate about building high-performance systems and meaningful experiences.

Read more articles