feat: service extraction (#4828)

This commit is contained in:
James Rich 2026-03-17 14:06:01 -05:00 committed by GitHub
parent 0d0bdf9172
commit 807db83f53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 309 additions and 257 deletions

View file

@ -0,0 +1,5 @@
# Track extract_services_20260317 Context
- [Specification](./spec.md)
- [Implementation Plan](./plan.md)
- [Metadata](./metadata.json)

View file

@ -0,0 +1,8 @@
{
"track_id": "extract_services_20260317",
"type": "refactor",
"status": "new",
"created_at": "2026-03-17T00:00:00Z",
"updated_at": "2026-03-17T00:00:00Z",
"description": "Extract service/worker/radio files from `app` to `core:service/androidMain` and `core:network/androidMain`"
}

View file

@ -0,0 +1,44 @@
# Implementation Plan: Extract service/worker/radio files from `app`
## Phase 1: Preparation & Analysis [checkpoint: 72022ed]
- [x] Task: Identify all Android-specific classes to be moved (Services, WorkManager workers, Radio connections in `app`) [fd916e3]
- [ ] Locate `Service` classes in `app/src/main/java/org/meshtastic/app`
- [ ] Locate WorkManager `Worker` classes
- [ ] Locate Radio connection classes
- [x] Task: Conductor - User Manual Verification 'Preparation & Analysis' (Protocol in workflow.md)
## Phase 2: Extraction to `core:service` [checkpoint: ff47af8]
- [x] Task: Setup `core:service` module for Android and Common targets (if not already fully configured) [a114084]
- [x] Task: Move Android `Service` implementations to `core:service/androidMain` [965def0]
- [x] Move the files
- [x] Update imports and Koin injections
- [x] Task: Abstract shared service logic into `core:service/commonMain` [a85e282]
- [x] Write failing tests for abstracted shared logic (TDD Red)
- [x] Extract interfaces and platform-agnostic logic (TDD Green)
- [x] Refactor the implementations to use these shared abstractions
- [x] Task: Conductor - User Manual Verification 'Extraction to core:service' (Protocol in workflow.md)
## Phase 3: Extraction to `core:network` [checkpoint: 97a5b62]
- [x] Task: Move Radio connection and networking files from `app` to `core:network/androidMain` [b5233cf]
- [x] Move the files
- [x] Update imports and Koin injections
- [x] Task: Abstract shared radio/network logic into `core:network/commonMain` [cc1581d]
- [x] Write failing tests for abstracted radio logic (TDD Red)
- [x] Extract platform-agnostic business logic (TDD Green)
- [x] Refactor implementations to use shared abstractions
- [x] Task: Conductor - User Manual Verification 'Extraction to core:network' (Protocol in workflow.md)
## Phase 4: Desktop Integration [checkpoint: fffcedc]
- [x] Task: Integrate newly extracted shared abstractions into the `desktop` module [f39df2f]
- [x] Implement desktop-specific actuals or Koin bindings for the shared interfaces
- [x] Wire up abstracted services/radio logic in desktop Koin graph
- [x] Task: Conductor - User Manual Verification 'Desktop Integration' (Protocol in workflow.md)
## Phase 5: Verification & Cleanup [checkpoint: a0866e0]
- [x] Task: Build project and verify no regressions in background processing or radio connectivity [a9edc2e]
- [x] Task: Verify test coverage (>80%) for all extracted and refactored code [9cff9bc]
- [x] Task: Remove any lingering unused dependencies or dead code in `app` [e39d2e2]
- [x] Task: Conductor - User Manual Verification 'Verification & Cleanup' (Protocol in workflow.md)
## Phase: Review Fixes
- [x] Task: Apply review suggestions [1ae9fb6]

View file

@ -0,0 +1,32 @@
# Specification: Extract service/worker/radio files from `app`
## Overview
This track aims to decouple the main `app` module by extracting Android-specific service, WorkManager worker, and radio connection files into `core:service` and `core:network` modules. The goal is to maximize code reuse across Kotlin Multiplatform (KMP) targets, clarify class responsibilities, and improve unit testability by isolating the network and service layers.
## Goals
- **Decouple `app`:** Remove Android-specific service dependencies from the main app module.
- **KMP Preparation:** Migrate as much logic as possible into `commonMain` for reuse across platforms.
- **Desktop Integration:** If logic is successfully abstracted into `commonMain`, integrate and use it within the `desktop` target to ensure reusability.
- **Testability:** Isolate service and network layers to facilitate better unit testing.
- **Simplification:** Refactor logic during the move to clarify and simplify responsibilities.
## Functional Requirements
- Identify all service, worker, and radio-related classes currently residing in the `app` module.
- Move Android-specific implementations (e.g., `Service`, `Worker`) to `core:service/androidMain` and `core:network/androidMain`.
- Extract platform-agnostic business logic and interfaces into `commonMain` within those core modules.
- Refactor existing logic where necessary to establish a clear delineation of responsibility.
- Update all dependency injections (Koin modules) and imports across the project to reflect the new locations.
- Attempt to wire up the newly abstracted shared logic within the `desktop` module if applicable.
## Non-Functional Requirements
- **Architecture Compliance:** Changes must adhere to the MVI / Unidirectional Data Flow and KMP structures defined in `tech-stack.md`.
- **Performance:** Refactoring should not negatively impact app startup time or background processing efficiency.
- **Code Coverage:** Maintain or improve overall test coverage for the extracted components (>80% target).
## Acceptance Criteria
- [ ] No service, worker, or radio connection classes remain in the `app` module.
- [ ] Extracted Android-specific classes compile successfully in `core:service/androidMain` and `core:network/androidMain`.
- [ ] Shared business logic compiles successfully in `core:service/commonMain` and `core:network/commonMain`.
- [ ] If logic is abstracted for reuse, it is integrated and utilized in the `desktop` target where applicable.
- [ ] The app compiles, installs, and runs without regressions in background processing or radio connectivity.
- [ ] Unit tests for the moved and refactored classes pass.

View file

@ -20,6 +20,6 @@ Meshtastic-Android is a Kotlin Multiplatform (KMP) application designed to facil
- Device configuration and firmware updates
## Key Architecture Goals
- Provide a robust, shared KMP core (`core:model`, `core:ble`, `core:repository`, `core:domain`, `core:data`, `core:network`) to support multiple platforms (Android, Desktop, iOS)
- Provide a robust, shared KMP core (`core:model`, `core:ble`, `core:repository`, `core:domain`, `core:data`, `core:network`, `core:service`) to support multiple platforms (Android, Desktop, iOS)
- Ensure offline-first functionality and resilient data persistence (Room KMP)
- Decouple UI logic into shared components (`core:ui`, `feature:*`) using Compose Multiplatform

View file

@ -7,6 +7,9 @@
- **Compose Multiplatform:** Shared UI layer for rendering on Android and Desktop.
- **Jetpack Compose:** Used where platform-specific UI (like charts or permissions) is necessary on Android.
## Background & Services
- **Platform Services:** Core service orchestrations and background work are abstracted into `core:service` to maximize logic reuse across targets, using platform-specific implementations (e.g., WorkManager/Service on Android) only where necessary.
## Architecture
- **MVI / Unidirectional Data Flow:** Shared view models using the multiplatform `androidx.lifecycle.ViewModel`.
- **JetBrains Navigation 3:** Multiplatform fork for state-based, compose-first navigation without relying on `NavController`.

View file

@ -1,5 +1,3 @@
# Project Tracks
This file tracks all major tracks for the project. Each track has its own detailed plan in its respective folder.
---