frontend-architecture
Fungsinya
Skill ini menunjukkan kepada AI Anda cara memecah kode frontend sehingga setiap berkas memiliki satu tugas. Skill ini mencakup proyek React, Next, dan Vue. Skill ini untuk pengembang yang ingin kodenya tetap rapi seiring pertumbuhannya.
Kapan dipakai
- βSaat Anda memulai proyek React, Next, atau Vue baru dan memerlukan struktur yang rapi.
- βSaat berkas frontend Anda mencampur tampilan, pengambilan data, dan validasi.
- βSaat sebuah berkas komponen sudah terlalu besar dan Anda ingin memecahnya berdasarkan tanggung jawab.
Link skill
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/frontend-architecture/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
βAtur ulang aplikasi React saya agar panggilan API, validasi, dan kode tampilan berada di berkas yang terpisah.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menjelaskan jenis kode mana yang termasuk ke lapisan mana, seperti tampilan, logika, data, dan tipe. AI menerapkan aturan itu saat membuat atau mengubah berkas.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Frontend Architecture
How to organize frontend code so it scales. Separation of concerns over file-type folders. Applies to React/Next and Vue. For directory layout, follow app-builder. For visual design, see frontend-design. For React/Next performance, see nextjs-react-expert.
1. Separation of Concerns β the core rule
Split code into four layers by responsibility. A unit of code does ONE of these, not several:
| Layer | Holds | Lives in |
|---|---|---|
| UI | Rendering, markup, presentational state | components/ |
| Logic | State, effects, data transforms, reusable UI logic | hooks/ (React) Β· composables/ (Vue) |
| Data | API calls, fetch/axios, cache keys | lib/ / service files (*.api.ts) |
| Type | TypeScript types, domain models | types.ts / *.types.ts |
| Validation | Form/data schemas | *.schema.ts (zod/yup/valibot) |
Directory layout (top-level folders) follows the project's scaffolding skill β do not invent a competing structure here. This skill is about which layer code belongs to, not where the folders sit.
2. File Responsibility & Size
One clear responsibility per file. Size is a signal, not a hard limit β a clear 230-line file beats a 90-line file that fetches, validates, renders, and juggles modals + toasts.
| File type | Comfortable range |
|---|---|
| UI component | 80β180 lines |
| Page / screen | 100β220 lines |
| Hook / composable | 40β150 lines |
| API service | 50β200 lines |
| Type / schema | flexible |
Split a file when it mixes UI + API + business logic + validation + state. Don't split a coherent file just to hit a number.
3. Components render UI; logic goes elsewhere
Components should primarily render. Push fetching/state/transforms into a hook or composable.
// β Component owns the data layer
function ProductList() {
const [products, setProducts] = useState([])
useEffect(() => { fetch('/api/products').then(r => r.json()).then(setProducts) }, [])
return <div>{/* render */}</div>
}
// β
Component renders; logic lives in a hook
function ProductList() {
const { products, isLoading } = useProducts()
if (isLoading) return <Loading />
return <div>{/* render */}</div>
}
- Custom hooks must start with
use. - A component calling an API directly is acceptable only for the smallest one-off cases.
4. Next.js β Server Components by default
In the App Router, page.tsx and layout.tsx are Server Components. Reach for "use client" only when you actually need the client.
| Server Component | Client Component |
|---|---|
| Fetch data, read DB/API | Form, modal, dropdown |
| Handle secret tokens | Event handlers, animation |
| Render static/semi-static layout | useState/useEffect, browser APIs (window, localStorage) |
Keep client components small. Don't "use client" a whole page for one interactive button β extract the button into its own client component and keep the page a Server Component.
5. Vue β Composition API + composables
For full production apps, prefer the Composition API with <script setup> Single File Components. (Options API is fine for simple cases / progressive enhancement.)
components/β UIcomposables/β reusable pure logic (useX)- service files β API calls
Use a composable for reusable pure logic; use a component when reusing both logic and layout.
6. State β start local, escalate only when needed
| Need | Use |
|---|---|
| Component-internal state | useState / ref |
| Reusable state/logic in one feature | custom hook / composable |
| Shared UI state in a subtree | Context (React) / provide-inject (Vue) |
| Cross-app, complex, persisted | Zustand / Pinia / Redux |
| Server state / API cache | TanStack Query (react-query) / similar |
Don't reach for global state (or Redux) on day one of a small app. Server state belongs in a query library, not a global store.
7. API in service files
Never scatter raw fetch/axios across components.
// user.api.ts
export async function getUsers() {
const res = await http.get('/users')
return res.data
}
// useUsers.ts
export function useUsers() {
return useQuery({ queryKey: ['users'], queryFn: getUsers })
}
Always handle loading, error, and empty states explicitly.
8.
Pertanyaan umum
Apakah ini menentukan nama folder?
Tidak. Skill menyatakan bahwa tata letak folder mengikuti panduan scaffolding proyek, dan skill berfokus pada lapisan tempat kode berada.
Apakah ini mencakup desain visual?
Tidak. Ini mencakup struktur kode, sedangkan desain visual ditangani skill terpisah.
Apakah ada batas ukuran berkas yang ketat?
Tidak. Ukuran berkas dianggap sebagai sinyal, bukan batas keras.
Detail
Deskripsi asli dari pembuat
How to organize frontend code β separation of concerns (UI / logic / data / type), file responsibility, state tiers, API services, schema validation, and framework conventions for React/Next and Vue. Structural rules, not visual design.
repo: vudovn/ag-kit
Popularitas
- Bintang GitHub
- 8.2k
- Peringkat
- #12532
- Lisensi
- MIT
- Diperbarui
- 18/10/2026
Komentar
- β¦
Skill lain dari repositori ini
batch-operations
8.2kMembantu agent Anda membuat perubahan yang sama di banyak berkas sekaligus, misalnya mengganti nama fungsi atau mengganti impor lama di semua tempat.
brainstorming
8.2kMengajari agent Anda untuk mengajukan pertanyaan klarifikasi sebelum membangun sesuatu yang baru atau rumit, agar ia memahami tujuan Anda terlebih dahulu.
code-review-checklist
8.2kMemberi agent Anda daftar periksa untuk meninjau kode dari sisi kebenaran, keamanan, performa, pengujian, dan dokumentasi, termasuk risiko khusus AI.
code-review-graph
8.2kMembantu agent Anda meninjau kode dalam proyek besar dengan peta struktural, sehingga ia hanya membaca berkas yang terdampak oleh perubahan.
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.