Skip to content

Data and Domain Architecture

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

Data & Domain Architecture

This document covers the domain layer architecture and data flow patterns in the Effective Office system. It focuses on the business logic implementation, use case patterns, domain models, and how data flows through the application layers.

For detailed information about specific use case implementations, see[Domain Use Cases](Data and Domain Architecture/Domain Use Cases). For repository implementations and data access patterns, see [Data Layer and Repositories](Data and Domain Architecture/Data Layer and Repositories).

Domain Architecture Overview

The Effective Office system follows clean architecture principles with clear separation between domain logic, data access, and presentation layers. The domain layer contains business rules and use cases that are independent of external frameworks and data sources.

Core Domain Structure

core-domain-structure.svg

Use Case Pattern Implementation

The system implements the use case pattern to encapsulate business logic and maintain clean separation of concerns. Each use case represents a single business operation and follows consistent patterns for error handling and data flow.

Use Case Categories

Category Use Cases Purpose
Booking Operations CreateBookingUseCase, UpdateBookingUseCase, DeleteBookingUseCase Manage room bookings with network/local synchronization
Room Management RoomInfoUseCase, SelectRoomUseCase, GetRoomByNameUseCase Handle room information and selection logic
Data Synchronization RefreshDataUseCase, UpdateUseCase, GetEventsFlowUseCase Coordinate data updates and real-time synchronization
Validation CheckBookingUseCase, CheckSettingsUseCase Validate business rules and constraints

Booking Use Case Pattern

booking-use-case-pattern.svg

Domain Models & Data Flow

The domain layer defines core business entities that represent the system's data model. These models are used consistently across use cases and provide type safety for business operations.

Core Domain Models

The main domain models include:

  • RoomInfo: Represents room state including current and upcoming events
  • EventInfo: Represents booking/event details with loading states
  • ErrorResponse: Standardized error information with HTTP status codes
  • Either<ErrorResponse, T>: Functional error handling pattern

Room Selection Logic

room-selection-logic.svg

Timer-Based Update Logic

The UpdateUseCase implements intelligent timing for room status updates based on event schedules:

time-based-update-logic.svg

Error Handling & Repository Pattern

The domain layer implements consistent error handling using the Either pattern and maintains data consistency through dual repository operations.

Either Pattern Implementation

All booking operations return Either<ErrorResponse, T> to provide type-safe error handling:

// Example from DeleteBookingUseCase
suspend operator fun invoke(
    roomName: String,
    eventInfo: EventInfo,
): Either<ErrorResponse, String>

Dual Repository Pattern

Booking operations follow a consistent pattern of optimistic local updates with network synchronization:

  1. Immediate Local Update: Update local repository with loading state
  2. Network Operation: Attempt network operation
  3. Result Handling:
    • Success: Confirm local changes
    • Error: Rollback to original state

Dependency Injection Structure

The domain layer uses Koin for dependency injection with a centralized module configuration that defines all use case dependencies and their relationships.

Domain Module Configuration

dependency-injection-structure.svg

The dependency injection follows these patterns:

  • Constructor Injection: All use cases receive dependencies through constructors
  • Single Instance: All use cases are registered as singletons
  • Layered Dependencies: Use cases depend only on repositories and other use cases, never on presentation layer components
Clone this wiki locally