Skip to content

Android Architecture

Garot Conklin edited this page Dec 15, 2024 · 1 revision

Android Architecture

Overview

RunOn! follows Clean Architecture principles with MVVM (Model-View-ViewModel) pattern for the presentation layer. This ensures separation of concerns, testability, and maintainability.

Architecture Layers

1. Presentation Layer (UI)

Components

  • Activities/Composables: UI containers and navigation hosts
  • Compose UI: Declarative UI components
  • ViewModels: UI state management and business logic
  • UI State: Immutable state objects
  • UI Events: User interactions and UI events

Key Patterns

  • Unidirectional Data Flow: State flows down, events flow up
  • State Hoisting: State management pattern for Compose
  • Screen-based Architecture: Each major feature is a separate screen module

2. Domain Layer

Components

  • Use Cases: Business logic operations
  • Domain Models: Core business objects
  • Repository Interfaces: Data access contracts
  • Domain Events: Business event definitions

Key Patterns

  • Clean Architecture: Separation of domain logic
  • Single Responsibility: Each use case handles one operation
  • Dependency Inversion: Domain layer defines interfaces

3. Data Layer

Components

  • Repositories: Data access implementation
  • Data Sources: Remote and local data providers
  • DTOs: Data transfer objects
  • Mappers: Object transformations

Key Patterns

  • Repository Pattern: Single source of truth
  • Offline First: Local cache as primary data source
  • Data Mapping: Clear separation between data and domain models

Module Structure

app/
├── core/
│   ├── common/           # Shared utilities and extensions
│   ├── design/           # Design system and UI components
│   ├── navigation/       # Navigation components
│   └── testing/          # Test utilities and fakes
├── data/
│   ├── remote/           # API and remote data sources
│   ├── local/            # Room database and local storage
│   └── repository/       # Repository implementations
├── domain/
│   ├── model/           # Domain models
│   ├── repository/      # Repository interfaces
│   └── usecase/         # Business logic use cases
└── features/
    ├── events/          # Event discovery feature
    ├── calendar/        # Calendar integration
    ├── social/          # Social features
    └── profile/         # User profile management

Key Architectural Decisions

1. Dependency Injection

  • Hilt for dependency injection
  • Module-level component provision
  • Scoped dependencies for efficient resource usage

2. Navigation

  • Navigation Compose for screen navigation
  • Deep linking support
  • Type-safe navigation arguments

3. State Management

data class EventsUiState(
    val events: List<Event> = emptyList(),
    val isLoading: Boolean = false,
    val error: String? = null
)

sealed interface EventsUiEvent {
    data class OnEventSelected(val eventId: String) : EventsUiEvent
    object OnRefreshRequested : EventsUiEvent
    // ... other events
}

4. Error Handling

  • Centralized error handling
  • Error mapping to UI states
  • Consistent error presentation

5. Testing Strategy

  • Unit Tests: Domain and ViewModel logic
  • Integration Tests: Repository and data layer
  • UI Tests: Critical user flows
  • Screenshot Tests: UI components

Data Flow

  1. UI Layer:

    • Composables observe ViewModel state
    • User actions trigger UI events
    • ViewModels process events
  2. Domain Layer:

    • Use cases execute business logic
    • Repository interfaces define data contracts
    • Domain models represent business objects
  3. Data Layer:

    • Repositories coordinate data sources
    • Data sources handle raw data
    • Mappers transform between layers

Security Considerations

  • Data Encryption: Sensitive data encryption at rest
  • Network Security: SSL pinning and secure communication
  • Authentication: AWS Cognito integration
  • Authorization: Role-based access control

Performance Optimization

  • Lazy Loading: On-demand resource loading
  • Caching: Multi-level caching strategy
  • Background Processing: WorkManager for background tasks
  • Memory Management: Lifecycle-aware components

Monitoring and Analytics

  • Crash Reporting: Crashlytics integration
  • Performance Monitoring: Firebase Performance
  • Analytics: User behavior tracking
  • Logging: Structured logging strategy

Future Considerations

  • Modularization: Further module separation
  • Dynamic Features: On-demand feature delivery
  • Compose Multiplatform: Potential iOS support
  • Backend-Driven UI: Server-driven UI components

RunOn Documentation

MVP Documentation

Core Documentation

Archived (Full-Featured)

Full-Featured Documentation

Clone this wiki locally