What is the main advantage of feature-first over layer-first structure?
Feature-first groups all presentation, domain, and data files for a feature in one folder, making it easy to find, modify, or delete an entire feature.
Organize your Flutter project with feature-first or layer-first folder structures
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
How you organize files and folders in your Flutter project has a direct impact on how fast your team can add new features, how easy it is to find code, and how cleanly you can delete or refactor features later. There are two main approaches: layer-first and feature-first. In layer-first, you group files by their architectural layer first (presentation, domain, data), then by feature inside each layer. In feature-first, you group files by feature first (authentication, cart, orders), then by layer inside each feature. For small apps either approach works fine, but as your project grows beyond five or six features, feature-first becomes significantly easier to maintain because all related files live together.
In the layer-first approach, your top-level folders represent architectural layers. Each layer contains sub-folders for every feature. This is simple to set up and understand, but it scatters files for a single feature across the entire project tree. When you want to add or remove a feature, you must touch multiple distant folders.
1// Layer-First Structure2// lib/3// presentation/4// auth/5// login_page.dart6// signup_page.dart7// products/8// product_list_page.dart9// product_detail_page.dart10// domain/11// auth/12// user.dart13// auth_repository.dart14// products/15// product.dart16// product_repository.dart17// data/18// auth/19// auth_repository_impl.dart20// auth_remote_datasource.dart21// products/22// product_repository_impl.dart23// product_remote_datasource.dart2425// Problem: To work on "products" feature, you jump between26// 3 different top-level folders. Deleting a feature requires27// finding and removing files from multiple places.
In the feature-first approach, your top-level folders represent features or functional areas of your app. Each feature contains its own presentation, domain, and data sub-folders. All code related to a single feature lives together, making it easy to find, modify, or delete an entire feature. Shared code that is used across multiple features goes into folders like common_widgets, constants, or routing at the top level.
1// Feature-First Structure (recommended for medium/large apps)2// lib/3// src/4// features/5// authentication/6// presentation/7// login_page.dart8// signup_page.dart9// auth_controller.dart10// domain/11// user.dart12// auth_repository.dart (abstract)13// data/14// auth_repository_impl.dart15// auth_remote_datasource.dart16// products/17// presentation/18// product_list_page.dart19// product_detail_page.dart20// product_controller.dart21// domain/22// product.dart23// product_repository.dart (abstract)24// data/25// product_repository_impl.dart26// product_api_service.dart27// cart/28// presentation/29// domain/30// data/31// orders/32// presentation/33// domain/34// data/35// common_widgets/36// loading_indicator.dart37// error_widget.dart38// constants/39// api_constants.dart40// app_colors.dart41// routing/42// app_router.dart43// utils/44// validators.dart45// formatters.dart
A common mistake is defining features based on screens or pages. Instead, define features based on what the user does, not what they see. A feature is a functional requirement that helps the user complete a task. For example, authentication is a feature that includes login, signup, password reset, and profile pages. Products is a feature that includes the product list, product detail, and product search. Think in terms of domain models: each feature should center around one or two closely related domain entities.
1// WRONG: Features defined by screens2// features/3// login_screen/4// signup_screen/5// product_list_screen/6// product_detail_screen/7// cart_screen/8// checkout_screen/9// Problem: product_list and product_detail share models/repos10// but are in separate folders1112// CORRECT: Features defined by domain functionality13// features/14// authentication/ (login + signup + password reset)15// products/ (list + detail + search)16// cart/ (add/remove items, view cart)17// checkout/ (payment, address, confirmation)18// orders/ (order history, order detail)19// reviews/ (write review, view reviews)2021// Barrel file for clean imports22// features/authentication/authentication.dart23export 'presentation/login_page.dart';24export 'presentation/signup_page.dart';25export 'domain/user.dart';26export 'domain/auth_repository.dart';
Start every new project with the feature-first structure from day one. It is much harder to restructure a layer-first project into feature-first later. Keep your test folder structure matching your lib folder structure so tests are easy to find. Use barrel files (index exports) to keep imports clean. Do not create folders named shared or utils until you truly have code used across three or more features. Keep the common_widgets folder for genuinely reusable UI components only.
Keep your test folder structure identical to your lib folder structure. For every file at lib/src/features/auth/domain/user.dart, create a test at test/src/features/auth/domain/user_test.dart. This makes finding and maintaining tests straightforward.
If your app has only two or three features, do not create deeply nested sub-folders for every possible layer. Add layers and sub-folders as your feature grows. Starting with too many empty folders adds complexity without benefit.
Even a good structure needs periodic reshaping as features evolve. Refactor when:
Use these triggers to keep architecture healthy without premature restructuring.
Organize your Flutter project with feature first or layer first folder structures. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Think in architecture, reliability, and team-level maintainability.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Connect this lesson to separation of concerns so your codebase stays maintainable as it grows.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
Feature-first groups all presentation, domain, and data files for a feature in one folder, making it easy to find, modify, or delete an entire feature.
Features should be defined by domain functionality and user tasks, not by individual screens. Multiple related screens belong to the same feature.
Code genuinely shared across multiple features belongs in top-level folders like common_widgets, constants, or utils to avoid duplication.
In layer-first, working on a single feature requires jumping between presentation, domain, and data folders that are far apart in the project tree.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue