Skip to content

Commit 6a85c8a

Browse files
committed
docs: add descriptions of the id and accountId
1 parent ae12eef commit 6a85c8a

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

core/architecture/api/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Core Architecture
2+
3+
High‑level primitives shared across modules in this project.
4+
5+
## ID
6+
7+
Small, cross‑module primitives for strongly‑typed identifiers.
8+
9+
### Core concepts
10+
11+
- Principles:
12+
- Keep IDs opaque and strongly typed (no raw strings at call sites).
13+
- Centralize generation/parsing via factories to ensure consistency.
14+
- Keep the core generic; domain modules extend via typealiases and small factories.
15+
- Building blocks:
16+
- `Id<T>`: a tiny value type wrapping a UUID (kotlin.uuid.Uuid).
17+
- `IdFactory<T>`: contract for creating/parsing typed IDs.
18+
- `BaseIdFactory<T>`: abstract UUID‑based implementation of `IdFactory<T>` for standardized creation and parsing.
19+
20+
Implement custom factories if you need non‑UUID schemes; otherwise prefer BaseIdFactory.
21+
22+
### Usage
23+
24+
Create a typed ID and parse from storage:
25+
26+
```kotlin
27+
// Domain type
28+
data class Project(val id: ProjectId)
29+
30+
// Typed alias
31+
typealias ProjectId = Id<Project>
32+
33+
// Factory
34+
object ProjectIdFactory : BaseIdFactory<Project>()
35+
36+
// Create new ID
37+
val id: ProjectId = ProjectIdFactory.create()
38+
39+
// Persist/restore
40+
val raw: String = id.asRaw()
41+
val parsed: ProjectId = ProjectIdFactory.of(raw)
42+
```
43+

feature/account/api/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)