compose-arch
Compose Multiplatform Architecture Framework - strict Screen/View/Component layering, use cases, repositories, and feature slice patterns
What this skill does
# Compose Multiplatform Architecture Framework
> **SINGLE SOURCE OF TRUTH** for Compose Multiplatform architecture rules. All agents and skills reference this file — do not duplicate these rules elsewhere.
Strict architectural patterns for building Compose Multiplatform features using feature slices. Enforces separation of concerns through Screen/View/Component layering.
**Related skills:**
- `kmp-feature-slice` — procedural feature generation workflow (uses this skill's rules)
- `kotlin-web` — web frontend patterns (Compose WASM follows these same rules)
## Core Principles
### Layer Separation (STRICT)
| Layer | Responsibility | Rules |
|-------|----------------|-------|
| **Screen** | Thin adapter | Reads viewState, passes to View. NO logic, NO remember, NO calculations |
| **View** | Pure UI | Only layout, only viewState, only eventHandler. NO side effects |
| **Component** | All logic | State, events, use cases, lifecycle. Uses Decompose |
| **Domain** | Business | Use cases, repositories, data sources |
## Screen Layer
**File**: `<FeatureName>Screen.kt`
```kotlin
@Composable
fun FeatureScreen(component: FeatureComponent) {
val viewState by component.viewState.subscribeAsState()
FeatureView(viewState, component::obtainEvent)
}
```
### Screen Rules
- **Maximum**: 1000 lines (hard limit)
- **Recommended**: Under 600 lines
- **Forbidden**:
- Business logic
- Navigation logic
- State management
- `remember` calls
- Calculations
## View Layer
**File**: `<FeatureName>View.kt`
```kotlin
@Composable
fun FeatureView(
viewState: FeatureViewState,
eventHandler: (FeatureEvent) -> Unit
) {
// Only layout and viewState rendering
Column(modifier = Modifier.fillMaxSize()) {
when (viewState) {
is FeatureViewState.Loading -> LoadingContent()
is FeatureViewState.Success -> SuccessContent(
data = viewState.data,
onItemClick = { eventHandler(FeatureEvent.ItemClicked(it)) }
)
is FeatureViewState.Error -> ErrorContent(
message = viewState.message,
onRetry = { eventHandler(FeatureEvent.Retry) }
)
}
}
}
```
### View Rules
- Only layout code
- Only work with viewState
- Only call eventHandler
- **NO** logic
- **NO** remember
- **NO** side effects
- **NO** previews in production code
### UI Guidelines
- Maximum nesting depth: **3 levels**
- Spacing: multiples of **8/16/24** dp
- Use theme: `AppTheme.colors`, `AppTheme.typography`
- Use theme icons consistently
- Extract to `common/ui/` if used in **5+ places**
## Component Layer
**File**: `<FeatureName>Component.kt`
```kotlin
interface FeatureComponent {
val viewState: Value<FeatureViewState>
fun obtainEvent(event: FeatureEvent)
}
// @AssistedInject — required whenever any constructor parameter is @Assisted.
// Plain @Inject would fail at compile time with "missing binding for ComponentContext".
@AssistedInject
class DefaultFeatureComponent(
private val getDataUseCase: GetDataUseCase,
@Assisted componentContext: ComponentContext,
@Assisted private val onNavigate: (String) -> Unit,
) : FeatureComponent, ComponentContext by componentContext {
private val _viewState = MutableValue<FeatureViewState>(FeatureViewState.Loading)
override val viewState: Value<FeatureViewState> = _viewState
private val scope = componentScope()
init { loadData() }
override fun obtainEvent(event: FeatureEvent) {
when (event) {
is FeatureEvent.ItemClicked -> onNavigate(event.itemId)
is FeatureEvent.Retry -> loadData()
}
}
private fun loadData() {
scope.launch {
_viewState.value = FeatureViewState.Loading
getDataUseCase.execute()
.onSuccess { _viewState.value = FeatureViewState.Success(it) }
.onError { msg, _ -> _viewState.value = FeatureViewState.Error(msg) }
}
}
@AssistedFactory
interface Factory {
operator fun invoke(
componentContext: ComponentContext,
onNavigate: (String) -> Unit,
): DefaultFeatureComponent
}
}
```
### Component Rules
- **Single source of logic**
- Stores state (`Value<T>` from Decompose)
- Handles all events
- Executes use cases
- Manages lifecycle
- Navigation **ONLY** through Decompose:
- `StackNavigation` / `childStack`
- `SlotNavigation` / `childSlot`
### Component Dependencies
Allowed:
- Use cases
- Repositories (indirectly via use cases)
- Platform drivers (via DI)
Forbidden:
- Direct data source access
- UI imports (Compose)
## Use Case Layer
**File**: `<FeatureName><Action>UseCase.kt`
Project-defined `AppResult<T>` (NOT `kotlin.Result`) — carries explicit message + cause for UI surfacing:
```kotlin
// common/result/AppResult.kt
sealed class AppResult<out T> {
data class Success<T>(val value: T) : AppResult<T>()
data class Failure(val message: String, val cause: Throwable? = null) : AppResult<Nothing>()
}
inline fun <T> AppResult<T>.onSuccess(block: (T) -> Unit): AppResult<T> {
if (this is AppResult.Success) block(value); return this
}
inline fun <T> AppResult<T>.onError(block: (String, Throwable?) -> Unit): AppResult<T> {
if (this is AppResult.Failure) block(message, cause); return this
}
```
```kotlin
@Inject
class GetFeatureDataUseCase(
private val repository: FeatureRepository
) {
suspend fun execute(params: Params): AppResult<FeatureData> {
return try {
AppResult.Success(repository.getData(params.id))
} catch (e: Exception) {
AppResult.Failure(e.message ?: "Unknown error", e)
}
}
}
```
### Use Case Rules
- **One class per file**
- Returns only `AppResult<T>`
- Single `execute(params): AppResult<T>` function
- **NOT** an operator function
- All error handling happens here
- Dependencies:
- Repository
- TokenManager (if needed)
- Platform drivers (if needed)
- Other UseCases (rarely, for reuse)
## Repository Layer
**File**: `<FeatureName>Repository.kt`
```kotlin
@Inject
class FeatureRepository(
private val localDataSource: FeatureLocalDataSource,
private val remoteDataSource: FeatureRemoteDataSource
) {
suspend fun getData(id: String): FeatureData {
return try {
remoteDataSource.fetch(id)
} catch (e: Exception) {
localDataSource.get(id) ?: throw e
}
}
suspend fun saveData(data: FeatureData) {
localDataSource.save(data)
remoteDataSource.sync(data)
}
}
```
### Repository Rules
- **Concrete class** (no interfaces needed for internal repos)
- Dependencies: only DataSources
- Returns clean data
- Coordinates local/remote sources
## DataSource Layer
**Files**:
- `<FeatureName>LocalDataSource.kt`
- `<FeatureName>RemoteDataSource.kt`
```kotlin
@Inject
class FeatureLocalDataSource(
private val database: AppDatabase
) {
suspend fun get(id: String): FeatureData? {
return database.featureDao().getById(id)?.toDomain()
}
suspend fun save(data: FeatureData) {
database.featureDao().insert(data.toEntity())
}
}
@Inject
class FeatureRemoteDataSource(
private val apiClient: ApiClient
) {
suspend fun fetch(id: String): FeatureData {
return apiClient.get("/features/$id").body<FeatureDto>().toDomain()
}
}
```
### DataSource Rules
- Simple provider pattern
- Dependencies:
- Local storage (Room, DataStore)
- Platform APIs
- Network client (Ktor)
**KMP HTTP client**: in `commonMain` DataSources use **Ktor `HttpClient`** — cross-platform. **OkHttp is JVM-only** — only acceptable in `jvmMain`/`androidMain` source sets. Don't reference `OkHttpClient` from `commonMain`.
## ViewState and Events
**File**: `<FeatureName>ViewState.kt`
Canonical 3-state template — fits **read-mostly** screens (lists, details, dashboards):
```kotlin
sealed class FeatureViewState {
data object LoaRelated in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.