android / android/nowinandroid

Restrict ViewModel visibility to `internal` within feature modules

Open
#1,921 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
21.8k
Forks
4.6k
Avg merge
19h 20m
Merged PRs (30d)
2

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

```kotlin
// Current (public by default)
@HiltViewModel
class BookmarksViewModel @Inject constructor(...) : ViewModel() {
...
}

// Suggested
@HiltViewModel
internal class BookmarksViewModel @Inject constructor(...) : ViewModel() {
...
}

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.