VSA vs Layered Architecture

VSA vs Layered Architecture

A reference for choosing between the two. Both are valid; they optimise for different things.

Side-by-side

LAYERED                      VSA
---------------              ---------------
src/                         src/
  domain/                      order/
    order.py                     domain/
    customer.py                    order.py
    payment.py                   application/
  application/                     place_order.py
    place_order.py               infrastructure/
    register_customer.py         presentation/
    capture_payment.py         customer/
  infrastructure/                domain/
    sql_order_repo.py              customer.py
    sql_customer_repo.py         application/
    sql_payment_repo.py            register_customer.py
  presentation/                  ...
    api/
      order_router.py        payment/
      customer_router.py       ...
      payment_router.py

Same code, different organising principle.

Side-by-side trade-offs

Concern Layered VSA
Onboarding ("where is X?") Need to know the layer One folder per feature
Adding a feature Touch 4+ folders Add 1 folder
Changing tech (DB, framework) One layer affected Touches every slice
Cross-layer refactoring Easy Spread across slices
Independent team ownership Hard Natural
Total file count Lower (DRY pulls in) Higher (some duplication)
Coupling discipline Implicit Must be made explicit
Suitable codebase size Small to medium Medium to very large
Deleting a feature Hunt across layers rm -rf order/

When each wins

Layered wins for:

VSA wins for:

A middle ground

A modular monolith with hexagonal layers inside each slice is VSA done with care: slices are the macro structure, each slice has its own layered (domain/application/infrastructure/presentation) interior. You get VSA's feature cohesion plus disciplined dependency rules within each slice.

Don't migrate halfway

The worst outcome: layered structure with order_service.py, order_repo.py, order_controller.py scattered across three layer folders, plus a features/order/ folder containing the new code. Pick one and stick to it; partial migrations leave both worse off.

A note on file duplication

VSA's "duplication" is mostly imagined. Two slices having their own Order model is not duplication — they're modelling different concepts that share a name (see Bounded Context). If they really were the same, the type belongs in shared kernel, not duplicated. The decision is deliberate, not accidental.