ADR 0002: Further towards hexagonal, with DDD only where there are rules
Status: Accepted, implemented (accepted 2026-11-22, the owner’s answers below; proposed the same day; built by 2026-11-23 in #879, #882, #883, #885, #886, #888, #895, #903, #904, #905, #906, #908, #910, #911, #913, #914, #915, documented in #772). Amends ADR 0001, decisions 1, D1 and D2.
Context
Section titled “Context”ADR 0001 put the Jellyfin server behind ports and rejected tactical DDD because the domain was thought thin. On 2026-11-22 the owner asked to go as far towards hexagonal architecture with DDD as is sensible, without waiting for Emby, and to do #773 (opaque ids) and #774 (the repository’s name) now. 5-hexagonal-ddd.md measures the code:
- Every feature module depends on
data, the Room adapter, because the repository interface lives there. Twenty files outsidedatause the DAO. - The catalog is thin, as ADR 0001 said. User data and downloads are not: their rules are spread
over
domain,dataandcore, and “a download is finished” is decided by a file name in eight files. - Ids are
UUIDin 173 files; the server type and the session are switched in two steps.
Decision
Section titled “Decision”- The application’s ports leave the Room adapter. The repository interface and the stores
that features use go to their own place (Q3), with no Room. Only the apps depend on
data, as only they depend onserver/jellyfin. The build enforces it (rule R9). - Room goes behind three store ports,
ServerStore,DownloadStore,PendingUserDataStore, keyed by anAccountKey(serverId, userId). Rule R4’s baseline goes to zero. Switching servers is one call that sets the type, address, token and account together. - DDD where there are rules, nowhere else. Two domain models,
PlayState(marks, stops, the sync’s conflict rules) andDownloadState; value objects for ids andAccountKey; oneTickshelper. No aggregates for the catalog, no new domain events, no use case per call. - Opaque ids now (replaces D1). One
ItemIdfor every kind of item, plusUserId,ServerIdandMediaSourceId, as value classes overString. For Jellyfin the string is the dashed form stored today, so Room needs no migration.java.util.UUIDstays insideserver/jellyfin(rule R10). Done first as a textual pass over the aliases, then as one flip. JellyfinRepositorybecomesMediaRepositorynow (replaces D2), with the model names per Q2. Packages keepdev.jdtech.jellyfin.- The order and the costs are in 5.3. Each step is one PR that leaves the app working, and each gain gets a rule that fails the build when it is undone.
Questions for the owner
Section titled “Questions for the owner”Answered by the owner on 2026-11-22, through the overseer session. Their own words, translated, where they added some.
| Question | Recommendation | Answer | |
|---|---|---|---|
| Q1 | Do T1 to T8 and T10; file T9 (a downloads module) for later |
yes | Everything, T9 included, as the last of the series after the ports it needs: “I don’t see the downside of simply doing it all right away.” |
| Q2 | Names: (a) the repository only, (b) also the Findroid* models, (c) also the packages |
(b) | (b). Renaming the packages is a possible follow-up, not a task: “gains nothing now.” The application id never changes |
| Q3 | The repository interface in a new application module, or in domain |
application |
application |
| Q4 | One ItemId, or one id type per kind |
one ItemId |
One ItemId, with their own types for what is something else (user, server): “We can change this later if bugs come up again.” |
| Q5 | Device tests on emulators with throwaway users only, no check by the owner | yes | Yes, with the thoroughness of the #770 check (upgrade from the previous build with rich data, the database compared before and after, switching users and servers). At the end of the series one beta from main, which the owner installs over their own install: “After all this I’ll test it myself in a beta anyway.” |
Consequences
Section titled “Consequences”- A feature module can no longer reach Room or an adapter; a fake of one store replaces a fake of the whole repository in the download and sync tests.
- An Emby adapter brings its own id strings and needs no mapping table.
- The rules about played, favourite and resume positions are tested in
domain, without Android. - Most upstream Kotlin changes are re-applied by hand after T1, T2 and T4 (accepted, PR 844).
- About 25 more PRs, none visible to a user, apart from the fix to the server switch.
Source: docs/architecture/adr/0002-hexagonal-ddd.md · raw Markdown