android-architecture
Defines project structure, package layout, layer boundaries, naming conventions, and dependency injection setup for Android projects. Use this skill whenever creating a new Android project, adding a new feature module, scaffolding a new screen or flow, setting up DI bindings, naming any class or file, or deciding which layer a piece of code belongs in. Also use it when reviewing or refactoring existing code to ensure it follows the established architecture.
- License 许可
- MIT
- 最近更新
- 2026-10-31
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- android-architecture
- license
- MIT
- description
- Defines project structure, package layout, layer boundaries, naming conventions, and dependency injection setup for Android projects. Use this skill whenever creating a new Android project, adding a new feature module, scaffolding a new screen or flow, setting up DI bindings, naming any class or file, or deciding which layer a piece of code belongs in. Also use it when reviewing or refactoring existing code to ensure it follows the established architecture.
03 SKILL.md 正文
Android Architecture
Use this skill to keep Android projects consistent, scalable, and easy to navigate.
1. Core architecture rules
Follow Clean Architecture inspired layering:
domainis the business core.datahandles remote, local, and other external data sources.presentationcoordinates state and mapping for the UI.uicontains Compose screens, reusable components, and theme.dicontains dependency injection modules.
Dependency flow always points inward:
ui -> presentation -> domain <- data
Rules:
domainmust not depend on Android, Compose, Retrofit, database, or DI APIs.presentationmust not depend on Retrofit, Room, or DTOs.datamay depend ondomain, not the other way around.uimust stay focused on rendering and user interaction.- Keep business rules out of UI and Android framework classes.
2. Recommended project structure
Prefer a feature-first layout with shared infrastructure only where it truly belongs.
com.company.app/
├── AppApplication.kt
├── MainActivity.kt
│
├── di/
│ ├── NetworkModule.kt
│ ├── DatabaseModule.kt
│ ├── RepositoryModule.kt
│ └── DispatcherModule.kt
│
├── domain/
│ ├── model/
│ ├── repository/
│ └── usecase/
│
├── data/
│ ├── api/
│ │ └── model/
│ ├── datasource/
│ ├── mapper/
│ └── repository/
│
├── presentation/
│ ├── <feature>/
│ │ ├── <Feature>ViewModel.kt
│ │ ├── model/
│ │ ├── mapper/
│
└── ui/
├── <feature>/
│ ├── <Feature>Screen.kt
│ ├── components/
└── theme/
Rules:
- Keep each feature self-contained.
- Place shared abstractions in the lowest common layer possible.
- Avoid large folders full of unrelated classes.
- Avoid creating
utilsorhelpersfolders as a dumping ground.
3. Layer responsibilities
domain
Contains only pure Kotlin code.
Typical contents:
- entities and value objects
- repository interfaces
- use cases
- domain errors
- domain calculators when the logic is reusable and not UI-specific
data
Handles anything outside the app process or outside the pure domain model.
Typical contents:
- Retrofit APIs
- DTOs and network models
- local datasource implementations
- mappers between external models and domain models
- repository implementations
- caching, persistence, synchronization logic
presentation
Owns screen behavior and state orchestration.
Typical contents:
- ViewModels
- screen UiState, UiAction, UiEvent
- input state and internal state models
- pure calculators, parsers, and mappers used only by the screen flow
ui
Owns rendering.
Typical contents:
- Screen composables
- stateless content composables
- reusable UI components
- theme, typography, colors, shapes, previews
di
Owns object graph wiring only.
Typical contents:
- bindings
- providers
- qualifiers
- module objects and abstract modules
4. Naming conventions
Use explicit and consistent names.
Common patterns
- ViewModel:
[Feature]ViewModel - Screen:
[Feature]Screen - Screen state:
[Feature]ScreenUiState - Content state:
[Feature]UiState - Actions:
[Feature]UiAction - Events:
[Feature]UiEvent - Repository interface:
[Feature]Repository - Repository implementation:
[Feature]RepositoryImpl - Use case:
[Verb][Subject]UseCase - Mapper:
[Source]Mapperor[Target]Mapper - Parser:
[Type]Parser - Provider:
[Name]Provider - DTO:
[Entity]Dto
Examples:
ObserveRateForCurrenciesUseCaseExchangeViewModelExchangeScreenUiStateExchangeRepositoryImplCurrencyMapperAmountParser
Rules:
- Prefer names that reveal responsibility immediately.
- Do not use vague names such as
Manager,Helper,Processor, orUtils. - Use
internalby default for implementation classes. - Keep file names aligned with class names.
5. Visibility rules
Use the narrowest visibility that still works.
Default rules:
internalfor most app implementation classes- package-private or public only when needed for module boundaries
publiconly for intended shared APIsprivatefor local helpers and implementation details
Practical guidance:
- ViewModels should usually be
internal. - Use cases should usually be
internal. - repository implementations should usually be
internal. - Compose screen and content functions should usually be
internalorprivateif only used locally. - Expose only the minimum needed surface area.
6. Dependency injection
Use Hilt with constructor injection.
Preferred pattern:
@HiltViewModel
internal class ExampleViewModel @Inject constructor(
private val repository: ExampleRepository,
) : ViewModel()
Rules:
- Prefer constructor injection everywhere.
- Use
@Bindsfor interface to implementation bindings. - Use
@Providesfor objects that need construction logic. - Keep all modules in
di/. - Separate modules by concern.
- Use
javax.inject.Inject.
Common module types:
- repository bindings
- network setup
- database setup
- dispatcher providers
- feature specific object providers
Do not use:
- service locators
- manual singleton containers
- global mutable dependency access
jakarta.inject.Inject
7. Android entry points
Recommended app entry points:
Applicationannotated with@HiltAndroidApp- single
MainActivityannotated with@AndroidEntryPoint
Prefer:
- one activity architecture
- Compose Navigation for routing
- no fragments for new work unless a specific legacy constraint requires them
8. Module and package boundaries
When adding a new feature:
- Define the feature boundary first.
- Create domain contracts.
- Add data implementations.
- Add presentation state and logic.
- Add UI composables.
- Wire everything in
di.
When moving code:
- move pure business rules down to
domain - move external data handling to
data - move screen orchestration to
presentation - keep rendering in
ui
9. Code review checklist
A piece of code belongs in the correct place only if:
- its dependencies point in the right direction
- its responsibility is clear
- the layer contains only concerns allowed by that layer
- its name matches its role
- the code can be tested in isolation
- the implementation does not leak framework details into lower layers
Refactor when:
- a ViewModel contains parsing or formatting logic that belongs elsewhere
- a repository returns DTOs instead of domain models
- UI code performs business calculations
- a module mixes unrelated responsibilities
- naming does not make the feature easy to understand
10. Practical decision rules
Use this skill when deciding where code belongs.
- Business rule with no UI dependency:
domain - Network or persistence logic:
data - Screen orchestration or state transformation:
presentation - Compose rendering:
ui - Dependency wiring:
di
When uncertain, choose the lowest layer that can own the logic without leaking framework concerns upward.
04 同仓库更多 Skills
security-review
Security code review for vulnerabilities. Use when asked to "security review", "find vulnerabilities", "check for security issues", "audit security", "OWASP review", or review code for injection, XSS, authentication, authorization, cryptography issues. Provides systematic review with confidence-based reporting.
security-model
Define, review, or update SECURITY_MODEL.md files that tell security review tools a repository's threat model, trust boundaries, invariants, reportable finding classes, and exclusions. Use when asked to "write a security model", "threat model this repo for scanners", "define security review scope", "what counts as a vulnerability here", "update SECURITY_MODEL.md", "why did the scanner flag or miss this", or to check whether existing security guidance still matches the code. Not for running a security review or editing the SECURITY.md disclosure policy.
mobile-harness
Portable Android and iOS device-control harness for agents. Use when an agent needs to control or automate Android/iOS devices — tap, swipe, screenshot, app control — locally (ADB/Portal/Simulator) or on Mobilerun cloud devices.
compose-agent
Helps AI coding assistants write modern Jetpack Compose: correct state, side effects, performance-aware modifiers, Navigation 3, Paging 3 in Compose, coroutines on lifecycle, animations, UI tests, focus/keyboard navigation, Compose Multiplatform boundaries, idiomatic Kotlin, and well-shaped composable APIs. Targets the mistakes LLMs actually make in Compose code. Use when reading, writing, or reviewing Compose projects.
material-design-3-ui
Design, redesign, review, or implement user interfaces using Google Material Design 3 (M3), Material You, and optional Material 3 Expressive principles. Use for UI/UX screens, app flows, design systems, component selection, theming, responsive/adaptive layouts, accessibility audits, Figma-ready specifications, or developer handoff where Material Design 3 is required.
web-design-guidelines
Web platform design and accessibility guidelines. Use when building web interfaces, auditing accessibility, implementing responsive layouts, or reviewing web UI code. Triggers on tasks involving HTML, CSS, web components, WCAG compliance, responsive design, or web performance.