android · 9 min read

Practical Clean Architecture for Android

Clean Architecture makes dependency direction explicit. The domain contains contracts and business rules; data implements those contracts; presentation renders state and triggers operations. A single Gradle module can enforce these conventions before a larger team needs separate modules.

How the pieces connect

Presentation → DomainData → DomainDI wires both

A starting folder structure

app/src/main/java/com/example/app/
  domain/
    model/
    repository/
    usecase/
  data/
    remote/
    local/
    repository/
  presentation/
  di/

Design repository contracts around business needs

Prefer observeSavedArticles over exposing a Room DAO directly. The contract should describe the operation and its domain values. Let the implementation choose between cache and network. Keep Retrofit response types and database entities inside data unless there is a deliberate reason to share them.

Put transaction rules in the right layer

A use case may coordinate validation and several repositories, but a database transaction belongs with the implementation that owns the database. Document consistency expectations in the contract. Offline synchronization needs explicit conflict handling; a folder layout cannot supply it.

Keep the composition root concrete

Hilt modules or a manual AppContainer create concrete implementations and bind interfaces. Presentation receives the domain contract. The starter uses a manual ViewModel factory with repository injection so clean boundaries remain visible even when a DI framework is selected.

Split modules when the team needs enforcement

Package boundaries are conventions within one module. Separate domain, data, and presentation modules when build isolation, ownership, or enforcement justifies the cost. Start small, test important rules, and resist copying the same model into every layer without a meaningful transformation.

Try this configuration

Clean Architecture · Hilt · Retrofit · Room · Compose

The generator includes a working counter example with a repository contract, selected dependencies, navigation, and local setup instructions. Extend the example around your own domain before shipping.

Configure your Android project →

Continue reading

Primary references

See Android architecture recommendations and ViewModel documentation for platform guidance and lifecycle behavior.