Learn/Architecture Patterns/Project Structure & Feature-First

Project Structure & Feature-First

Organize your Flutter project with feature-first or layer-first folder structures

7 min~8 min read+40 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Layer-First Structure
  2. 2. Feature-First Structure
  3. 3. What Counts as a Feature
  4. 4. Practical Guidelines
  5. 5. Refactor Trigger Points
  6. 6. This Lesson In Simple Words
  7. 7. Your level focus
  8. 8. One practical habit
  9. 9. Deep Understanding Guide
  10. 10. Why this lesson matters
  11. 11. Study flow for better retention
  12. 12. Quick Glossary
  13. 13. Architecture Lens

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

Project Structure & Feature-First Architecture

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.

Layer-First Structure

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.

dart
1// Layer-First Structure
2// lib/
3// presentation/
4// auth/
5// login_page.dart
6// signup_page.dart
7// products/
8// product_list_page.dart
9// product_detail_page.dart
10// domain/
11// auth/
12// user.dart
13// auth_repository.dart
14// products/
15// product.dart
16// product_repository.dart
17// data/
18// auth/
19// auth_repository_impl.dart
20// auth_remote_datasource.dart
21// products/
22// product_repository_impl.dart
23// product_remote_datasource.dart
24
25// Problem: To work on "products" feature, you jump between
26// 3 different top-level folders. Deleting a feature requires
27// finding and removing files from multiple places.

Feature-First Structure

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.

dart
1// Feature-First Structure (recommended for medium/large apps)
2// lib/
3// src/
4// features/
5// authentication/
6// presentation/
7// login_page.dart
8// signup_page.dart
9// auth_controller.dart
10// domain/
11// user.dart
12// auth_repository.dart (abstract)
13// data/
14// auth_repository_impl.dart
15// auth_remote_datasource.dart
16// products/
17// presentation/
18// product_list_page.dart
19// product_detail_page.dart
20// product_controller.dart
21// domain/
22// product.dart
23// product_repository.dart (abstract)
24// data/
25// product_repository_impl.dart
26// product_api_service.dart
27// cart/
28// presentation/
29// domain/
30// data/
31// orders/
32// presentation/
33// domain/
34// data/
35// common_widgets/
36// loading_indicator.dart
37// error_widget.dart
38// constants/
39// api_constants.dart
40// app_colors.dart
41// routing/
42// app_router.dart
43// utils/
44// validators.dart
45// formatters.dart

What Counts as a Feature

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.

dart
1// WRONG: Features defined by screens
2// 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/repos
10// but are in separate folders
11
12// CORRECT: Features defined by domain functionality
13// 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)
20
21// Barrel file for clean imports
22// features/authentication/authentication.dart
23export 'presentation/login_page.dart';
24export 'presentation/signup_page.dart';
25export 'domain/user.dart';
26export 'domain/auth_repository.dart';

Practical Guidelines

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.

Mirror Tests to Lib

💡 Mirror Tests to Lib

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.

Do Not Over-Engineer Folder Structure

⚠️ Do Not Over-Engineer Folder Structure

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.

Refactor Trigger Points

Even a good structure needs periodic reshaping as features evolve. Refactor when:

  • One feature folder starts containing unrelated workflows.
  • Shared utilities are copied into multiple features.
  • Naming patterns diverge between teams or contributors.
  • Deleting a feature requires edits in too many unrelated folders.

Use these triggers to keep architecture healthy without premature restructuring.

Feature-First Governance Checklist

  • Each feature has clear presentation, domain, and data ownership boundaries.
  • Shared folders contain only genuinely cross-feature code.
  • Barrel files are limited and do not create hidden cyclic imports.
  • Test directory mirrors feature folders for fast navigation.
  • Folder naming conventions are documented and consistently enforced.

This Lesson In Simple Words

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.

Your level focus

Think in architecture, reliability, and team-level maintainability.

One practical habit

After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.

Deep Understanding Guide

Why this lesson matters

Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.

Study flow for better retention

  1. Separate UI, state, and data boundaries before writing implementation details.
  2. Use a simple cycle: understand, implement, test, and explain.
  3. If another developer can read your flow quickly, your design choices are clear.

Common Mistakes To Avoid

  • Moving forward without checking whether the current concept is truly clear.
  • Copying code exactly without experimenting with small changes.
  • Skipping edge cases and only testing happy-path behavior.
  • Assuming one pattern works for every scenario without trade-off analysis.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one tiny example from memory after finishing this lesson.
  • Write one paragraph about where this concept fits in a real app.
  • Create one failure scenario and verify your app handles it safely.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "What is the main advantage of feature-first over layer-first structure?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • const: A compile-time constant that can reduce rebuild work.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Architecture Lens

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.

Lesson Completion Checklist

  • I can explain "Project Structure & Feature-First" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Moving forward without checking whether the current concept is truly clear.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

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.

How should you define a feature in feature-first architecture?

Features should be defined by domain functionality and user tasks, not by individual screens. Multiple related screens belong to the same feature.

Where should shared code used by multiple features go?

Code genuinely shared across multiple features belongs in top-level folders like common_widgets, constants, or utils to avoid duplication.

What is the drawback of layer-first structure in large apps?

In layer-first, working on a single feature requires jumping between presentation, domain, and data folders that are far apart in the project tree.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

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