The domain layer represents the core business logic of your application — the part that defines how your system behaves according to the rules and requirements specific to your product or business. Unlike other layers (like data or UI), the domain layer is platform-agnostic and independent of frameworks or infrastructure.
Think of it as the "what" your app does, not "how" it’s displayed or where the data comes from.
What Belongs in the Domain Layer?
You should place code here if it:
- Encapsulates business rules or decisions.
- Coordinates multiple operations across repositories or data sources.
- Should be reused across different layers (e.g., ViewModel, background tasks).
- It is independent of Android/iOS/UI or DB frameworks.
Examples:
- Authentication rules.
- User eligibility checks.
- Subscription billing logic.
- Health metric calculations.
- Decision-making policies (e.g., "Should this reminder be triggered now?").
Best Practices
- Use pure Kotlin: No Android, no UI toolkit, no framework dependencies.
- Favor immutability: Inputs and outputs should be value types where possible.