Clean architecture

Feature-first

One notes folder holds domain, application, infrastructure, and presentation. The composition root stays shared.

clean-architectureserverpodfeature-first

Feature-first puts the whole notes use case in one folder. features/notes/domain, application, infra, and presentation sit together. A small shared/ kernel holds ValidationFailure. app/ is still the only wiring site.

Open features/notes/ and you can read save-a-note without jumping to four top-level directories. The dependency rule is unchanged: features/notes/domain imports nothing from the other three, even though they are siblings.

The tree

text
lib/src/features/notes/domain/note.dart
lib/src/features/notes/application/save_note_use_case.dart
lib/src/features/notes/infra/note_repository_impl.dart
lib/src/features/notes/presentation/notes_endpoint.dart
lib/src/features/notes/presentation/wire_mappers.dart
lib/src/shared/validation_failure.dart
lib/src/app/use_cases.dart
lib/src/bootstrap/talaria_monitoring.dart

The package is examples/serverpod/feature_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 layer-first and hybrid. The chooser is the table of where a file sits.