android-clean-architecture
OfficialAndroid と Kotlin Multiplatform プロジェクトのクリーンアーキテクチャパターン — モジュール構造、依存関係ルール、UseCase、Repository、データ層パターン。
What this skill does
When applied, it prepends a system prompt before your request is sent — no extra calls and no change to how you are billed beyond the added tokens.
---
name: android-clean-architecture
description: Android と Kotlin Multiplatform プロジェクトのクリーンアーキテクチャパターン — モジュール構造、依存関係ルール、UseCase、Repository、データ層パターン。
origin: ECC
---
# Android クリーンアーキテクチャ
Android と KMP プロジェクトのクリーンアーキテクチャパターン。モジュール境界、依存関係の逆転、UseCase/Repository パターン、Room・SQLDelight・Ktor を使用したデータ層設計をカバーします。
## 起動タイミング
- Android または KMP プロジェクトモジュールの構造化
- UseCase、Repository、DataSource の実装
- 層間のデータフロー設計(ドメイン、データ、プレゼンテーション)
- Koin または Hilt による依存性注入のセットアップ
- 層状アーキテクチャでの Room、SQLDelight、Ktor の使用
## モジュール構造
### 推奨レイアウト
```
project/
├── app/ # Android エントリポイント、DI ワイヤリング、Application クラス
├── core/ # 共有ユーティリティ、基底クラス、エラー型
├── domain/ # UseCase、ドメインモデル、リポジトリインターフェース(純粋 Kotlin)
├── data/ # リポジトリ実装、DataSource、DB、ネットワーク
├── presentation/ # スクリーン、ViewModel、UI モデル、ナビゲーション
├── design-system/ # 再利用可能な Compose コンポーネント、テーマ、タイポグラフィ
└── feature/ # フィーチャーモジュール(大規模プロジェクト向けのオプション)
├── auth/
├── settings/
└── profile/
```
### 依存関係ルール
```
app → presentation, domain, data, core
presentation → domain, design-system, core
data → domain, core
domain → core(または依存関係なし)
core → (なし)
```
**重要**: `domain` は `data`、`presentation`、またはどのフレームワークにも依存してはいけません。純粋な Kotlin のみを含みます。
## ドメイン層
### UseCase パターン
各 UseCase は 1 つのビジネス操作を表します。クリーンな呼び出しサイトのために `operator fun invoke` を使用します:
```kotlin
class GetItemsByCategoryUseCase(
private val repository: ItemRepository
) {
suspend operator fun invoke(category: String): Result<List<Item>> {
return repository.getItemsByCategory(category)
}
}
// リアクティブストリーム向けフローベースの UseCase
class ObserveUserProgressUseCase(
private val repository: UserRepository
) {
operator fun invoke(userId: String): Flow<UserProgress> {
return repository.observeProgress(userId)
}
}
```
### ドメインモデル
ドメインモデルはプレーンな Kotlin データクラス — フレームワークのアノテーションなし:
```kotlin
data class Item(
val id: String,
val title: String,
val description: String,
vUse this skill
Add a "skill" field with the skill’s ID to your chat completion request. It is applied server-side before your prompt is sent — no extra calls.
{
"model": "gpt-4o-mini",
"skill": "imp-f6c7ff30-f107-4f48-a02a-d3afa4933755",
"messages": [{ "role": "user", "content": "…" }]
}Install the skill, enable it in your dashboard and (optionally) limit it to specific models. It then applies automatically to every matching request — with no "skill" field to send each time.
Set it up in your dashboardMore skills
Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.
Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.
List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.
Create, search, and manage Bear notes via grizzly CLI.
Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.
BluOS CLI (blu) for discovery, playback, grouping, and volume.
Capture frames or clips from RTSP/ONVIF cameras.
Search, install, update, sync, or publish agent skills with the ClawHub CLI and registry.