Best folder structure for flutter app with riverpod

If you’re building a big and complex app, it’s important to consider the folder structure. Without it, your unorganized code can hinder your progress over time.

Each state management library in Flutter has many folder structure patterns, including Riverpod. However, the pattern We are sharing with you is easy to understand, test, debug, and scale. It also allows for easy code clean-up and refactoring, as well as simple migration from any other structure. Let’s take a closer look and see how simple it actually is.

First, divide the app into features. Say your app has four features; your structure will look like this:

App level structure

The app-level structure includes three layers:

  1. Presentation Layer
  2. Logic Layer
  3. Data Layer

But for better organization, modify the structure for each feature:

Feature level sturcture
  1. Presentations :- This folder contains the widget code that’s rendered on the screen.
  2. States :- This folder contains all the states that widget apdat to render something different.
  3. Notifiers :- This folder contains the business logic to manage the widget state.
  4. Services :- This folder contains the business logic to manage the application state.
  5. Models :- This folder contains the data model to share data coming from the repository to notifiers or services.
  6. Repositories :- This folder contains the handling for data coming in and out from your database or server.
  7. Data Providers :- This folder contains all your data sources, such as fake data, server calls, or database calls.

That’s it! You can add as many features as you want and remove them easily if they’re not required. Test each layer individually, debug only the folder with the problem, and solve it quickly like this:

You can also explore example here. We hope to see you in our coming articles.