Bplogger

Pulse Log Android/iOS 공통 코드 설계

1. 목표

Android와 iOS를 함께 운영할 때 같은 정책과 데이터 규칙을 두 번 구현하지 않도록 Kotlin Multiplatform 기반 공통 모듈을 둔다.

목표는 다음과 같다.

2. 결론

권장 구조는 shared Kotlin Multiplatform 모듈 + Android 앱 + iOS 앱이다.

첫 단계에서 공유할 것:

첫 단계에서 공유하지 않을 것:

이유:

3. 목표 구조

settings.gradle.kts
build.gradle.kts

shared/
  build.gradle.kts
  src/
    commonMain/kotlin/com/pulselog/shared/
      model/
      domain/
      repository/
      usecase/
      presentation/
      export/
    commonTest/kotlin/com/pulselog/shared/
    androidMain/kotlin/com/pulselog/shared/
    iosMain/kotlin/com/pulselog/shared/

app/
  기존 Android 앱

iosApp/
  Xcode/SwiftUI 앱 또는 Compose Multiplatform iOS entry

4. 공유 대상 상세

4.1 Model

공유한다.

data class DailyHealthRecord(...)
data class NotificationSettings(...)
data class CalendarDayStatus(...)
data class GraphPoint(...)

주의:

4.2 Domain Policy

공유한다.

이 영역은 가장 먼저 옮긴다. Android 테스트를 shared common test로 이전하면 양쪽 플랫폼이 같은 규칙을 사용한다.

4.3 Repository Interface

공유한다.

interface HealthRepository {
    fun observeRecord(date: LocalDate): Flow<DailyHealthRecord?>
    fun observeMonthStatuses(month: YearMonth): Flow<List<CalendarDayStatus>>
    fun observeGraphPoints(days: Int): Flow<List<GraphPoint>>
    fun observeNotificationSettings(): Flow<NotificationSettings>

    suspend fun saveMorning(...)
    suspend fun saveEvening(...)
    suspend fun saveWeight(...)
    suspend fun deleteMorning(...)
    suspend fun deleteEvening(...)
    suspend fun deleteWeight(...)
    suspend fun saveNotificationSettings(settings: NotificationSettings)
}

Android 구현:

iOS 구현:

4.4 Presentation State

부분 공유한다.

공유하기 좋은 것:

플랫폼에 남길 것:

권장 방식:

shared presentation reducer/usecase
Android BpViewModel -> shared usecase 호출
iOS ObservableObject -> shared usecase 호출

이렇게 하면 UI 상태 규칙은 공유하고, 플랫폼 생명주기와 UI 이벤트 처리는 각 플랫폼에 남길 수 있다.

4.5 Database

두 가지 선택지가 있다.

선택 A. Room KMP

장점:

주의:

선택 B. SQLDelight

장점:

주의:

권장:

5. UI 공유 전략

옵션 A. UI는 플랫폼별, 로직만 공유

권장 첫 단계.

장점:

단점:

옵션 B. Compose Multiplatform으로 UI까지 공유

2단계 이후 검토.

장점:

단점:

권장:

6. 단계별 이행 계획

Phase KMP-0. 준비

완료 기준:

Phase KMP-1. 순수 정책 이동

완료 기준:

Phase KMP-2. 모델과 repository 계약 공유

완료 기준:

Phase KMP-3. UseCase 공유

완료 기준:

Phase KMP-4. iOS 앱 연결

완료 기준:

Phase KMP-5. UI 공유 검토

완료 기준:

7. 리스크와 대응

Android 배포 회귀

대응:

iOS 빌드 환경 복잡도

대응:

UI 공유 과욕

대응:

DB 공통화 리스크

대응:

8. 최종 방향

Pulse Log의 장기 구조는 다음이 가장 적합하다.

공유 Kotlin:
  모델, 정책, repository 계약, usecase, export formatter, 알림 판단

Android:
  기존 Compose UI, Android ViewModel wrapper, Room 구현, AlarmManager, Android share sheet

iOS:
  SwiftUI 또는 Compose UI, iOS state wrapper, iOS repository 구현, UNUserNotificationCenter, iOS share sheet

이 구조는 업데이트 때 검증/정책/데이터 의미를 한 번만 수정하게 만들고, 플랫폼별 OS 기능은 각 플랫폼에서 안정적으로 처리하게 한다.