Files
Kecalek/specs/agent-i-hilt-di.md
filip fe861cfafa Initial commit: Kecalek Android client
Complete Android client for encrypted chat platform.
78+ Kotlin files: crypto (X3DH, Double Ratchet, AES-GCM, Ed25519, X25519,
RSA-PSS), network (TCP/TLS, 50 endpoints), Hilt DI, Room+SQLCipher DB,
Jetpack Compose UI with Catppuccin Mocha theme.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 01:19:17 +01:00

143 lines
3.7 KiB
Markdown

# Agent I: Hilt DI Modules
## Phase: 3 (Core Logic)
## Depends on: Agent A (Gradle), Agent C (Room database)
## Context
Set up Hilt dependency injection for the entire app.
Provides singletons for database, network, crypto components.
## Task
Create all Hilt DI modules for the application.
## Files to Create
### 1. di/AppModule.kt
```kotlin
package com.kecalek.chat.di
import android.content.Context
import androidx.room.Room
import com.kecalek.chat.data.local.AppDatabase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import net.sqlcipher.database.SupportFactory
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides
@Singleton
fun provideDatabase(
@ApplicationContext context: Context,
): AppDatabase {
// TODO: Get database passphrase from secure storage
// For now, use a placeholder. In production, derive from identity key.
val passphrase = "TODO_REPLACE_WITH_DERIVED_KEY".toByteArray()
val factory = SupportFactory(passphrase)
return Room.databaseBuilder(
context,
AppDatabase::class.java,
"kecalek_chat.db"
)
.openHelperFactory(factory)
.fallbackToDestructiveMigration()
.build()
}
}
```
### 2. di/DatabaseModule.kt
```kotlin
package com.kecalek.chat.di
import com.kecalek.chat.data.local.AppDatabase
import com.kecalek.chat.data.local.dao.ConversationDao
import com.kecalek.chat.data.local.dao.MessageDao
import com.kecalek.chat.data.local.dao.UserCacheDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
@Provides
fun provideMessageDao(db: AppDatabase): MessageDao = db.messageDao()
@Provides
fun provideConversationDao(db: AppDatabase): ConversationDao = db.conversationDao()
@Provides
fun provideUserCacheDao(db: AppDatabase): UserCacheDao = db.userCacheDao()
}
```
### 3. di/NetworkModule.kt
```kotlin
package com.kecalek.chat.di
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
// TODO: Provide ConnectionManager singleton
// TODO: Provide ProtocolHandler singleton
// TODO: Provide ServerApi singleton
// Placeholder — will be wired when network layer is implemented by Claude Code
}
```
### 4. di/CryptoModule.kt
```kotlin
package com.kecalek.chat.di
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
object CryptoModule {
// TODO: Provide crypto components (implemented by Claude Code)
// - AesGcmCrypto
// - HkdfUtils
// - KeyEncryption (ECP1)
// - Ed25519Crypto
// - X25519Crypto
// - RSACrypto
// - MessagePadding
// - ContactVerification
// Placeholder — will be wired when crypto layer is implemented by Claude Code
}
```
## Constraints
- All modules use `@InstallIn(SingletonComponent::class)` unless scoped differently
- Database uses SQLCipher encryption via SupportFactory
- DAO providers are simple pass-through from AppDatabase
- Network and Crypto modules are placeholders (Claude Code implements the actual classes)
- Use `@Singleton` for expensive objects (database, network manager)
## DO NOT
- Implement actual crypto or network classes
- Add any UI-related bindings
- Create ViewModel bindings (Hilt handles those automatically via @HiltViewModel)