# Skill Layer — API Only

File ini berisi konteks dan asumsi default untuk project bertipe **API only** — backend service, microservice, atau platform API tanpa frontend signifikan.

---

## Kapan Pakai Skill Ini

Gunakan jika project Anda adalah:
- REST API atau GraphQL API yang dikonsumsi oleh frontend atau third-party
- Microservice dalam arsitektur yang lebih besar
- Platform API yang akan dipakai developer lain
- Backend service untuk mobile app atau multiple client

---

## Asumsi Default yang Langsung Diterapkan

### API Design
- REST API dengan JSON response (default)
- GraphQL hanya jika ada kebutuhan flexible querying atau multiple client dengan kebutuhan data berbeda
- API versioning dari awal: `/api/v1/` di semua endpoint
- Consistent response envelope:
```json
{
  "success": true,
  "data": {},
  "meta": {},
  "error": null
}
```
- Pagination: cursor-based untuk list yang besar, offset-based untuk yang sederhana

### Auth
- API Key untuk server-to-server (machine client)
- OAuth 2.0 Client Credentials untuk service-to-service
- JWT Bearer token untuk user-facing API
- Rate limiting per API key dan per IP

### Documentation
- OpenAPI 3.0 spec wajib — documentation-first approach
- Swagger UI atau Redoc untuk interactive docs
- Changelog API yang dikelola dengan baik
- Versioning policy yang jelas (deprecation timeline)

### Performance
- Response time target: < 200ms untuk operasi sederhana
- Database query optimization dari awal
- Caching layer (Redis) untuk resource yang sering dibaca
- Database connection pooling

### Reliability
- Health check endpoint: `GET /health` (status, uptime, dependencies)
- Readiness check endpoint: `GET /ready`
- Circuit breaker untuk external service calls
- Retry dengan exponential backoff untuk downstream service

### Observability
- Structured logging dengan request ID per request
- Distributed tracing (jika microservice)
- Metrics: request count, latency, error rate
- Alert untuk error rate spike

### Security
- Rate limiting di semua endpoint
- Input validation dan sanitization
- SQL injection prevention
- CORS configuration yang eksplisit (bukan `*` di production)
- Sensitive data tidak pernah ada di response atau log

---

## Pertanyaan Tambahan untuk Brief API Only

- Siapa yang akan consume API ini? (web frontend, mobile, third-party developer, atau service lain?)
- Apakah ini standalone API atau bagian dari sistem yang lebih besar?
- Berapa estimasi request per detik di peak load?
- Apakah ada SLA yang harus dipenuhi?
- Apakah API ini akan dipublikasikan untuk developer eksternal?

---

## Guardrails Tambahan untuk API Only

- Jangan pernah return data lebih dari yang diminta — principle of least privilege
- Semua endpoint harus punya auth check kecuali health/docs endpoint
- Error response jangan expose stack trace atau internal detail di production
- Perubahan breaking pada API harus di-version dulu, tidak langsung modify existing endpoint
- Jangan buat endpoint yang bisa enumerate resources sensitif (gunakan UUID)
