Chapitre 1 · Leçon 1
Séparer les couches pour un code testable
Section 1
Step 1
Clean Architecture adapte ses 3 couches au mobile : Domain (pur Dart), Data (sources de données), Presentation (widgets + state).
snippet.dart
1// Structure recommandée par feature
2lib/
3├── core/
4│ ├── error/
5│ │ ├── failures.dart // Sealed classes d'erreurs
6│ │ └── exceptions.dart
7│ └── usecases/
8│ └── usecase.dart // Interface générique
9│
10└── features/
11 └── tutorials/
12 ├── domain/
13 │ ├── entities/
14 │ │ └── tutorial.dart // Entité pure (Dart seul)
15 │ ├── repositories/
16 │ │ └── tutorial_repository.dart // Interface abstract
17 │ └── usecases/
18 │ ├── get_tutorials.dart
19 │ └── get_tutorial_by_slug.dart
20 │
21 ├── data/
22 │ ├── models/
23 │ │ └── tutorial_model.dart // Entité + fromJson/toJson
24 │ ├── datasources/
25 │ │ ├── tutorial_remote_ds.dart
26 │ │ └── tutorial_local_ds.dart
27 │ └── repositories/
28 │ └── tutorial_repository_impl.dart
29 │
30 └── presentation/
31 ├── providers/
32 │ └── tutorials_provider.dart
33 └── screens/
34 ├── tutorials_screen.dart
35 └── tutorial_detail_screen.dartStep 2
Le flux est toujours : Présentation → Usecase → Repository (interface) → Impl → DataSource. La couche domain ne sait rien des couches externes.