Feature-Based Folder Structure in Flutter: Dependency Direction in a Growing App

In the first few weeks, a Flutter project can be managed with almost any folder layout. The trouble starts when the app reaches forty screens: the screens, models, services, and widgets folders bloat, and changing a single feature means hopping between five different directories. For growing apps, the approach that works for us is grouping by feature instead of by layer.

The limits of a layer-based structure

In a layer-based layout, the code for a "cart" feature is scattered across four folders. Deleting the feature, moving it, or reusing it in another app becomes hard. And because everything can import everything, dependencies multiply unchecked; chains that reach from one screen's model file to another feature's service form without anyone noticing.

The basic feature-based layout

Each feature lives in its own folder and carries its own layers inside it. A typical structure looks like this:

  • lib/features/cart/data: the API client, DTOs, and the repository implementation.
  • lib/features/cart/domain: pure Dart models and repository interfaces.
  • lib/features/cart/presentation: pages, widgets, and state management (bloc, riverpod, or whatever solution you prefer).
  • lib/core: shared code that knows nothing about features, such as the theme, HTTP infrastructure, error classes, and routing.
  • lib/shared: widgets used by more than one feature that contain no business rules.
In a layer-based folder layout, a feature is scattered across many folders; in a feature-based layout, the feature is self-contained in its own folder.
In a growing app, a feature-based layout narrows a change down to a single folder.

The real issue: dependency direction

More important than folder names is who can import whom. Our rule is this: presentation depends on domain; data depends on domain; and domain depends on nothing. If you see a package:flutter or package:dio import in the domain layer, the direction is broken.

The presentation and data layers depend on domain; the domain layer depends on nothing.
If you see package:flutter or package:dio in the domain's imports, the direction is broken.

Dependencies between features call for similar discipline. A feature shouldn't reach directly into another feature's data folder; it should get what it needs through that feature's domain interface. If the cart screen needs user information, it uses the auth feature's repository interface rather than writing the HTTP call itself.

Enforcing these rules automatically

If the rules only live in a document, they'll be broken three sprints later. A cheap way to enforce them in Dart is a small script inside a test that scans the files under lib/features/*/domain and looks for forbidden imports. Tools like dart_code_metrics, or lint packages that restrict imports, do the same job. What matters is that violations are caught in CI, not left to someone's attention during code review.

Routing and dependency injection

So that features can navigate without knowing about each other directly, we keep route definitions in a central place, referenced only by path names. In projects using go_router, each feature exposes its own list of GoRoute entries, and core/router combines them. The same logic applies to dependency injection: each feature provides its own registration function, and they're all called in sequence at app startup. That way, removing a feature is as simple as deleting one registration line.

For an internal app with a handful of screens, a domain layer and interface abstractions can be overkill. In that case, it's enough to keep the feature folders and split each one into data and presentation. Pick the structure to fit the size of the app, then add the domain layer when you need it; a folder layout can be moved around, but a tangle of dependencies can't.

Trying to restructure an existing app in one go usually ends up half-finished. We create every newly written feature in the new structure and move old code only as far as we touch it. The feature with the fewest dependencies, such as settings or profile, moves first; as shared code is split out under core and shared, subsequent moves get easier. If each move is a small pull request, rolling back is easy too.

If your existing Flutter app slows down as it grows, or adding a new feature breaks something every time, write to us through our contact page. Let's look at your codebase and plan together which structure to clean up, and in what order.