4 min read
πŸ“– Personal Library - Android App

Project Description

Android application developed in Kotlin that implements Clean Architecture principles to manage a personal library. While simple in functionality, it demonstrates the implementation of modern Android development patterns and practices.

Project Structure

πŸ“ LibraryApp
β”œβ”€β”€ πŸ“„ LibraryApplication.kt
β”œβ”€β”€ πŸ“„ MainActivity.kt
β”œβ”€β”€ πŸ“ data
β”‚   β”œβ”€β”€ πŸ“ local
β”‚   β”‚   β”œβ”€β”€ πŸ“ dao
β”‚   β”‚   β”‚   └── πŸ“„ BookDao.kt
β”‚   β”‚   β”œβ”€β”€ πŸ“ database
β”‚   β”‚   β”‚   └── πŸ“„ AppDatabase.kt
β”‚   β”‚   └── πŸ“ entity
β”‚   β”‚       └── πŸ“„ BookEntity.kt
β”‚   β”œβ”€β”€ πŸ“ mapper
β”‚   β”‚   └── πŸ“„ BookMapper.kt
β”‚   β”œβ”€β”€ πŸ“ remote
β”‚   β”‚   β”œβ”€β”€ πŸ“ api
β”‚   β”‚   └── πŸ“ dto
β”‚   └── πŸ“ repository
β”‚       └── πŸ“„ BookRepositoryImpl.kt
β”œβ”€β”€ πŸ“ di
β”‚   └── πŸ“„ DatabaseModule.kt
β”œβ”€β”€ πŸ“ domain
β”‚   β”œβ”€β”€ πŸ“ model
β”‚   β”‚   β”œβ”€β”€ πŸ“„ Book.kt
β”‚   β”‚   └── πŸ“„ ReadStatus.kt
β”‚   β”œβ”€β”€ πŸ“ repository
β”‚   β”‚   └── πŸ“„ BookRepository.kt
β”‚   └── πŸ“ usecase
β”‚       β”œβ”€β”€ πŸ“„ AddBookUseCase.kt
β”‚       β”œβ”€β”€ πŸ“„ GetAllBooksUseCase.kt
β”‚       β”œβ”€β”€ πŸ“„ GetBookByIdUseCase.kt
β”‚       β”œβ”€β”€ πŸ“„ SearchBooksUseCase.kt
β”‚       └── πŸ“„ UpdateBookStatusUseCase.kt
β”œβ”€β”€ πŸ“ presentation
β”‚   β”œβ”€β”€ πŸ“ common
β”‚   β”‚   β”œβ”€β”€ πŸ“ components
β”‚   β”‚   └── πŸ“ extensions
β”‚   β”œβ”€β”€ πŸ“ model
β”‚   β”‚   β”œβ”€β”€ πŸ“„ BookDetailUiState.kt
β”‚   β”‚   β”œβ”€β”€ πŸ“„ BookListUiState.kt
β”‚   β”‚   └── πŸ“„ BookUI.kt
β”‚   β”œβ”€β”€ πŸ“ navigation
β”‚   β”‚   └── πŸ“„ NavigationGraph.kt
β”‚   └── πŸ“ screens
β”‚       β”œβ”€β”€ πŸ“ bookdetail
β”‚       β”‚   β”œβ”€β”€ πŸ“„ BookDetailScreen.kt
β”‚       β”‚   └── πŸ“„ BookDetailViewModel.kt
β”‚       β”œβ”€β”€ πŸ“ bookform
β”‚       β”‚   β”œβ”€β”€ πŸ“„ BookFormScreen.kt
β”‚       β”‚   └── πŸ“„ BookFormViewModel.kt
β”‚       └── πŸ“ booklist
β”‚           β”œβ”€β”€ πŸ“„ BookListScreen.kt
β”‚           └── πŸ“„ BookListViewModel.kt
β”œβ”€β”€ πŸ“ ui
β”‚   └── πŸ“ theme
β”‚       β”œβ”€β”€ πŸ“„ Color.kt
β”‚       β”œβ”€β”€ πŸ“„ Theme.kt
β”‚       └── πŸ“„ Type.kt
└── πŸ“ util

Architecture and Design Patterns

Clean Architecture

The application is structured in layers following Clean Architecture principles:

  • Presentation Layer: Implements MVVM (Model-View-ViewModel) pattern

    • ViewModels handle presentation logic and UI states
    • Immutable states using UiState for each screen
    • Independent and reusable Composables in Jetpack Compose
  • Domain Layer: Contains business logic

    • Use Cases for each specific operation
    • Domain models independent of data layer
    • Repository interfaces to maintain dependency inversion
  • Data Layer: Handles persistence and data sources

    • Room Database for local storage
    • Repository implementations
    • Mappers to convert between data and domain models

Implemented Technologies and Tools

  • Jetpack Components

    • Room: Local data persistence
    • Navigation: Single-activity navigation
    • ViewModel: UI state and logic management
    • Compose: Modern declarative UI
  • Dependency Injection

    • Hilt for dependency injection
    • Modules organized by functionality
    • Appropriate scopes for each dependency
  • Coroutines and Flow

    • Asynchronous operations with Coroutines
    • Flow for reactive data streams
    • StateFlow for UI states

App Preview


Vista 1 Vista 2

Implemented Best Practices

SOLID Principles

  • Single Responsibility: Each class has a single responsibility
  • Open/Closed: Use of interfaces to allow extensions
  • Dependency Inversion: Dependencies toward abstractions
  • Interface Segregation: Specific interfaces for each need

Design Patterns

  • Repository Pattern: Abstraction of data sources
  • Mapper Pattern: Conversion between data models
  • Factory Pattern: Dependency creation in Hilt modules

Testing

  • Architecture prepared for testing
  • Separation of concerns that facilitates unit testing
  • Independent and testable Use Cases

Data Flow

UI -> ViewModel -> UseCase -> Repository -> DataSource
  1. UI observes ViewModel states
  2. ViewModel executes Use Cases
  3. Use Cases coordinate with Repository
  4. Repository handles data using DataSources
  5. Changes flow back as immutable states

Application Features

  • Book listing
  • Book details
  • Add/Edit books
  • Book search
  • Reading status
  • Local persistence

Despite being a simple application in functionality, it demonstrates a robust implementation of modern Android architecture, following development best practices and maintaining clean, testable, and scalable code.