# Structuring Real Flutter Apps

> Organise a production Flutter app with Riverpod or Bloc, gorouter, repositories, code generation and key pub.dev packages. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/mobile/flutter-app-structure
Last updated: 2026-11-28

Organise a production Flutter app with Riverpod or Bloc, go_router, repositories, code generation and key pub.dev packages.

Intermediate · about 10 hours · difficulty 3/5

Learn first: [Widget Tree, BuildContext & Lifecycle](https://www.internhack.in/roadmaps/tracks/mobile/flutter-widgets), [App-wide State Tools](https://www.internhack.in/roadmaps/tracks/mobile/state-libraries)

A demo app fits in `main.dart`; a real one needs layers so you can test logic and change data sources without touching UI.

### A common layered structure

- **UI layer**: widgets and screens, reading state from providers or blocs.
- **State layer**: Riverpod `Notifier`/`AsyncNotifier` or Bloc/Cubit classes holding screen state and business rules.
- **Data layer**: repositories that hide where data comes from (HTTP, database, cache).
- Organise folders **by feature** (`features/auth`, `features/feed`) rather than by type once the app grows.

### Useful packages

- **go_router** for declarative routing and deep links.
- **dio** or `http` for networking.
- **freezed** and **json_serializable** for immutable models and JSON parsing via code generation (`dart run build_runner build`).
- **drift** or **sqflite** for SQLite, **shared_preferences** for simple settings.

### Pitfalls

- Business logic inside `build` methods cannot be unit tested.
- Mixing several state management approaches in one app confuses everyone. Pick one per project.

**Good enough to move on:** you have a two-feature app where a repository is injected into a notifier or bloc and replaced by a fake in tests.

## Key concepts

- **Layered architecture**
- **Feature-first folders**
- **Riverpod providers and notifiers**
- **Bloc and Cubit**
- **go_router**
- **freezed and json_serializable**
- **Dependency injection for tests**

## Mini project

Build a news reader with a feed and bookmarks feature, using go_router, a repository layer and Riverpod or Bloc, with one unit test per notifier.

## Check yourself

What does a repository layer let you do that calling HTTP directly from a widget does not?

## Free resources

- [Flutter: Guide to app architecture](https://docs.flutter.dev/app-architecture) (Flutter)
- [Riverpod](https://riverpod.dev/) (Riverpod)
- [Bloc library](https://bloclibrary.dev/) (Bloc)

Previous: [Widget Tree, BuildContext & Lifecycle](https://www.internhack.in/roadmaps/tracks/mobile/flutter-widgets) · Next: [Platform Channels & Native Integration in Flutter](https://www.internhack.in/roadmaps/tracks/mobile/flutter-platform-channels)

## More in Flutter & Dart in Depth

- [Widget Tree, BuildContext & Lifecycle](https://www.internhack.in/roadmaps/tracks/mobile/flutter-widgets)
- [Structuring Real Flutter Apps](https://www.internhack.in/roadmaps/tracks/mobile/flutter-app-structure)
- [Platform Channels & Native Integration in Flutter](https://www.internhack.in/roadmaps/tracks/mobile/flutter-platform-channels)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Mobile App Developer Roadmap](https://www.internhack.in/roadmaps/tracks/mobile)
