Layered, modular monolith, clean, and hexagonal architecture
standardintermediateAll four are ways to stop business logic from depending directly on a database or a web framework. Layered stacks responsibilities top to bottom; modular monolith groups by feature instead of layer; clean and hexagonal both point every dependency inward, toward the business rules.
Think of it as
Layered architecture is a one-way street: presentation calls service, service calls repository, repository calls the database — each layer only knows the one below it. Clean and hexagonal architecture redraw that street as a circle: business rules sit in the center depending on nothing, and the database, the web framework, and the CLI are all replaceable plugins on the outside that depend inward on the business rules, never the reverse. A modular monolith keeps everything in one deployable process but slices it by feature (orders, billing, shipping) instead of by layer, so each slice can still be layered internally.
- Presentation — HTTP views, CLI commands — talks to the service layer only
- Service — Business use cases — talks to repositories through an interface
- Repository — Data access — the only layer that imports a database driver
- Database — PostgreSQL, SQLite, or any storage the repository wraps
Comparing the four styles
Together
Remember: All four styles exist to stop business rules from depending on infrastructure — layered stacks that rule top-down, clean/hexagonal make it a hard boundary business code cannot cross.
See also: domain driven design fundamentals · repository · service layer

