Skip to content

Commit 3866163

Browse files
committed
Update architecture and style guidelines for Compose and DataStore migration
Modernize documentation to reflect the shift from Fragments/XML to Compose/Navigation3 and SharedPreferences/Moshi to DataStore/Kotlinx Serialization. Updates base classes to ViewModel4 and StateFlow.
1 parent 4174c8c commit 3866163

3 files changed

Lines changed: 49 additions & 37 deletions

File tree

.claude/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ Detailed guidelines are in `.claude/rules/`:
2323
- `commit-guidelines.md` — Commit message format, PR description format, area prefixes
2424
- `build-commands.md` — Build, test, lint, screenshot, and release commands
2525
- `architecture.md` — Module structure, patterns, base classes, data flow
26-
- `code-style.md` — Kotlin conventions, ViewModel/Fragment patterns, logging
26+
- `code-style.md` — Kotlin conventions, ViewModel/Compose patterns, logging
2727
- `testing.md` — Test locations, patterns, running tests
2828
- `localization.md` — String resources, naming conventions

.claude/rules/architecture.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77

88
## Core Architecture Patterns
99

10-
- **MVVM**: ViewModels with LiveData/StateFlow for UI state management
10+
- **MVVM**: ViewModels with StateFlow for UI state management
1111
- **Dependency Injection**: Hilt/Dagger for dependency management
1212
- **Coroutines**: Extensive use of Kotlin coroutines for async operations
1313
- **Repository Pattern**: Data layer abstraction with sealed State classes
14-
- **Single Activity**: Navigation Component with multiple fragments
14+
- **Single Activity**: Navigation3 with Compose screens
1515

1616
## Base UI Classes (`app/src/main/java/eu/darken/myperm/common/uix/`)
1717

18-
- `ViewModel3`: Full MVVM support with nav events + error events (most feature VMs extend this)
18+
- `ViewModel4`: Primary base class — implements `NavigationEventSource` + `ErrorEventSource2` via `SingleEventFlow` (all
19+
feature VMs extend this)
20+
- `ViewModel3`: Legacy MVVM base with `SingleLiveEvent` (still exists, not used by new code)
1921
- `ViewModel2`: Coroutine scope with error handlers
2022
- `ViewModel1`: Basic logging
21-
- `Fragment3`: MVVM integration, observes navEvents/errorEvents from ViewModel
22-
- `Fragment2`: Lifecycle logging
2323
- `Activity2`: Base activity with logging
24+
- `Service2`: Base service with logging
2425

2526
## Repository Pattern
2627

@@ -38,16 +39,17 @@ sealed class State {
3839

3940
## Navigation System
4041

41-
- Single Activity (`MainActivity`) with `NavHostFragment`
42-
- AndroidX Navigation with Safe Args (KSP-generated)
43-
- Navigation graphs: `res/navigation/main_navigation.xml`, `res/navigation/bottom_navigation.xml`
44-
- `NavEventSource` interface: ViewModels expose `navEvents: SingleLiveEvent<NavDirections>`
45-
- `ErrorEventSource` interface: ViewModels expose `errorEvents: SingleLiveEvent<Throwable>`
42+
- Single Activity (`MainActivity`) with Navigation3 (Compose-based, no fragments)
43+
- Custom `NavigationController` + `NavigationEntry` (not AndroidX Navigation fragments)
44+
- `NavigationEventSource` interface: ViewModels expose `navEvents: SingleEventFlow<NavEvent>`
45+
- `NavEvent` sealed class: `GoTo(destination, popUpTo, inclusive)` and `Up`
46+
- `ErrorEventSource2` interface: ViewModels expose `errorEvents: SingleEventFlow<Throwable>`
4647

4748
## Settings System
4849

49-
- `GeneralSettings` singleton uses SharedPreferences with Moshi JSON serialization
50-
- Flow-based preference reading via `createFlowPreference()`
50+
- `GeneralSettings` singleton uses DataStore Preferences with Kotlinx Serialization
51+
- Flow-based preference reading via `createValue()` with `kotlinxReader`/`kotlinxWriter` helpers
52+
- SharedPreferences retained only for migration via `SharedPreferencesMigration`
5153
- Located in `settings/core/GeneralSettings.kt`
5254

5355
## Data Flow
@@ -57,36 +59,45 @@ The app follows unidirectional data flow:
5759
1. `AppRepo` queries PackageManager for installed apps
5860
2. `PermissionRepo` aggregates permission data from apps
5961
3. ViewModels combine repository flows with filter/sort options
60-
4. UI observes ViewModel state via LiveData
62+
4. Compose UI collects ViewModel state via StateFlow
6163
5. User actions trigger ViewModel methods which update repository or navigate
6264

6365
## Project Structure
6466

67+
Representative structure (not exhaustive):
68+
6569
```
6670
app/src/main/java/eu/darken/myperm/
6771
├── main/ # MainActivity, main navigation hub
6872
├── permissions/ # Permissions feature
6973
│ ├── core/ # PermissionRepo, data models
70-
│ └── ui/ # List and details fragments
74+
│ └── ui/ # List and details Compose screens
7175
├── apps/ # Apps feature
7276
│ ├── core/ # AppRepo, PackageManager interactions
73-
│ └── ui/ # List and details fragments
77+
│ └── ui/ # List and details Compose screens
78+
├── watcher/ # Permission change monitoring
79+
│ ├── core/ # WatcherManager, SnapshotDiffer, PermissionDiff
80+
│ └── ui/ # Dashboard and report detail screens
7481
├── settings/ # Settings feature
7582
│ ├── core/ # GeneralSettings
76-
│ └── ui/ # Settings fragments
83+
│ └── ui/ # Settings Compose screens
7784
└── common/ # Shared utilities
78-
├── uix/ # Base UI classes
85+
├── uix/ # Base UI classes (ViewModel4, Activity2, Service2)
86+
├── compose/ # Shared Compose components
7987
├── coroutine/ # DispatcherProvider, AppScope
8088
├── dagger/ # Hilt DI modules
81-
├── navigation/ # Nav extensions
82-
├── lists/ # ModularAdapter pattern for RecyclerView
83-
└── preferences/# FlowPreference utilities
89+
├── datastore/ # DataStore helpers (createValue, kotlinxReader/Writer)
90+
├── navigation/ # Navigation3 extensions, NavigationEventSource
91+
├── room/ # Room database, DAOs, entities
92+
└── serialization/ # Kotlinx Serialization utilities
8493
```
8594

8695
## Key Dependencies
8796

97+
- **Jetpack Compose**: UI framework (Material 3)
8898
- **Hilt**: Dependency injection framework
89-
- **AndroidX Navigation**: Fragment navigation with SafeArgs
90-
- **Moshi**: JSON serialization for settings and data
99+
- **Navigation3**: Compose-based navigation
100+
- **Kotlinx Serialization**: JSON serialization for settings and data
101+
- **DataStore**: Preferences storage
102+
- **Room**: Database for watcher snapshots
91103
- **Coil**: Image loading for app icons
92-
- **Material Design**: UI components

.claude/rules/code-style.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ Use `DispatcherProvider` interface for testability instead of hardcoded dispatch
2222

2323
```kotlin
2424
@HiltViewModel
25-
class MyFeatureVM @Inject constructor(
25+
class MyFeatureViewModel @Inject constructor(
2626
private val handle: SavedStateHandle,
2727
dispatcherProvider: DispatcherProvider,
2828
private val myRepo: MyRepo,
29-
) : ViewModel3(dispatcherProvider = dispatcherProvider)
29+
) : ViewModel4(dispatcherProvider = dispatcherProvider)
3030
```
3131

32-
## Fragment Creation Pattern
32+
## Screen Creation Pattern
3333

3434
```kotlin
35-
@AndroidEntryPoint
36-
class MyFeatureFragment : Fragment3(R.layout.my_feature_fragment) {
37-
override val vm: MyFeatureVM by viewModels()
38-
override val ui: MyFeatureFragmentBinding by viewBinding()
35+
@Composable
36+
fun MyFeatureScreenHost(vm: MyFeatureViewModel = hiltViewModel()) {
37+
ErrorEventHandler(vm)
38+
NavigationEventHandler(vm)
39+
val state by vm.state.collectAsState()
40+
MyFeatureScreen(state = state, ...)
3941
}
4042
```
4143

@@ -58,19 +60,18 @@ log(TAG, WARN) { "Unexpected state" } // WARN
5860

5961
## UI Patterns
6062

61-
- XML layouts with ViewBinding for UI components
63+
- Jetpack Compose is the sole UI framework — no XML layouts remain
6264
- Material 3 theming and design system
63-
- Single Activity architecture with Fragment-based navigation
64-
- Compose is used for new screens alongside existing XML/ViewBinding
65+
- Single Activity architecture with Compose-based navigation
6566

6667
## Error Handling
6768

68-
- Use the established error handling patterns with `ErrorEventSource`
69-
- ViewModels expose `errorEvents: SingleLiveEvent<Throwable>`
69+
- ViewModels implement `ErrorEventSource2`, exposing `errorEvents: SingleEventFlow<Throwable>`
70+
- Compose screens wire errors via `ErrorEventHandler(vm)` composable
7071

7172
## Data & State
7273

7374
- Reactive programming with Kotlin Flow and StateFlow
74-
- SharedPreferences with Moshi JSON serialization for settings
75+
- DataStore with Kotlinx Serialization for settings
7576
- Room for database operations
7677
- Coil for image loading

0 commit comments

Comments
 (0)