DEV Community šŸ‘©ā€šŸ’»šŸ‘Øā€šŸ’»

DEV Community šŸ‘©ā€šŸ’»šŸ‘Øā€šŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to Organize Android Package / Folder Structure?
Vincent Tsen
Vincent Tsen

Posted on • Updated on • Originally published at vtsen.hashnode.dev

How to Organize Android Package / Folder Structure?

Of course, this is very personal. There is no right or wrong how you would like to organize your Android source code.

I prefer to organize my source code based on recommended Android app architecture, which is also known as MVVM architecture.

recommended_folder_structure_01.PNG

Image source: MindOrks

This is how my package / folder structure looks like at java root folder.

Package / Folder Name Description
ui UI controller such as activity and fragment
viewmodel Data for the UI
repository Modules that handle data operation
local Room database - SQlite
remote Remote data source - Retrofit

This works for a small app, which is exactly what Iā€™m doing now. However, I imagine if your app is huge and contributed by many developers, you may want to break down by different modules / features instead.

Module1
ā””ā”€ā”€ā”€ ui
ā””ā”€ā”€ā”€ viewmodel
ā””ā”€ā”€ā”€ repository
ā””ā”€ā”€ā”€ local
ā””ā”€ā”€ā”€ remote
    ...
Module2
ā””ā”€ā”€ā”€ ui
ā””ā”€ā”€ā”€ viewmodel
ā””ā”€ā”€ā”€ repository
ā””ā”€ā”€ā”€ local
ā””ā”€ā”€ā”€ remote
    ...
...
Enter fullscreen mode Exit fullscreen mode

This allows your modules to be exported or shared as generic libraries easily in the future. Since my app is small, I'm good with what I'm doing now.

[Updated - July 02, 2022]: Given that I'm now have a bit of experience. This is my current package naming convention based on the latest app architecture guide.

root package
ā””ā”€ā”€ā”€ data
     ā””ā”€ā”€ā”€ local
     ā””ā”€ā”€ā”€ mapper
     ā””ā”€ā”€ā”€ remote
     ā””ā”€ā”€ā”€ repository
ā””ā”€ā”€ā”€ domain
     ā””ā”€ā”€ā”€ model
     ā””ā”€ā”€ā”€ repository
ā””ā”€ā”€ā”€ ui
     ā””ā”€ā”€ā”€ screens
     ā””ā”€ā”€ā”€ theme
     ā””ā”€ā”€ā”€ viewmodel
ā””ā”€ā”€ā”€ utils
Enter fullscreen mode Exit fullscreen mode
  • mapper contains extension functions to covert data to and from different layer.

For app reference, you can refer here.


Originally published at https://vtsen.hashnode.dev.

Top comments (0)

šŸŒš Life is too short to browse without dark mode