Why should you structure your solution by components?

Technology CommunityCategory: Layering & MiddlewareWhy should you structure your solution by components?
VietMX Staff asked 3 years ago

For medium sized apps and above, monoliths are really bad – having one big software with many dependencies is just hard to reason about and often leads to spaghetti code. Even smart architects — those who are skilled enough to tame the beast and ‘modularize’ it — spend great mental effort on design, and each change requires carefully evaluating the impact on other dependent objects.

The ultimate solution is to develop small software: divide the whole stack into self-contained components that don’t share files with others, each constitutes very few files (e.g. API, service, data access, test, etc.) so that it’s very easy to reason about it.

Some may call this ‘microservices’ architecture — it’s important to understand that microservices are not a spec which you must follow, but rather a set of principles.

  • Structure your solution by self-contained components is good (orders, users…)
  • Group your files by technical role is bad (ie. controllers, models, helpers…)