Introduction
TecMeli is built following Clean Architecture principles combined with the MVVM (Model-View-ViewModel) pattern. This architecture ensures separation of concerns, testability, and maintainability across the codebase.Architecture Diagram
Layer Overview
TecMeli follows a three-layer architecture:UI Layer
Jetpack Compose screens, ViewModels, and UI state management
Domain Layer
Business logic, use cases, and domain models
Data Layer
Data sources, repositories, and DTOs
UI Layer
Location:ui/ package
Responsibilities:
- Render UI using Jetpack Compose
- Observe ViewModel state changes
- Handle user interactions
- Display loading, success, and error states
- Screens: Composable functions that define the UI (
HomeScreen,ProductDetailScreen) - ViewModels: Manage UI state and business logic orchestration
- UI State: Sealed class representing different states (
UiState.kt:11)
Domain Layer
Location:domain/ package
Responsibilities:
- Define business logic through use cases
- Declare repository contracts (interfaces)
- Define domain models (pure Kotlin data classes)
- Remain independent of frameworks and external libraries
- Use Cases: Encapsulate single business operations (
GetProductsUseCase,GetProductDetailUseCase) - Repository Interfaces: Define data access contracts (
ProductRepository,TokenRepository) - Domain Models: Business entities (
Product,ProductDetail,ProductAttribute)
Data Layer
Location:data/ package
Responsibilities:
- Implement repository interfaces
- Fetch data from remote APIs
- Map DTOs to domain models
- Handle network errors and responses
- Repository Implementations: Concrete repository classes (
ProductRepositoryImpl,TokenRepositoryImpl) - Remote APIs: Retrofit interfaces (
MeliApi,AuthApi) - DTOs: Data Transfer Objects for network responses (
ResultsDto,SearchResponseDto) - Mappers: Extension functions to convert DTOs to domain models (
ProductMapper.kt)
Package Structure
Data Flow
Key Benefits
Separation of Concerns
Separation of Concerns
Each layer has a single, well-defined responsibility. UI handles presentation, domain contains business logic, and data manages data access.
Testability
Testability
Each layer can be tested independently. Use cases can be tested without UI or network, repositories can be mocked in use case tests.
Maintainability
Maintainability
Changes in one layer don’t affect others. For example, switching from Retrofit to Ktor only affects the data layer.
Independence
Independence
Domain layer is framework-agnostic. Business logic doesn’t depend on Android, Compose, or Retrofit.
Scalability
Scalability
New features follow the same pattern, making the codebase predictable and easy to extend.
Technology Stack
- UI Framework: Jetpack Compose with Material 3
- Architecture Pattern: MVVM + Clean Architecture
- Dependency Injection: Hilt (Dagger)
- Networking: Retrofit + OkHttp
- Serialization: Gson
- Async: Kotlin Coroutines + Flow
- Navigation: Jetpack Navigation Compose
Next Steps
Dive deeper into each architectural component: