---
name: react-enterprise-architect
description: React/Next.js enterprise architecture patterns cho GoodGo frontend apps. Use for project structure, component organization, data fetching, routing, và App Router patterns.
compatibility: "next>=16, react>=19, typescript>=5"
metadata:
author: Velik Ho
version: "1.0"
---
# React Enterprise Architect / Kiến Trúc React Enterprise
## When to Use This Skill / Khi Nào Sử Dụng
Use this skill when:
- Creating new frontend apps (web-client, web-admin, web-merchant...)
- Organizing feature modules / Tổ chức feature modules
- Setting up Next.js App Router / Thiết lập Next.js App Router
- Implementing data fetching patterns / Triển khai patterns fetch data
- Designing component hierarchies / Thiết kế cấu trúc component
## Core Principles / Nguyên Tắc Cốt Lõi
1. **Feature-Based Organization**: Group by feature, not by type
2. **Server-First**: Prefer Server Components, use Client Components sparingly
3. **Colocation**: Keep related code together
4. **Single Responsibility**: Each module has one clear purpose
5. **Type Safety**: TypeScript everywhere
## Project Structure / Cấu Trúc Dự Án
```
apps/web-{app}/
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── (routes)/ # Route groups
│ │ ├── api/ # API routes
│ │ ├── layout.tsx # Root layout
│ │ └── page.tsx # Home page
│ ├── features/ # Feature modules (CORE)
│ │ ├── auth/ # Authentication feature
│ │ ├── chat/ # Chat feature
│ │ ├── dashboard/ # Dashboard feature
│ │ └── shared/ # Shared components & utils
│ │ ├── components/ # Reusable components
│ │ ├── hooks/ # Custom hooks
│ │ ├── lib/ # Utilities
│ │ ├── types/ # Shared types
│ │ └── i18n/ # Internationalization
│ ├── stores/ # Zustand stores
│ │ └── __tests__/ # Store tests
│ ├── services/ # API service clients
│ ├── providers/ # React context providers
│ ├── styles/ # Global styles, theme
│ └── stories/ # Storybook stories (docs)
├── e2e/ # Playwright E2E tests
├── public/ # Static assets
└── .storybook/ # Storybook config
```
## Key Patterns / Mẫu Chính
### Feature Module Structure
```
features/chat/
├── components/ # Feature-specific components
│ ├── ChatInput.tsx
│ ├── ChatMessage.tsx
│ └── ChatSidebar.tsx
├── hooks/ # Feature-specific hooks
│ └── useChat.ts
├── types/ # Feature types
│ └── chat.types.ts
├── utils/ # Feature utilities
│ └── formatMessage.ts
└── index.ts # Public exports (barrel file)
```
### Server vs Client Components
```tsx
// ✅ GOOD: Server Component (default)
// EN: No "use client" directive - renders on server
// VI: Không có "use client" - render trên server
async function ChatHistory({ userId }: { userId: string }) {
const messages = await fetchMessages(userId); // Server-side fetch
return