Skip to content
Architecture
Architecture explorationIntermediate20 Aug 2026

Clean Architecture in Flutter: what actually matters

The parts of Clean Architecture that pay for themselves in a Flutter app, and the parts that are just extra files.

FlutterArchitectureClean Architecture

Most Flutter projects that say they use Clean Architecture have the folders and not the idea. You open lib/, find domain, data and presentation, and then find a widget importing http directly. The folders were free. The discipline was not.

Here is what I think is worth keeping and what I think you can drop.

The one rule that matters

Dependencies point inward. The UI knows about the domain. The domain knows about nothing.

That is the whole thing. If your domain layer imports Flutter, Dio, Firebase or a generated JSON model, the architecture is decoration.

dart
// domain/repositories/order_repository.dart
// No Flutter. No Dio. No JSON. Just what the app needs.
abstract class OrderRepository {
  Future<Order> placeOrder(Cart cart);
  Stream<OrderStatus> watchStatus(OrderId id);
}

The implementation lives in data/ and can be as ugly as the real API forces it to be. That ugliness stops at the boundary, and that is the point.

Why this pays off in Flutter specifically

Two reasons.

First, Flutter APIs change. Backend APIs change more. When your screens talk directly to Dio, an API change is a UI change, and now you are editing widgets to fix a response shape. With a repository in between, one file changes.

Second, testing. A widget test that needs a real HTTP client is a bad test. A use case that takes a repository interface can be tested in a few lines, with no pumpWidget, no mock server, no waiting.

dart
test('placing an order clears the cart', () async {
  final repo = FakeOrderRepository();
  final placeOrder = PlaceOrder(repo);
 
  await placeOrder(cartWithTwoItems);
 
  expect(repo.lastCart!.items, hasLength(2));
});

What I drop

A use case class for every single call. If GetUserProfile only calls repository.getProfile() and returns it, it is a file that exists to be a file. I add a use case when there is real logic: combining sources, validating, deciding. Otherwise the BLoC talks to the repository.

Entity plus model plus DTO for the same thing. Three classes with the same fields and two mappers between them is a lot of typing to protect against a change that may never come. I keep two: the domain entity and the data model that knows about JSON. When the API shape and the domain shape are genuinely the same, sometimes I keep one and accept the coupling on purpose.

Abstracting things with one implementation forever. An interface earns its place when it gives you a seam for testing or a second implementation. AuthRepository earns it. StringFormatterInterface does not.

How I lay a feature out

code
lib/
  features/
    orders/
      domain/     entities, repository interfaces, use cases with real logic
      data/       api client, models, repository implementation
      presentation/  bloc, pages, widgets
  core/
    network/, errors/, di/, theme/

Feature-first, not layer-first. When you work on orders, everything about orders is in one folder. Layer-first sounds tidy and then you spend the day scrolling between four directories to add one field.

The test I use before adding a layer

Before I add an abstraction I ask: what breaks if I skip it?

If the honest answer is "nothing, it just feels less clean", I skip it. Architecture is supposed to make change cheaper. If a layer makes change more expensive and buys nothing back, it is not architecture, it is ceremony.

Where I still get this wrong

State management is where the boundary leaks most often for me. It is easy to let a BLoC know a little too much about how data is fetched, such as a page number, a cache flag or a retry count, and suddenly the presentation layer is holding data layer concerns. I catch it when a UI change forces me to touch the repository. That is the smell.