Architecture Overview
The GreenhouseAdmin API follows a clean MVVM + Repository Pattern architecture with consistent error handling and dependency injection across all platforms (Android, iOS, Desktop, Web).Core Principles
- Repository Pattern - All data access goes through repository interfaces
- Result<T> Error Handling - Consistent error handling across all operations
- Dependency Injection - Koin-based DI for loose coupling
- Platform Abstraction - Kotlin Multiplatform for cross-platform support
Repository Pattern
All repositories follow a consistent interface-based design pattern:Repository Hierarchy
All Repositories
The API provides 10 repositories for different domains:ClientsRepository
Manage greenhouse clients (tenants)
GreenhousesRepository
Greenhouse CRUD with location and timezone support
SectorsRepository
Manage sectors within greenhouses
DevicesRepository
Device management (sensors, actuators) with catalog support
UsersRepository
User management and role assignment per tenant
AlertsRepository
Alert CRUD, resolution, and severity management
SettingsRepository
Settings configuration with periods and actuator states
Result<T> Error Handling
All repository methods returnResult<T> for consistent error handling:
Using Result<T> in ViewModels
Dependency Injection with Koin
Repositories are registered in the Koin DI container for easy injection:Module Definition
Using Repositories in ViewModels
Using in Composables
Platform Abstraction
Certain components likeTokenStorage use Kotlin’s expect/actual pattern for platform-specific implementations:
- Android:
SharedPreferenceswith encryption - iOS: Keychain
- Web:
localStorageorsessionStorage - Desktop: Encrypted file storage
Next Steps
Authentication
Learn about JWT authentication and session management
Repository Reference
Explore detailed repository interfaces and methods