api-and-interface-design
하는 일
사용하기 쉽고 잘못 사용하기 어려운 인터페이스(API나 프로그램 부분 사이의 계약)를 만드는 방법을 안내합니다. 소프트웨어 부분들이 명확하고 안정적으로 통신하도록 정의하는 법을 가르칩니다.
사용하는 경우
- ✓프로그램 사이의 새 연결(API)을 만들 때.
- ✓같은 프로그램의 서로 다른 부분이 통신하는 방식을 정의할 때.
- ✓프로그램이 사용자와 상호작용하는 방식(그래픽 인터페이스)을 계획할 때.
스킬 링크
https://github.com/addyosmani/agent-skills/blob/main/skills/api-and-interface-design/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“시스템에서 사용자가 제목과 설명을 지정해 새 작업을 만드는 방법을 정의하도록 도와주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
통신 방식('계약')을 코드를 쓰기 전에 먼저 정의하는 것으로 작동합니다. 이렇게 하면 모두가 규칙을 이해하고 예기치 않은 일을 피할 수 있습니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
API and Interface Design
Overview
Design stable, well-documented interfaces that are hard to misuse. Good interfaces make the right thing easy and the wrong thing hard. This applies to REST APIs, GraphQL schemas, module boundaries, component props, and any surface where one piece of code talks to another.
When to Use
- Designing new API endpoints
- Defining module boundaries or contracts between teams
- Creating component prop interfaces
- Establishing database schema that informs API shape
- Changing existing public interfaces
Core Principles
Hyrum's Law
With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody, regardless of what you promise in the contract.
This means: every public behavior — including undocumented quirks, error message text, timing, and ordering — becomes a de facto contract once users depend on it. Design implications:
- Be intentional about what you expose. Every observable behavior is a potential commitment.
- Don't leak implementation details. If users can observe it, they will depend on it.
- Plan for deprecation at design time. See
deprecation-and-migrationfor how to safely remove things users depend on. - Tests are not enough. Even with perfect contract tests, Hyrum's Law means "safe" changes can break real users who depend on undocumented behavior.
The One-Version Rule
Avoid forcing consumers to choose between multiple versions of the same dependency or API. Diamond dependency problems arise when different consumers need different versions of the same thing. Design for a world where only one version exists at a time — extend rather than fork.
1. Contract First
Define the interface before implementing it. The contract is the spec — implementation follows.
// Define the contract first
interface TaskAPI {
// Creates a task and returns the created task with server-generated fields
createTask(input: CreateTaskInput): Promise<Task>;
// Returns paginated tasks matching filters
listTasks(params: ListTasksParams): Promise<PaginatedResult<Task>>;
// Returns a single task or throws NotFoundError
getTask(id: string): Promise<Task>;
// Partial update — only provided fields change
updateTask(id: string, input: UpdateTaskInput): Promise<Task>;
// Idempotent delete — succeeds even if already deleted
deleteTask(id: string): Promise<void>;
}
2. Consistent Error Semantics
Pick one error strategy and use it everywhere:
// REST: HTTP status codes + structured error body
// Every error response follows the same shape
interface APIError {
error: {
code: string; // Machine-readable: "VALIDATION_ERROR"
message: string; // Human-readable: "Email is required"
details?: unknown; // Additional context when helpful
};
}
// Status code mapping
// 400 → Client sent invalid data
// 401 → Not authenticated
// 403 → Authenticated but not authorized
// 404 → Resource not found
// 409 → Conflict (duplicate, version mismatch)
// 422 → Validation failed (semantically invalid)
// 500 → Server error (never expose internal details)
Don't mix patterns. If some endpoints throw, others return null, and others return { error } — the consumer can't predict behavior.
3. Validate at Boundaries
Trust internal code. Validate at system edges where external input enters:
// Validate at the API boundary
app.post('/api/tasks', async (req, res) => {
const result = CreateTaskSchema.safeParse(req.body);
if (!result.success) {
return res.status(422).json({
error: {
code: 'VALIDATION_ERROR',
message: 'Invalid task data',
details: result.error.flatten(),
},
});
}
// After validation, internal code trusts the types
const task = await taskService.create(result.data);
return res.status(201).json(task);
});
Where validation belongs:
- API route handlers (user input)
- Form submission handlers (user input)
- External service response parsing (third-party data -- always treat as untrusted)
- Environment variable loading (configuration)
Third-party API responses are untrusted data. Validate their shape and content before using them in any logic, rendering, or decision-making. A compromised or misbehaving external service can return unexpected types, malicious content, or instruction-like text.
Where validation does NOT belong:
…
자주 묻는 질문
API란 무엇인가요?
API는 식당 메뉴와 같습니다. 무엇을 주문할 수 있는지(기능)와 어떻게 주문하는지(매개변수)를 정하지만, 주방(프로그램)이 요리를 어떻게 만드는지는 알 필요가 없습니다.
'계약 우선(contract first)'이 왜 중요한가요?
게임을 시작하기 전에 규칙에 합의하는 것과 같습니다. 모두가 규칙(계약)을 알면 게임(프로그램)이 더 잘 흘러가고 충돌을 피할 수 있습니다.
'Hyrum의 법칙(Hyrum's Law)'이란 무엇인가요?
많은 사람이 무언가를 사용하면, 의도하지 않은 동작이나 세부 사항까지 결국 의존하게 된다는 생각입니다. 그래서 무엇을 공개할지 신중해야 합니다.
상세 정보
작성자의 원본 설명
Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.
repo: addyosmani/agent-skills
인기도
- GitHub 스타
- 107k
- 순위
- #761
- 라이선스
- MIT
- 업데이트
- 2026. 10. 13.
댓글
- …
이 저장소의 다른 스킬
browser-testing-with-devtools
107k에이전트가 실제 브라우저에서 코드를 직접 테스트하도록 돕습니다. 사용 환경에서 어떻게 작동하는지 확인하고, 오류와 성능 문제를 찾는 데 유용합니다.
ci-cd-and-automation
107k반복 작업을 자동화하고, 프로젝트를 배포하며, 인프라를 관리하도록 에이전트에게 가르칩니다.
code-review-and-quality
107k여러 측면에서 상세한 코드 검토를 수행합니다. 새 변경 사항을 병합하기 전에 품질을 확인하고 향후 문제를 막는 데 유용합니다.
code-simplification
107k코드를 이해하고 유지보수하기 쉽도록 단순화합니다. 코드는 작동하지만 너무 복잡할 때 명확성을 높이는 데 유용합니다.
비슷한 스킬
api-connector-builder
280k에이전트가 기존 패턴을 따라 새로운 API 연결을 만들도록 합니다. 새로운 방식을 도입하지 않고 연동을 하나 더 추가할 때 씁니다.
api-design
280k에이전트가 모범 사례에 따라 REST API를 설계하도록 돕습니다. API가 통신하는 방식, 오류를 보여 주는 방식, 데이터를 정리하는 방식을 정하는 데 유용합니다.
backend-patterns
280k에이전트가 서버 쪽 아키텍처 패턴과 데이터베이스 최적화를 다루도록 돕습니다. 서버에서 실행되는 코드를 만들거나 검토할 때 유용합니다.