frontend-architecture
Skill này làm gì
Skill này chỉ cho AI của bạn cách tách mã frontend để mỗi file chỉ có một nhiệm vụ. Nó bao gồm các dự án React, Next và Vue. Dành cho lập trình viên muốn mã gọn gàng khi dự án lớn lên.
Khi nào nên dùng
- ✓Khi bạn bắt đầu một dự án React, Next hoặc Vue mới và cần cấu trúc gọn gàng.
- ✓Khi các file frontend của bạn trộn lẫn hiển thị, lấy dữ liệu và kiểm tra.
- ✓Khi một file component đã quá lớn và bạn muốn tách nó theo trách nhiệm.
Liên kết skill
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/frontend-architecture/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tổ chức lại ứng dụng React của tôi để các lời gọi API, phần kiểm tra và mã hiển thị nằm trong các file riêng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill giải thích loại mã nào thuộc tầng nào, như hiển thị, logic, dữ liệu và kiểu. AI áp dụng các quy tắc đó khi tạo hoặc thay đổi file.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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.
Câu hỏi thường gặp
Nó có quyết định tên thư mục không?
Không. Skill nói rằng cách bố trí thư mục theo hướng dẫn scaffolding của dự án, còn nó tập trung vào việc mã thuộc tầng nào.
Nó có bao gồm thiết kế hình ảnh không?
Không. Nó bao gồm cấu trúc mã, còn thiết kế hình ảnh do một skill riêng đảm nhiệm.
Có giới hạn kích thước file nghiêm ngặt không?
Không. Kích thước file được xem là tín hiệu, không phải giới hạn cứng.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 8.2k
- Vị trí xếp hạng
- #12532
- Giấy phép
- MIT
- Cập nhật
- 18/10/2026
Bình luận
- …
Thêm skill từ kho mã này
batch-operations
8.2kGiúp agent của bạn thực hiện cùng một thay đổi trên nhiều file cùng lúc, như đổi tên một hàm hoặc thay một import cũ ở khắp nơi.
brainstorming
8.2kDạy agent của bạn đặt câu hỏi làm rõ trước khi xây dựng bất cứ thứ gì mới hoặc phức tạp, để agent hiểu mục tiêu của bạn trước.
code-review-checklist
8.2kCung cấp cho agent của bạn một danh sách kiểm tra để rà soát mã về tính đúng đắn, bảo mật, hiệu năng, kiểm thử và tài liệu, kể cả rủi ro riêng của AI.
code-review-graph
8.2kGiúp agent của bạn rà soát mã trong dự án lớn bằng một bản đồ cấu trúc, để nó chỉ đọc các file bị ảnh hưởng bởi một thay đổi.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.