Skip to content

Refactor to api + core + remote module architecture#39

Merged
linroid merged 6 commits intomainfrom
refactor/api-embedded-remote
Feb 11, 2026
Merged

Refactor to api + core + remote module architecture#39
linroid merged 6 commits intomainfrom
refactor/api-embedded-remote

Conversation

@linroid
Copy link
Owner

@linroid linroid commented Feb 11, 2026

Summary

Split the monolithic library module into three focused modules with clear separation of concerns:

  • library:api — shared public types and the KDownApi interface
  • library:core — in-process download engine implementing KDownApi
  • library:remote — HTTP+SSE client implementing KDownApi for controlling a remote daemon

This enables the UI layer to work identically regardless of whether downloads run in-process or on a remote server.

Changes

New: library:api

  • Public types extracted into flat com.linroid.kdown.api package: KDownApi, KDownVersion, DownloadTask, DownloadRequest, DownloadState, DownloadProgress, DownloadPriority, DownloadSchedule, DownloadCondition, SpeedLimit, Segment, KDownError, PathSerializer
  • KDownApi interface defines the contract both backends implement

New: library:core (extracted from the original monolithic module)

  • Core implementation class named KDown (implements KDownApi)
  • All engine, file I/O, segment, task, and logging internals in com.linroid.kdown.core

New: library:remote

  • RemoteKDown implements KDownApi via HTTP calls to the daemon server
  • RemoteDownloadTask with reactive state via SSE
  • Internal wire DTOs and WireMapper for JSON serialization

Naming

  • KDownApi = the interface (api module)
  • KDown = the core in-process implementation (core module)
  • RemoteKDown = the remote client implementation (remote module)

Other modules updated

  • library:ktor, library:kermit, library:sqlite — import updates
  • server/ — uses KDownApi in route signatures, KDown for construction
  • examples/ — updated imports and constructor calls

Module dependency graph

library:api           ← shared types + KDownApi interface
  ↑          ↑
library:core         library:remote
  ↑
library:ktor, library:kermit, library:sqlite

Test plan

  • All library modules compile (api, core, remote, ktor, kermit)
  • All test sources compile (api, core)
  • No stale imports remaining (verified via grep)

🤖 Generated with Claude Code

Restructure library modules to separate shared API types from
implementation, enabling both embedded and remote backends to share
a unified DownloadTask interface.

Module changes:
- library:core → library:embedded (renamed)
- library:service → deleted (merged into embedded as EmbeddedKDownService)
- library:client → library:remote (renamed)
- library:api → expanded with shared types and DownloadTask interface

Key design changes:
- DownloadTask is now an interface in api; DownloadTaskImpl is internal
  in embedded; RemoteDownloadTask implements it via HTTP in remote
- KDownService rewritten to use DownloadTask directly (no wire DTOs)
- Wire models (TaskResponse, CreateDownloadRequest) moved to remote
  as internal serialization types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2026

Test Results

492 tests  +255   491 ✅ +254   6s ⏱️ -1s
 42 suites + 19     0 💤 ±  0 
 42 files   + 19     1 ❌ +  1 

For more details on these failures, see this check.

Results for commit 3f40c58. ± Comparison against base commit 1d030ed.

This pull request removes 99 and adds 354 tests. Note that renamed tests count towards both.
com.linroid.kdown.DownloadProgressTest ‑ defaultBytesPerSecond_isZero[jvm]
com.linroid.kdown.DownloadProgressTest ‑ isComplete_whenFullyDownloaded[jvm]
com.linroid.kdown.DownloadProgressTest ‑ isComplete_whenOverDownloaded[jvm]
com.linroid.kdown.DownloadProgressTest ‑ isNotComplete_whenPartial[jvm]
com.linroid.kdown.DownloadProgressTest ‑ isNotComplete_whenZeroTotal[jvm]
com.linroid.kdown.DownloadProgressTest ‑ percent_complete[jvm]
com.linroid.kdown.DownloadProgressTest ‑ percent_halfComplete[jvm]
com.linroid.kdown.DownloadProgressTest ‑ percent_zeroProgress[jvm]
com.linroid.kdown.DownloadProgressTest ‑ percent_zeroTotal_returnsZero[jvm]
com.linroid.kdown.DownloadRequestTest ‑ blankUrl_throws[jvm]
…
com.linroid.kdown.QueueConfigTest ‑ copy_preservesFields[jvm]
com.linroid.kdown.QueueConfigTest ‑ customConfig_preservesValues[jvm]
com.linroid.kdown.QueueConfigTest ‑ defaultConfig_hasExpectedValues[jvm]
com.linroid.kdown.QueueConfigTest ‑ downloadConfig_defaultQueueConfig[jvm]
com.linroid.kdown.QueueConfigTest ‑ downloadConfig_includesQueueConfig[jvm]
com.linroid.kdown.QueueConfigTest ‑ equality_sameValues[jvm]
com.linroid.kdown.QueueConfigTest ‑ negativeMaxConcurrentDownloads_throws[jvm]
com.linroid.kdown.QueueConfigTest ‑ negativeMaxConnectionsPerHost_throws[jvm]
com.linroid.kdown.QueueConfigTest ‑ singleConcurrentDownload_allowed[jvm]
com.linroid.kdown.QueueConfigTest ‑ singleConnectionPerHost_allowed[jvm]
…

♻️ This comment has been updated with latest results.

linroid and others added 3 commits February 11, 2026 12:01
- KDownService interface → KDown interface (in library:api)
- EmbeddedKDownService → EmbeddedKDown (in library:embedded)
- RemoteKDownService → RemoteKDown (in library:remote)
- Use import alias in EmbeddedKDown to disambiguate from
  com.linroid.kdown.KDown engine class

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
events() is an SSE/server concern, not a consumer API concern.
Consumers observe tasks and task.state StateFlows directly.

- Remove events() from KDown interface
- Delete TaskEvent, ProgressResponse, ErrorResponse from api/model
- Remove events() implementation from EmbeddedKDown and RemoteKDown
- Delete TaskMapper from embedded (only used for event synthesis)
- Remove toTaskEvent from WireMapper in remote

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- connectionState is a remote-specific concern, moved to RemoteKDown
- getStatus()/ServerStatus removed (consumers derive counts from tasks)
- backendLabel kept on KDown interface
- ConnectionState moved from api to remote module
- Delete empty api/model/ directory (ServerStatus was last file)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Feb 11, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

…ackage

- Rename api module interface `KDown` → `KDownApi` to resolve naming conflict
- Rename core module class `CoreKDown` → `KDown` (the natural name for the impl)
- Flatten all api types into `com.linroid.kdown.api` (remove task/, segment/,
  error/, file/ subpackages)
- Update all imports across core, remote, ktor, kermit, sqlite, server, examples

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@linroid linroid changed the title Refactor to api + embedded + remote module architecture Refactor to api + core + remote module architecture Feb 11, 2026
@linroid linroid merged commit a52ec8f into main Feb 11, 2026
5 of 7 checks passed
@linroid linroid deleted the refactor/api-embedded-remote branch February 11, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant