D
ArchitectureMedium30 XP3 min read

Should you organize your Flutter app feature-first or layer-first?

TL;DR: Feature-first (lib/features/quiz/) scales better — all quiz-related code is co-located. Layer-first (lib/blocs/, lib/repositories/) leads to cross-folder changes for every feature and becomes hard to navigate as apps grow.

Full Answer

AspectFeature-firstLayer-first
Structurefeatures/quiz/bloc, features/quiz/uiblocs/quiz, repositories/quiz
CohesionHigh — related code in one placeLow — feature spread across folders
ScalabilityBetter — add feature folder, donePoorer — changes touch 5 folders
NavigationFeature scope is clearHard to find what belongs to what
Team sizeBetter for teams per featureOK for very small projects
🎯

Robert C. Martin's 'screaming architecture': your folder structure should tell you what the app does, not what framework it uses. features/quiz screams quiz; blocs/ screams BLoC.

Code Examples

dartFeature-first structure
Output
// Feature-first: 'where is quiz code?' -> features/quiz/
// Layer-first: check blocs/, repos/, models/, pages/...

Common Mistakes

  • Mixing both structures — use a consistent approach across the entire codebase
  • Shared/ folder growing too large — if it has more than 10-15 items, refactor into a feature

Interview Tip

💡

This question tests architectural thinking beyond code. Mention that Flutter teams at large companies universally prefer feature-first for maintainability.

#folder-structure#feature-first#layer-first#modularity