VSA + DDD

VSA + DDD

VSA and DDD compose well: VSA tells you where the code lives, DDD tells you what the code is. Most healthy combinations: one slice approximately equals one bounded context.

Mapping slice to bounded context

The clean case:

src/
  order/         <- bounded context "Order"
    domain/
      order.py       # Aggregate
      events.py
    application/
      place_order.py
    ...
  customer/      <- bounded context "Customer"
    ...

One slice per BC. Each slice's domain/ is one BC's tactical model. Slices communicate by domain events or IDs — same as bounded contexts.

When one BC has multiple slices

A large bounded context can split into sub-slices for ergonomic reasons (different teams, very different feature sets within the same model):

src/
  order/                  <- one bounded context "Order"
    placing/              <- slice
      domain/             # Order aggregate
      application/
        place_order.py
    fulfilment/           <- slice
      application/
        ship_order.py

This works only if both slices share the same ubiquitous language and respect the same aggregate boundaries. Otherwise it's two pretending to be one.

How DDD building blocks map into a slice

DDD block Slice location
Aggregate root domain/
Value object domain/ (or shared/ if truly cross-context)
Repository protocol domain/
Repository impl infrastructure/
Domain service domain/
Domain event domain/events.py
Application service (use case) application/use_cases/
Integration event publisher infrastructure/

Slice boundaries vs bounded context boundaries

When they align, life is easy. When they don't:

Two failure modes

  1. VSA without DDD. Slices are folders with no model discipline. Each slice has its own anaemic OrderService operating on raw dicts. VSA's structure without DDD's substance.
  2. DDD without VSA. All aggregates in domain/, all use cases in application/. Domain is well-modelled but feature ownership is unclear; adding a feature requires hunting across layers.

Either alone is fine. Together is usually what you want for non-trivial domains.

Practical advice