|
| 1 | +# Account API (feature/account/api) |
| 2 | + |
| 3 | +A small, feature‑agnostic API for representing accounts by identity only. It provides: |
| 4 | + |
| 5 | +- Strongly‑typed account identifiers (`AccountId`) |
| 6 | +- A minimal Account interface (identity only) |
| 7 | +- A unified account sentinel for aggregated views |
| 8 | +- Profile types for UI (`AccountProfile`) and an abstraction to fetch/update them (AccountProfileRepository) |
| 9 | + |
| 10 | +This module intentionally avoids feature‑specific fields (like email addresses). Mail, calendar, sync, etc. should |
| 11 | +attach their own capability models keyed by `AccountId`. |
| 12 | + |
| 13 | +## Core concepts |
| 14 | + |
| 15 | +- `Account`: Marker interface for an account, identified solely by `AccountId`. |
| 16 | +- `AccountId`: Typealias of `Id<Account>` (UUID‑backed inline value class). Prefer this over raw strings. |
| 17 | +- `AccountIdFactory`: Utility for creating/parsing `AccountId` values. |
| 18 | +- `UnifiedAccountId`: Reserved `AccountId` (UUID nil) used to represent the virtual “Unified” scope across accounts. |
| 19 | + - `AccountId.isUnified`: Shorthand check for unified account id. |
| 20 | + - `AccountId.requireReal()`: Throws if called with the unified ID. Use in repositories/mutation paths. |
| 21 | +- `AccountProfile`: Display/profile data for UI (name, color, avatar) keyed by AccountId. |
| 22 | +- `AccountProfileRepository`: Abstraction to read/update profiles. |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Create a new `AccountId` or parse an existing one: |
| 27 | + |
| 28 | +```kotlin |
| 29 | +val id = AccountIdFactory.create() // new random AccountId |
| 30 | +val parsed = AccountIdFactory.of(rawString) // parse from persisted value |
| 31 | +``` |
| 32 | + |
| 33 | +Detect and guard against the unified account in write paths: |
| 34 | + |
| 35 | +```kotlin |
| 36 | +fun AccountId.requireReal(): AccountId // throws IllegalStateException for unified |
| 37 | + |
| 38 | +if (id.isUnified) { |
| 39 | + // route to unified UI/aggregation services instead of repositories |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +Fetch/update an account profile: |
| 44 | + |
| 45 | +```kotlin |
| 46 | +val profiles: Flow<AccountProfile?> = repo.getById(id) |
| 47 | +repo.update(AccountProfile(id, name = "Alice", color = 0xFFAA66, avatar = AccountAvatar.Monogram(value = "A"))) |
| 48 | +``` |
| 49 | + |
| 50 | +## Design guidelines |
| 51 | + |
| 52 | +- Keep Account minimal (identity only). Do not add mail/calendar/sync fields here. |
| 53 | +- Feature modules should define their own models keyed by `AccountId`. |
| 54 | +- Do not persist data for `UnifiedAccountId`. Compute unified profiles/labels in UI where needed. |
| 55 | +- Prefer strong types (`AccountId`) over raw strings for safety and consistency. |
| 56 | + |
| 57 | +## Related types |
| 58 | + |
| 59 | +- `Id<T>`: Generic UUID‑backed identifier (core/architecture/api) |
| 60 | + |
0 commit comments