Skip to content

Domain Use Cases

Radch-enko edited this page Jul 24, 2025 · 2 revisions

Domain Use Cases

This document covers the business logic implementation and use case patterns in the Effective Office tablet client. Domain use cases represent the core business operations that the application can perform, implementing clean architecture principles by separating business logic from UI and data concerns.

For information about the data layer and repository patterns that support these use cases, see Data Layer & Repositories. For details about the overall system architecture, see System Architecture.

Purpose and Scope

The domain layer contains use cases that encapsulate specific business operations such as booking management, room selection, and data synchronization. Each use case follows a single responsibility principle and coordinates between repositories to achieve business goals. The use cases are organized into distinct categories based on their functional area and are managed through dependency injection.

Use Case Architecture Overview

The domain use cases are structured in a layered architecture where use cases coordinate between repositories and implement business rules.

usecase-architecture-overview.svg

Booking Management Use Cases

The booking use cases handle the core business operations for managing room reservations. These use cases follow a consistent pattern of optimistic updates with rollback capabilities.

DeleteBookingUseCase Implementation

The DeleteBookingUseCase demonstrates the typical pattern used across booking operations:

deletebookingusecase-implementation.svg

The use case implements optimistic updates by immediately marking the event as loading in the local repository, attempting the network operation, and either completing the deletion or rolling back to the original state on failure.

Room Selection and Management

SelectRoomUseCase Logic

The SelectRoomUseCase implements intelligent room selection based on availability and capacity matching:

select-room-usecase-logic.svg

The selection algorithm prioritizes rooms that are immediately available and have similar capacity to the current room, with fallback logic for finding the nearest available time slot.

Real-time Update Management

UpdateUseCase Timer Logic

The UpdateUseCase manages automatic data refresh timing based on upcoming events:

update-usecase.svg

The use case calculates optimal update intervals by finding the minimum time until the next significant event change (either an event starting or ending), ensuring the UI stays synchronized with real-time booking changes.

Dependency Injection Structure

The domain use cases are organized through a comprehensive dependency injection module that manages their creation and dependencies:

Use Case Category Use Cases Key Dependencies
Booking Operations CreateBookingUseCase, UpdateBookingUseCase, DeleteBookingUseCase NetworkBookingRepository, LocalBookingRepository, GetRoomByNameUseCase
Room Information RoomInfoUseCase, GetRoomsInfoUseCase, GetCurrentRoomInfosUseCase LocalRoomRepository, RefreshDataUseCase
Data Flow GetEventsFlowUseCase, RefreshDataUseCase NetworkRoomRepository, LocalRoomRepository
Utility TimerUseCase, UpdateUseCase, SelectRoomUseCase Various domain dependencies

Central RoomInfoUseCase

The RoomInfoUseCase serves as a central coordinator that aggregates multiple data sources:

room-info-usecase.svg

This composition pattern allows the RoomInfoUseCase to provide comprehensive room information by coordinating multiple specialized use cases.

Feature-Specific Use Cases

Main Screen Use Cases

The main screen feature includes specialized use cases for UI-specific logic:

  • GetRoomIndexUseCase: Manages room index calculation for display
  • GetTimeToNextEventUseCase: Calculates timing information for UI updates

These feature-specific use cases are registered in their own module and handle presentation-layer business logic.

Error Handling Patterns

The domain use cases implement consistent error handling using the Either type pattern, providing structured error responses with HTTP-style status codes and descriptive messages. Failed operations attempt graceful degradation by rolling back to previous states in local repositories while preserving error information for user feedback.

Clone this wiki locally