A flexible folder structure designed for projects of all sizes (MVPs, large complex enterprise projects), based on organizing code by specific package by application cases (app cases).
This isn't a brand new architecture, but rather a clear way to visualize and implement "vertical slicing" in your codebase.
Many existing folder conventions rely on traditional layered structures (package by layer), sometimes mistakenly labeled as "hexagonal" or "clean architecture." However, these architectures don't inherently dictate a horizontal (layered) approach.
Let's move away from big service files and horizontal folder structures!
"A layered architecture doesn't scream anything about business domain"
— Missing chapter, Clean architecture, Robert C Martin and Simon Brown
"As an application grows, each layer can get sufficiently complex on its own that you need to modularize further. When this happens it's usually not best to use presentation-domain-data as the higher level of modules. Often frameworks encourage you to have something like view-model-data as the top level namespaces; that's OK for smaller systems, but once any of these layers gets too big you should split your top level into domain oriented modules which are internally layered."
— Presentation Domain Data Layering, Martin Fowler
"The pattern has absolutely nothing to say about how you structure your application internally."
— Hexagonal Architecture, Alistair Cockburn
This structure has been successfully tested with:
- Serverless architectures using Lambda handlers
- NodeJs (ExpressJS, KoaJS, CLI)
- Domain-Driven Design (DDD)
- MVPs (without clean or hexagonal architecture)
- NestJS (avoiding excessive service files)
- Enterprise Projects (with clean architecture and DDD)
- Prioritize Critical Thinking: Don't always rely on common sense; it might not be accurate.
- Learn from Others: Many people (some of them popular) have likely encountered similar challenges. Follow their lead.
- Discover Better Ways to Develop Software: Embracing experimentation is crucial for enhancing project success.