guillemroca/agent-skills-android/api-and-interface-design
Claude Code and agent skill by guillemroca/agent-skills-android
- community
Checking that the SKILL.md file is still in the repository.
Use when designing interfaces between layers (Repository, UseCase, API client) or defining data contracts. Covers Retrofit interfaces, Room DAOs, Kotlin sealed classes, backward compatibility, and idempotency keys for safely retried writes.
Install
npx vskill@latest install guillemroca/agent-skills-android/api-and-interface-designSKILL.md
The same SKILL.md was published earlier as guillemroca/agent-skills-android/api-and-interface-design.
API and Interface Design
Overview
Hyrum's Law: "With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody." Design interfaces — Repository contracts, UseCase signatures, Retrofit services, Room DAOs — as deliberate contracts. Everything observable becomes a dependency.
When to Use
- Defining a new Repository interface
- Creating Retrofit API service interfaces
- Designing Room DAOs
- Defining ViewModel ↔ UI contracts (UiState, Events)
- Changing any public interface in a shared module
- Designing inter-module contracts in multi-module projects
- Sending state-changing requests that can be retried (payments, orders, messages, uploads)
Skip when: Modifying internal (private) implementation details.
Core Process
Step 1: Contract-First Design
- Define the interface before implementing:
- Design principles:
- Return
Flowfor observable data (notsuspendfor single reads) - Use
suspendfor one-shot operations - Accept domain types, not framework types (no
Entityin interfaces) - Throw domain-specific exceptions, not framework exceptions
Step 2: Retrofit Interfaces
- Define clean API contracts:
- API contract rules:
- Use
@Serializabledata classes for request/response bodies (Kotlin Serialization) - Separate request and response models (even if fields overlap)
- Use
sealed classfor polymorphic responses - Never expose Retrofit internals (no
Response<T>in Repository interface)
Step 3: Data Models and Sealed Types
- Use the type system to make illegal states unrepresentable:
- Use value classes for type safety:
Step 4: Error Handling Strategy
- Define domain-specific errors:
- Error handling rules:
- Catch specific exceptions, not generic
Exception - Map framework exceptions to domain errors at the boundary
- Never swallow errors silently
- Provide actionable error messages for the UI
Step 5: Backward Compatibility
- Extend, don't modify:
- When breaking changes are necessary:
- Deprecate with
@Deprecatedand replacement guidance - Provide a migration period
- Update all callers in the same PR
- See
deprecation-and-migrationfor the full process
Step 6: Naming Conventions
| Element | Convention | Example | |
|---|---|---|---|
| Repository | get*, observe*, create*, update*, delete* | getTaskById() | |
| UseCase | Verb phrase, operator fun invoke() | GetTasksUseCase() | |
| Retrofit | HTTP-verb aligned | @GET, @POST, @PUT, @DELETE | |
| Room DAO | observe* for Flow, get* for suspend | observeAll(), getById() | |
| UiState | Sealed interface per screen | TaskListUiState.Success | |
| Events | Past-tense or imperative | TaskClicked, DeleteTask | |
| Request/Response | Suffixed | CreateTaskRequest, TaskResponse |
Step 7: Validation at Boundaries
- Validate at system boundaries, trust internally:
Step 8: Idempotency Keys for Retried Writes
- Assume every write is sent more than once. On Android, duplicates come from OkHttp's
retryOnConnectionFailure, caller retry loops, WorkManager retries with backoff, double-taps, and process death between sending a request and persisting the response. A timeout means unknown, not failed — the server may already have applied it. For non-idempotent writes (POSTthat charges, orders, sends), attach anIdempotency-Key.
Key the intent, not the attempt. Generate a UUID once when the user commits the action, persist it with the pending operation (Room outbox row or WorkManager inputData), and reuse it on every retry — including after process death:
- Never generate the key inside an OkHttp interceptor, the Retrofit call, or
doWork()— that layer runs once per attempt. If you prefer an interceptor over@Header, pass the stored key via a Retrofit@Tagand read it withrequest.tag(). - Don't derive the key from content (
"$userId:$amount") — two legitimate identical orders would collapse into one.
Know the server contract (usually another team's): it stores key + request fingerprint + response, replays the stored response for a repeat, rejects the same key with a different body (422, sometimes 409), returns 409 while the first attempt is still in flight, and expires keys after a window. Client consequences: treat a replayed response as success, retry an in-flight 409 with backoff, treat a body-mismatch error as a client bug (never "fix" it with a new key), and keep the outbox retry horizon shorter than the server's key expiry.
Common Rationalizations
| Shortcut | Why It Fails | |
|---|---|---|
| "I'll define the interface from the implementation" | Implementation leaks into the contract. Design the contract first. | |
| "One model for all layers is simpler" | Coupling DB schema to API to UI makes all three brittle. | |
| "Strings are fine for types" | Strings allow typos, have no exhaustiveness checking, and no IDE support. | |
| "We don't need backward compatibility yet" | By the time you need it, you have callers you can't easily find. | |
| "Duplicate requests are rare" | They're correlated with bad networks and degraded backends — exactly when retries spike and duplicates cost most. | |
| "A new key per retry is fine, the server dedupes" | The server dedupes by key. A fresh key per attempt is a fresh charge per attempt. | |
| "The key can live in memory" | Process death mid-request is routine on Android. A key that isn't persisted with the operation is lost exactly when a retry is needed. |
Red Flags
- Room entities exposed to UI layer
- Retrofit
Response<T>returned from Repository - Generic
Stringwhere sealed type or enum is appropriate - No validation at system boundaries
- Breaking interface changes without deprecation
AnyorObjectin public interfaces- Inconsistent naming across layers
- Non-idempotent
POST(payment, order, message) retried without anIdempotency-Key UUID.randomUUID()for the key inside an interceptor, API call, ordoWork()- Idempotency key held only in memory or a ViewModel, not persisted with the pending operation
- A
409/422on a keyed request "handled" by retrying with a new key
Verification
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/api-and-interface-design/SKILL.md
Popularity
- Repository stars
- 2
- 7-day trend score
- 5
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/guillemroca/agent-skills-android/api-and-interface-design)