Clean architecture

Layer-first

Top folders are the layers. The notes feature repeats inside each one, and wire mappers live in one shared file.

clean-architectureserverpodlayer-first

Layer-first is the horizontal tree. domain/, application/, infra/, and presentation/ are the top folders. notes is a folder inside each of them. app/ is the only place that constructs NoteRepositoryImpl.

This is the shape to copy from a Serverpod server whose modules repeat by layer: an endpoint under presentation/notes, a use case under application/notes, a port under domain/notes, and an impl under infra/notes. Wire mapping sits in presentation/mappers/wire_mappers.dart, one file for every endpoint, instead of beside a single feature.

The tree

text
lib/src/domain/notes/entities/note.dart
lib/src/domain/notes/note_repository.dart
lib/src/application/notes/save_note_use_case.dart
lib/src/application/ports/clock.dart
lib/src/infra/notes/note_repository_impl.dart
lib/src/presentation/notes/notes_endpoint.dart
lib/src/presentation/mappers/wire_mappers.dart
lib/src/app/use_cases.dart
lib/src/bootstrap/talaria_monitoring.dart

The package is examples/serverpod/layer_first. From that directory, dart test runs the domain test, the use-case test with a fake repository, and one integration test through the endpoint.

Read this track

  1. Pros and cons
  2. When to use it
  3. Domain
  4. Application
  5. Infrastructure
  6. Presentation
  7. Composition root
  8. Tests
  9. Talaria

Compare this tree with feature-first and hybrid. The chooser is the table of where a file sits.