-
Notifications
You must be signed in to change notification settings - Fork 0
Data Layer and Repository
This document covers the data access layer architecture, repository pattern implementations, and data coordination strategies used throughout the Effective Office system. It focuses on how data flows between network APIs, local storage, and business logic components in both the backend and tablet client applications.
For business logic and use case patterns, see [Domain Use Cases](Data and DOmain Architecture/Domain Use Cases). For specific booking workflows, see Room Booking Workflow.
The data layer follows clean architecture principles with clear separation between data sources, repositories, and domain logic. The system uses the repository pattern to abstract data access and provide consistent interfaces for both network and local data operations.
The tablet client implements repositories that handle both network and local data coordination. The RoomRepositoryImpl
serves as the primary example of this pattern.
The RoomRepositoryImpl
demonstrates key repository characteristics:
Method | Purpose | Data Source | Return Type |
---|---|---|---|
subscribeOnUpdates() |
Real-time data subscription | Network via BookingApi
|
Flow<Either<ErrorWithData, List<RoomInfo>>> |
getRoomsInfo() |
Fetch room availability | Network via WorkspaceApi
|
Either<ErrorWithData, List<RoomInfo>> |
The backend uses repositories for data persistence and external API coordination. The ChannelRepository
manages Google Calendar notification channels.
The getRoomsInfo()
method in RoomRepositoryImpl
implements sophisticated time management for booking data:
The implementation rounds the current time to 15-minute intervals and fetches booking data for a 14-day window.
The repository implements reactive data patterns using Kotlin Flow for real-time updates:
The ResourceDisposerUseCase
manages subscription lifecycle and implements debouncing to prevent excessive refresh operations.
The data layer uses the Either<Error, Success>
type for consistent error handling across all repository methods:
Either State | Purpose | Error Handling |
---|---|---|
Either.Error |
Network failures, validation errors | Wraps error with ErrorWithData<T>
|
Either.Success |
Successful data retrieval | Contains transformed domain objects |
The RoomInfoMapper
handles transformation between network DTOs and domain models, while the backend WorkspaceController
converts domain entities to API DTOs.
The data layer uses Koin for dependency injection, allowing use cases to access repositories through interfaces:
Components inject use cases using by inject()
.
The ResourceDisposerUseCase
demonstrates proper resource cleanup patterns:
Resource | Management Strategy | Implementation |
---|---|---|
Coroutine Scope |
SupervisorJob() with Dispatchers.IO
|
ResourceDisposerUseCase.kt |
Subscription Job | Cancellable job tracking | ResourceDisposerUseCase.kt |
Cleanup | Explicit dispose() method |
ResourceDisposerUseCase.kt |