MVVM, Riverpod state management and Folder by feature structure
Hey big fan of your videos. Honestly, I have been waiting for this. So let's get to work.
I went through the code base. I'd like to propose organising the directory as following for the new comers to adapt easily:
Ideally inside authentication directory this is what I normally do:
But since this is done in firebase, we don't have that much going on in here. So we can simplify this like the first image
We can also throw a local widget directory in there, if needed.
Great suggestion and thank you for writing out the structure so thoroughly!
@KalleHallden do you want me to convert a feature like this? I think Login, Sign up would be a great point to start. Let me know if you want that.
Also, if we start working on this, then until this gets merged we should not accept any other changes in the authentication area to avoid merge conflict. Given this would be a huge change. LMK, what you think
This is by far the biggest issue with the codebase and should be nailed down before continuing. Especially because you have open sourced this, You want anyone jumping in to understand the codebase and how it is to be structured.
I would recommend just making a new folder and start transferring stuff across, the app is small enough that it wouldn't take to long and it avoids all the merge conflicts. Once the new folder is in the desired state you can just point the 'main.dart' at the new folder
Another suggestion I have but can wait until after this change is complete is to move the app to the root of the repo.
@KalleHallden Expecting your feedback. If you agree I'll get started
Yeah definitely man! Go for it, seems like you have a better idea of creating proper structure than me so that would be awesome!
I believe this would be fine to work on in the master branch
@KalleHallden I have been wondering if we should stick with Bloc or change to something else? For example Riverpod may be? Let me know what you think. If you have any preferences or not.
@dinurymomshad As i can see, we aren't using the real bloc atm. I think it's more like an repository approach since the networking calls are directly inside the 'bloc'. I would prefere to use Riverpod, since we can also provide own states with the StateNotifierProvider or simply can use AsyncData or something like that.
Architecture change suggestion
Also i would make a change in the architecture. I can't see any folder for logic, therefore i would suggest to create a 'domain' and inside a 'logic' folder where all the logic can stay. It forces the developer to seperate logic from ui. Further more i would like to split the models into entity and model.
- The entity is inside the domain folder. It is a class without any
fromJsonor toJsonstuff. - The model is inside data folder. It extends the entity and has all needed parsing methods like
fromJsonand toJson.
Example:

@Scount ~https://github.com/KalleHallden/exer_log/issues/10#issuecomment-1206686825 What do think about this?~
Never mind. I vote for riverpod as well. Since, we haven't implemented bloc. Riverpod would be much simpler and less boilerplate heavy.
Regarding the change in architecture: I was thinking more like, view will only hold the UI. UI will watch a StateNotifier (aka Controller), Controller will hold all the business logic. Controller will also have access to repository to do the api calls.
Here, what logic do you want separated in a logic folder?
Yes you are right with the view --> controller including controller specific logic --> repository. What i mean with logic is global logic, functions like sort and filter which are used multiple times from different controllers. I didn't dive in the code that deep to search for things like that but i think, if something like this exists it has to be defined globally so any controller hat access to the same logic.
I think I will get started with very basic implementation. And then we can proceed from there. I am using Riverpod
Work In Progress: https://github.com/dinurymomshad/exer_log/tree/feature/authentication-refactor
@KalleHallden can you assign this issue to me please? And also update in project board if you have any?
@dinurymomshad I suggest you to change the project folder to root too. (Currently its in app/exerlog/) Since this is already a massive update might as well add that too.
And, @KalleHallden, lets merge #55 pull request first than anything, then we can update other features and contribute base on this architecture.
@dinurymomshad I suggest you to change the project folder to root too. (Currently its in app/exerlog/) Since this is already a massive update might as well add that too.
You are right. Gonna do that.
@suzanpradhan done. Please give it a review if you will. I have built the project and ran the app.