Architecture

Vertical architecture VS Horizontal architecture #

✅ What is Layered Architecture? #

Layered architecture (also called n-tier architecture) organizes code into horizontal layers, where each layer has a specific role and communicates only with the layer directly below it.

Typical Layers: #

  1. Presentation layer – UI or API layer (e.g. controllers).
  2. Application layer – Coordinates use cases, handles application logic.
  3. Domain layer – Business logic, entities, domain rules.
  4. Infrastructure layer – External systems (DBs, APIs, files, etc).

📌 Direction of dependencies: Upper layers depend on lower ones (e.g., UI → Application → Domain → Infra).


✅ What is Horizontal Architecture? #

This usually refers to organizing code by feature or module, not by technical layer. Each module contains its own UI, business logic, and data access.

Example modules:

  • orders/

    • controller.py, service.py, repository.py
  • users/

    • controller.py, service.py, repository.py

📌 It’s also called feature-based, modular, or sometimes vertical slicing (opposite of horizontal layering).


✅ Clean Architecture Patterns: Horizontal or Layered? #

Clean Architecture (as proposed by Robert C. Martin) is technically a layered architecture, but with a twist: inversion of dependencies.

Clean Architecture Layers (from center out): #

  • Entities (core domain)
  • Use Cases / Interactors
  • Interface Adapters (controllers, presenters, gateways)
  • Frameworks & Drivers (web, DB, etc.)

But in Clean Architecture:

Dependencies must always point inward, toward the business rules.

So:

  • Clean Architecture is layered.
  • It’s not horizontal, because it organizes code by layers, not by feature.

🧭 Other Architectural Styles #

Here are some other major ones to know:

Architecture Style Organized By Notes
Layered (N-tier) Technical layers Most common in monoliths
Modular (Horizontal) Feature/modules Easier for microservices or large codebases
Clean Architecture Layers (domain-centric) Dependency inversion + layered
Hexagonal (Ports & Adapters) Layers (with ports) Similar to Clean but uses adapters/ports explicitly
Onion Architecture Layers (like Clean) Emphasizes domain core at center
Screaming Architecture Features/modules Code “screams” what app does, not tech it uses

🧠 Summary #

Architecture Horizontal or Layered? Organized By
Layered/N-tier ✅ Layered Technical layers
Clean Architecture ✅ Layered Business logic layers
Modular (vertical slice) ✅ Horizontal Features/modules
Hexagonal ✅ Layered Domain + adapters
Onion ✅ Layered Domain-centric layers
Screaming Arch. ✅ Horizontal Use case/domain name first

Would you like a diagram comparing these visually?