frontend-data-contracts
Fungsinya
Tool ini membantu memastikan data yang masuk ke aplikasi web atau mobile Anda itu andal dan aman. Tool ini membuat satu gerbang tunggal tempat data diperiksa dan diubah menjadi format yang aman sebelum digunakan.
Kapan dipakai
- βSaat Anda ingin memastikan data yang diterima dari server sudah benar.
- βSaat membangun aplikasi yang membutuhkan keamanan dan keandalan data.
- βUntuk mencegah error yang disebabkan oleh data tak terduga di aplikasi React atau React Native.
Link skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/frontend-data-contracts/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βPeriksa data faktur sebelum menampilkannya di aplikasi.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Caranya dengan menetapkan satu titik masuk untuk semua permintaan data. Di titik ini, data mentah dari internet diubah menjadi format yang aman dan terpercaya, atau sebuah pesan error yang jelas dikembalikan.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Frontend Data Contracts (typed network boundary)
When to Use
Use this skill when you need a portable, framework-agnostic discipline for type safety at the network edge of any React or React Native app. Establishes one typed API client as the single fetch boundary, a parse-don't-validate rule that turns wire JSON into trusted domain types before it enters the app, runtime parsing, normalized errors and branded identifiers.
Portable skill β readable by Claude Code, OpenCode, Codex, Cursor, Windsurf, and others. This skill describes a discipline at the network edge β one client, one envelope, one error type, validated types β not a state library or a styling system. It pairs with the frontend-architecture skill (the client lives in
shared/api-client/) and is the foundation the frontend-optimistic-mutations skill builds on.
The goal: the moment data crosses from the network into the app, it stops being any-shaped wire
JSON and becomes a trusted, typed domain value β or it becomes a single, typed error.
There is exactly one place this transformation happens, and nothing untyped escapes it.
Example contract
The snippets marked βessenceβ are architecture sketches with omitted project dependencies and methods, not a complete client. A generic get<Invoice> type parameter is only a compile-time assertion: it cannot establish runtime validity. Require the actual schema parse before treating a value as an Invoice, normalize parser failures into the project error type, and keep authorization independent of both schema validation and branded IDs. Bind adapter behavior to the installed library version; do not assume an unsupported per-query callback exists.
0. The five core ideas
- One client is the only fetch boundary. A single typed
apiClientwrapsfetch. Components and hooks never callfetch/axiosdirectly β the boundary is enforceable in review and lint. - Parse, don't validate. Wire JSON is parsed into domain types at the boundary. After the client returns, the value is trusted everywhere downstream β no defensive
?.chains, no re-checking shapes in components. - One envelope. Every response is
{ data }on success or{ error }on failure. The client unwrapsdataand throws onerror, so callers receive the payload directly or a typed throw. - One normalized error type. Server error envelope, non-2xx status, malformed body, network failure, and abort all become a single
ApiErrorwith a machine code, status, and optional per-field errors. Callers handle one shape. - Identifiers are branded. Domain IDs are nominal types (
InvoiceId,CustomerId) so the compiler rejects passing one where another is expected β the most common silent bug in data-heavy UIs.
1. Directory layout
The boundary is one folder in shared/ (per the frontend-architecture skill).
src/shared/api-client/
βββ index.ts β barrel: apiClient, ApiError, types
βββ client.ts β the fetch wrapper: buildUrl, headers, parse, verbs
βββ config.ts β base URL resolution, default headers
βββ error.ts β the ApiError class + codeβmessage-key mapping
βββ types.ts β envelope types, HttpMethod, RequestOptions, field errors
βββ client.test.ts β boundary behavior tests (envelope, errors, network)
Domain entity types and their schemas live with their feature module
(modules/{feature}/types/) or a shared contract package; the client is generic over T.
2. One client, the only fetch boundary
Every verb returns the unwrapped data payload typed by the caller, and throws an
ApiError on any failure. Components never see envelopes or raw responses.
// shared/api-client/client.ts (essence)
export const apiClient = {
get<T>(path: string, options?: RequestOptions): Promise<T> {
return request<T>("GET", path, undefined, options);
},
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {
return request<T>("POST", path, body, options);
},
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {
/* β¦ */
},
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {
/* β¦ */
},
delete<T>(path: string, options?: RequestOptions): Promise<T> {
/* β¦ */
},
} as const;
export type ApiClient = typeof apiClient;
// CORRECT β a feature hook wraps the client, typed by the caller
β¦
Pertanyaan umum
Apa maksud 'type safety'?
Artinya kode sudah tahu persis jenis informasi yang diharapkan, misalnya angka, teks, atau tanggal, sehingga mencegah error yang tidak terduga.
Apa itu 'network' atau 'network edge'?
Itu adalah titik tempat data masuk ke aplikasi Anda dari luar, misalnya dari server di internet.
Mengapa disebut 'parse, don't validate'?
Validasi hanya memeriksa apakah data sudah benar, sedangkan 'parsing' mengubah data menjadi format yang aman dan terpercaya sehingga aplikasi dapat menggunakannya dengan aman.
Detail
Deskripsi asli dari pembuat
A portable, framework-agnostic discipline for type safety at the network edge of any React or React Native app.
Popularitas
- Bintang GitHub
- 48k
- Peringkat
- #4663
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- β¦
Skill lain dari repositori ini
00-andruia-consultant
48kMembantu agent Anda memulai atau meningkatkan proyek AI. Agent menganalisis kode, menyarankan tools, dan membuat rencana aksi dalam bahasa Spanyol.
007
48kMemungkinkan agent Anda melakukan audit keamanan dan threat modeling. Berguna untuk melindungi proyek dari serangan dan celah keamanan.
10-andruia-skill-smith
48kMembantu agent Anda membuat atau meningkatkan tools AI. Agent mendefinisikan cara kerja tools, menulis dokumentasi, dan memvalidasi strukturnya.
20-andruia-niche-intelligence
48kMemungkinkan agent Anda membuat ringkasan industri tertentu. Berguna untuk memahami konteks, aturan, pola penggunaan, dan risiko proyek dengan sumber terpercaya.
Skill serupa
angular-developer
280kMembantu agent Anda membuat kode Angular dan memberi saran struktur proyek. Berguna saat memulai proyek baru, membuat komponen, atau meningkatkan performa.
frontend-a11y
280kMembantu agent Anda membuat antarmuka web dapat diakses semua orang. Memastikan website dan aplikasi berfungsi baik dengan screen reader dan navigasi keyboard.
frontend-patterns
280kMembuat agent Anda menerapkan pola modern dalam frontend. Mengoptimalkan performa, mengelola state, dan mengikuti praktik terbaik React dan Next.js.