Explore GemAI’s base classes, use cases, ViewModels, and AI model abstractions that form the foundation of the application
GemAI is built on a set of reusable base components that enforce architectural patterns and reduce boilerplate code. Understanding these components is essential for extending the application.
Defines the contract for all business logic operations:
BaseUseCase.kt
interface BaseUseCase<in Params, out Result> { // Execute without parameters suspend fun perform(): Result = throw NotImplementedError("BaseUseCase perform() not implemented") // Execute with parameters suspend fun perform(params: Params): Result? = throw NotImplementedError("BaseUseCase perform(params) not implemented") // Execute as a stream fun performStreaming(params: Params): Flow<Result> = throw NotImplementedError("BaseUseCase performStreaming() not implemented") fun performStreaming(): Flow<Result> = throw NotImplementedError("BaseUseCase performStreaming() not implemented")}
Use cases encapsulate single business operations. Override only the methods you need: perform(), perform(params), or performStreaming().
Show Real use case examples from GemAI
class SendMessageUseCase @Inject constructor( private val chatRepository: ChatRepository, @Dispatcher(GemAIDispatchers.IO) private val dispatcher: CoroutineDispatcher,) : BaseUseCase<Message, Result<Unit, RequestError>> { override suspend fun perform(params: Message): Result<Unit, RequestError> = withContext(dispatcher) { chatRepository.sendMessage(params) }}
Provides common CRUD operations for all Room DAOs:
BaseDao.kt
@Daointerface BaseDao<T> { @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insert(entity: T): Long @Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insertAll(entities: List<T>): List<Long> @Upsert suspend fun upsert(entity: T): Long @Upsert suspend fun upsertAll(entities: List<T>) @Update suspend fun update(entity: T) @Update suspend fun updateAll(entities: List<T>) @Delete suspend fun delete(entity: T) @Delete suspend fun deleteAll(entities: List<T>)}
All DAOs extend BaseDao<T> to inherit standard operations, then add custom queries specific to their entity.