Restrict ViewModel visibility to `internal` within feature modules

Open
#1,921 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
kotlin
Domain
mobile-dev

Research direction

Search the project for @HiltViewModel classes and public ViewModel declarations, starting with the BookmarksViewModel example. Inspect each ViewModel's references across feature modules before changing visibility; done means only ViewModels unused outside their own module are internal and the project still compiles.

Written by the indexing model from the issue text.

Description

Summary

All ViewModel classes across the project are currently declared as public, even though they are only used within their respective feature modules. This can lead to unintended usages across modules and violates encapsulation principles.

Proposal

Change the visibility modifier of each ViewModel from public to internal if it is not used outside the module it belongs to.

This adjustment:

  • Prevents accidental access from other modules
  • Reinforces module boundaries
  • Keeps internal logic private to its domain
  • Makes the codebase more maintainable and intention-revealing
Example
// Current (public by default)
@HiltViewModel
class BookmarksViewModel @Inject constructor(...) : ViewModel() {
    ...
}

// Suggested
@HiltViewModel
internal class BookmarksViewModel @Inject constructor(...) : ViewModel() {
    ...
}
Dominant language
Kotlin
Stars
22.1k
Forks
4.7k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/nowinandroid

All issues in android/nowinandroid

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.