desktop-team-doc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -0
- package/content/docs/README.md +227 -0
- package/content/docs/index.md +352 -0
- package/content/docs/instructions/coding-conventions/.clang-format +65 -0
- package/content/docs/instructions/coding-conventions/cpp.md +132 -0
- package/content/docs/instructions/coding-conventions/frontend.md +612 -0
- package/content/docs/instructions/coding-conventions/team-wide.md +176 -0
- package/content/docs/instructions/workflows/assets/jira-1.png +0 -0
- package/content/docs/instructions/workflows/assets/jira-comment.png +0 -0
- package/content/docs/instructions/workflows/assets/jira-release-note.png +0 -0
- package/content/docs/instructions/workflows/assets/jira-tag.png +0 -0
- package/content/docs/instructions/workflows/code-review.md +451 -0
- package/content/docs/instructions/workflows/git-branch-convention.md +246 -0
- package/content/docs/instructions/workflows/git-commit.md +95 -0
- package/content/docs/instructions/workflows/jira-process.md +173 -0
- package/content/docs/instructions/workflows/jira-ticket-guide.md +105 -0
- package/content/docs/instructions/workflows/pull-request-generation.md +319 -0
- package/content/docs/instructions/workflows/scrum-process.md +104 -0
- package/content/docs/instructions/workflows/survey-project-setup.md +76 -0
- package/content/docs/knowledge/architecture/README.md +11 -0
- package/content/docs/knowledge/architecture/audio-plugin-architecture.md +213 -0
- package/content/docs/knowledge/architecture/cross-platform-design.md +176 -0
- package/content/docs/knowledge/architecture/frontend-native-bridge.md +193 -0
- package/content/docs/knowledge/architecture/native-command.md +189 -0
- package/content/docs/knowledge/architecture/state-management-architecture.md +105 -0
- package/content/docs/knowledge/component-library/ControlComponent/README.md +281 -0
- package/content/docs/knowledge/component-library/ControlComponent/accessibility/accessibility-implementation.md +503 -0
- package/content/docs/knowledge/component-library/ControlComponent/common-mechanisms.md +278 -0
- package/content/docs/knowledge/component-library/ControlComponent/core/error-handling.md +451 -0
- package/content/docs/knowledge/component-library/ControlComponent/core/native-interface.md +515 -0
- package/content/docs/knowledge/component-library/ControlComponent/core/state-management.md +509 -0
- package/content/docs/knowledge/component-library/ControlComponent/creating-new-controls.md +654 -0
- package/content/docs/knowledge/component-library/ControlComponent/design/api-design-reference.md +1142 -0
- package/content/docs/knowledge/component-library/ControlComponent/design/design-principles.md +336 -0
- package/content/docs/knowledge/component-library/ControlComponent/design/styling-architecture.md +595 -0
- package/content/docs/knowledge/component-library/ControlComponent/design/visual-feedback.md +456 -0
- package/content/docs/knowledge/component-library/ControlComponent/development-environment.md +213 -0
- package/content/docs/knowledge/component-library/ControlComponent/interaction/gesture-algorithms.md +705 -0
- package/content/docs/knowledge/component-library/ControlComponent/interaction/touch-support.md +525 -0
- package/content/docs/knowledge/component-library/ControlComponent/interaction/value-processing-patterns.md +801 -0
- package/content/docs/knowledge/component-library/ControlComponent/interaction/velocity-damping-systems.md +741 -0
- package/content/docs/knowledge/component-library/ControlComponent/knob/architecture.md +490 -0
- package/content/docs/knowledge/component-library/ControlComponent/knob/how-to-use.md +304 -0
- package/content/docs/knowledge/component-library/ControlComponent/knob/index.md +105 -0
- package/content/docs/knowledge/component-library/ControlComponent/optimization/performance-benchmarks.md +535 -0
- package/content/docs/knowledge/component-library/ControlComponent/optimization/performance-optimization.md +1092 -0
- package/content/docs/knowledge/component-library/ControlComponent/quick-start.md +345 -0
- package/content/docs/knowledge/component-library/ControlComponent/slider/architecture.md +444 -0
- package/content/docs/knowledge/component-library/ControlComponent/slider/how-to-use.md +470 -0
- package/content/docs/knowledge/component-library/ControlComponent/slider/index.md +107 -0
- package/content/docs/knowledge/component-library/ControlComponent/testing-guide.md +950 -0
- package/content/docs/knowledge/component-library/ControlComponent/troubleshooting.md +657 -0
- package/content/docs/knowledge/component-library/frontend-develop/LICENSE.txt +176 -0
- package/content/docs/knowledge/component-library/frontend-develop/SKILL.md +124 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/code-organization.md +620 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/coding-standards.md +275 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/component-reusability.md +559 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/examples.md +554 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/layout-separation.md +638 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/performance-optimization.md +678 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/state-management.md +331 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/styling-guidelines.md +349 -0
- package/content/docs/knowledge/component-library/frontend-develop/references/type-safety.md +493 -0
- package/content/docs/knowledge/development/assets/cyberduck-aws-credentials.png +0 -0
- package/content/docs/knowledge/development/assets/postman-environment-setup.png +0 -0
- package/content/docs/knowledge/development/aws-storage.md +95 -0
- package/content/docs/knowledge/development/crm-system.md +22 -0
- package/content/docs/knowledge/development/glossary.md +246 -0
- package/content/docs/knowledge/development/pg-api-guide.md +71 -0
- package/content/docs/knowledge/development/staging-license-management.md +44 -0
- package/content/docs/knowledge/development/tech-stack.md +240 -0
- package/content/docs/knowledge/domain/popup-system.md +106 -0
- package/content/docs/knowledge/domain/sigpath.md +264 -0
- package/content/docs/knowledge/environment-setup/aax-signing-update.md +149 -0
- package/content/docs/knowledge/environment-setup/assets/aax-1.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/aax-2.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/aax-3.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/aax-4.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/aax-5.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/aax-6.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/aax-7.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-1.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-10.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-11.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-12.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-13.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-14.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-2.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-3.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-4.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-5.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-6.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-7.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-8.png +0 -0
- package/content/docs/knowledge/environment-setup/assets/buildmachine-9.png +0 -0
- package/content/docs/knowledge/environment-setup/build-machine-setup.md +224 -0
- package/content/docs/knowledge/environment-setup/build-machine-troubleshooting.md +193 -0
- package/content/docs/knowledge/implementation-guides/adding-amp.md +190 -0
- package/content/docs/knowledge/implementation-guides/adding-fx.md +111 -0
- package/content/docs/knowledge/implementation-guides/cab-integration.md +194 -0
- package/content/docs/knowledge/implementation-guides/custom-pedal-integration.md +309 -0
- package/content/docs/knowledge/projects/BIAS_ONE_GUI/README.md +17 -0
- package/content/manifest.json +122 -0
- package/content/rules/cpp.mdc +135 -0
- package/content/rules/frontend.mdc +615 -0
- package/content/rules/index.mdc +256 -0
- package/content/rules/knowledge.mdc +46 -0
- package/content/rules/team-wide.mdc +179 -0
- package/content/rules/workflows.mdc +43 -0
- package/content/tools/agents/context-compressor.md +357 -0
- package/content/tools/agents/context-writer.md +328 -0
- package/content/tools/agents/release-notes-generator.md +389 -0
- package/content/tools/agents/srs-writer-agent.md +63 -0
- package/content/tools/mcp/README.md +25 -0
- package/content/tools/mcp/mcp-desktop-team.example.json +13 -0
- package/content/tools/skills/frontend-develop/LICENSE.txt +176 -0
- package/content/tools/skills/frontend-develop/SKILL.md +124 -0
- package/content/tools/skills/frontend-develop/references/code-organization.md +620 -0
- package/content/tools/skills/frontend-develop/references/coding-standards.md +275 -0
- package/content/tools/skills/frontend-develop/references/component-reusability.md +559 -0
- package/content/tools/skills/frontend-develop/references/examples.md +554 -0
- package/content/tools/skills/frontend-develop/references/layout-separation.md +638 -0
- package/content/tools/skills/frontend-develop/references/performance-optimization.md +678 -0
- package/content/tools/skills/frontend-develop/references/state-management.md +331 -0
- package/content/tools/skills/frontend-develop/references/styling-guidelines.md +349 -0
- package/content/tools/skills/frontend-develop/references/type-safety.md +493 -0
- package/content/tools/slash-commands/commit.md +17 -0
- package/content/tools/slash-commands/context-compress.md +149 -0
- package/content/tools/slash-commands/context-write.md +92 -0
- package/content/tools/slash-commands/jira.md +12 -0
- package/content/tools/slash-commands/pr-gen.md +12 -0
- package/content/tools/slash-commands/pr-review.md +12 -0
- package/dist/commands/detect.d.ts +1 -0
- package/dist/commands/detect.js +33 -0
- package/dist/commands/install.d.ts +1 -0
- package/dist/commands/install.js +100 -0
- package/dist/commands/uninstall.d.ts +1 -0
- package/dist/commands/uninstall.js +132 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +53 -0
- package/dist/lib/detect-env.d.ts +3 -0
- package/dist/lib/detect-env.js +52 -0
- package/dist/lib/prompt-env.d.ts +3 -0
- package/dist/lib/prompt-env.js +16 -0
- package/dist/lib/resolve-doc-repo.d.ts +14 -0
- package/dist/lib/resolve-doc-repo.js +61 -0
- package/dist/lib/symlink.d.ts +7 -0
- package/dist/lib/symlink.js +60 -0
- package/dist/lib/sync-from-manifest.d.ts +8 -0
- package/dist/lib/sync-from-manifest.js +64 -0
- package/package.json +46 -0
package/content/docs/knowledge/component-library/frontend-develop/references/code-organization.md
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
# Code Organization Guidelines
|
|
2
|
+
|
|
3
|
+
This document provides comprehensive guidelines for organizing frontend code, including functionality classification, hooks and stores usage, Atomic Design principles, and single responsibility principle.
|
|
4
|
+
|
|
5
|
+
## Core Principles
|
|
6
|
+
|
|
7
|
+
### Single Responsibility Principle (SRP)
|
|
8
|
+
|
|
9
|
+
**Rule**: Each component, hook, or function should have one clear responsibility.
|
|
10
|
+
|
|
11
|
+
**Bad**:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
function UserProfile({ userId }: { userId: string }) {
|
|
15
|
+
const [user, setUser] = useState(null);
|
|
16
|
+
const [posts, setPosts] = useState([]);
|
|
17
|
+
const [comments, setComments] = useState([]);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
// Fetch user
|
|
21
|
+
fetchUser(userId).then(setUser);
|
|
22
|
+
// Fetch posts
|
|
23
|
+
fetchPosts(userId).then(setPosts);
|
|
24
|
+
// Fetch comments
|
|
25
|
+
fetchComments(userId).then(setComments);
|
|
26
|
+
}, [userId]);
|
|
27
|
+
|
|
28
|
+
// Render user, posts, and comments...
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Good**:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
interface UserProfileProps {
|
|
36
|
+
userId: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Separate concerns into hooks
|
|
40
|
+
function useUser(userId: string) {
|
|
41
|
+
const [user, setUser] = useState(null);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
fetchUser(userId).then(setUser);
|
|
44
|
+
}, [userId]);
|
|
45
|
+
return user;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function useUserPosts(userId: string) {
|
|
49
|
+
const [posts, setPosts] = useState([]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
fetchPosts(userId).then(setPosts);
|
|
52
|
+
}, [userId]);
|
|
53
|
+
return posts;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function UserProfile({ userId }: UserProfileProps) {
|
|
57
|
+
const user = useUser(userId);
|
|
58
|
+
const posts = useUserPosts(userId);
|
|
59
|
+
// Render...
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Functionality Classification
|
|
64
|
+
|
|
65
|
+
### When to Extract Functionality
|
|
66
|
+
|
|
67
|
+
Extract functionality into separate modules when:
|
|
68
|
+
|
|
69
|
+
1. **Reusability**: Logic is used in multiple components
|
|
70
|
+
2. **Complexity**: Logic is complex enough to warrant separation
|
|
71
|
+
3. **Testability**: Logic needs to be tested independently
|
|
72
|
+
4. **Maintainability**: Logic changes independently from component
|
|
73
|
+
|
|
74
|
+
### Classification Patterns
|
|
75
|
+
|
|
76
|
+
#### Pattern 1: Extract to Custom Hook
|
|
77
|
+
|
|
78
|
+
**When**: Logic involves React hooks and state management.
|
|
79
|
+
|
|
80
|
+
**Example**:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Custom hook for cooldown pattern
|
|
84
|
+
const useCooldown = (delayMs: number) => {
|
|
85
|
+
const lastCallTime = useRef(0);
|
|
86
|
+
|
|
87
|
+
return () => {
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
if (now - lastCallTime.current < delayMs) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
lastCallTime.current = now;
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Usage
|
|
98
|
+
function Button() {
|
|
99
|
+
const checkCooldown = useCooldown(1000);
|
|
100
|
+
|
|
101
|
+
const handleClick = () => {
|
|
102
|
+
if (checkCooldown()) {
|
|
103
|
+
// Execute action
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Pattern 2: Extract to Utility Function
|
|
110
|
+
|
|
111
|
+
**When**: Pure functions without React dependencies.
|
|
112
|
+
|
|
113
|
+
**Example**:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// Utility function
|
|
117
|
+
export function formatCurrency(amount: number, currency: string): string {
|
|
118
|
+
return new Intl.NumberFormat('en-US', {
|
|
119
|
+
style: 'currency',
|
|
120
|
+
currency,
|
|
121
|
+
}).format(amount);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Usage in component
|
|
125
|
+
interface PriceDisplayProps {
|
|
126
|
+
amount: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function PriceDisplay({ amount }: PriceDisplayProps) {
|
|
130
|
+
return <span>{formatCurrency(amount, 'USD')}</span>;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### Pattern 3: Extract to Store (Redux)
|
|
135
|
+
|
|
136
|
+
**When**: State needs to be shared across multiple components.
|
|
137
|
+
|
|
138
|
+
See [State Management](./state-management.md) for detailed guidelines.
|
|
139
|
+
|
|
140
|
+
## Hooks Organization
|
|
141
|
+
|
|
142
|
+
### Custom Hooks Best Practices
|
|
143
|
+
|
|
144
|
+
#### Naming Convention
|
|
145
|
+
|
|
146
|
+
**Rule**: Custom hooks must start with `use` prefix.
|
|
147
|
+
|
|
148
|
+
**Example**:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Good
|
|
152
|
+
function useCooldown(delayMs: number) {}
|
|
153
|
+
function useNewestValue<T>(value: T) {}
|
|
154
|
+
function useMountedState() {}
|
|
155
|
+
|
|
156
|
+
// Bad
|
|
157
|
+
function cooldown(delayMs: number) {}
|
|
158
|
+
function getNewestValue<T>(value: T) {}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Hook Structure
|
|
162
|
+
|
|
163
|
+
**Rule**: Follow consistent structure for custom hooks.
|
|
164
|
+
|
|
165
|
+
**Structure**:
|
|
166
|
+
|
|
167
|
+
1. Input parameters (props)
|
|
168
|
+
2. State declarations (`useState`, `useRef`)
|
|
169
|
+
3. Effects (`useEffect`, `useLayoutEffect`)
|
|
170
|
+
4. Computed values (`useMemo`, `useCallback`)
|
|
171
|
+
5. Return value
|
|
172
|
+
|
|
173
|
+
**Example**:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
function useNewestValue<T>(value: T): () => T {
|
|
177
|
+
// 1. Input: value (T)
|
|
178
|
+
|
|
179
|
+
// 2. State
|
|
180
|
+
const ref = useRef(value);
|
|
181
|
+
|
|
182
|
+
// 3. Effects
|
|
183
|
+
ref.current = value;
|
|
184
|
+
|
|
185
|
+
// 4. Computed
|
|
186
|
+
// (none in this case)
|
|
187
|
+
|
|
188
|
+
// 5. Return
|
|
189
|
+
return () => ref.current;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Hook Dependencies
|
|
194
|
+
|
|
195
|
+
**Rule**: Always specify complete dependency arrays.
|
|
196
|
+
|
|
197
|
+
**Bad**:
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
fetchData(userId);
|
|
202
|
+
}, []); // Missing userId dependency
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Good**:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
fetchData(userId);
|
|
210
|
+
}, [userId]); // Complete dependency array
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### When to Create Custom Hooks
|
|
214
|
+
|
|
215
|
+
Create custom hooks when:
|
|
216
|
+
|
|
217
|
+
1. **Reusable Logic**: Logic is used in multiple components
|
|
218
|
+
2. **Complex State**: State logic is complex
|
|
219
|
+
3. **Side Effects**: Managing side effects that can be abstracted
|
|
220
|
+
4. **API Calls**: Data fetching logic that can be reused
|
|
221
|
+
|
|
222
|
+
**Example**: Custom hook for API calls
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
function useApiData<T>(url: string): {
|
|
226
|
+
data: T | null;
|
|
227
|
+
loading: boolean;
|
|
228
|
+
error: Error | null;
|
|
229
|
+
} {
|
|
230
|
+
const [data, setData] = useState<T | null>(null);
|
|
231
|
+
const [loading, setLoading] = useState(true);
|
|
232
|
+
const [error, setError] = useState<Error | null>(null);
|
|
233
|
+
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
setLoading(true);
|
|
236
|
+
fetch(url)
|
|
237
|
+
.then((res) => res.json())
|
|
238
|
+
.then((data) => {
|
|
239
|
+
setData(data);
|
|
240
|
+
setLoading(false);
|
|
241
|
+
})
|
|
242
|
+
.catch((err) => {
|
|
243
|
+
setError(err);
|
|
244
|
+
setLoading(false);
|
|
245
|
+
});
|
|
246
|
+
}, [url]);
|
|
247
|
+
|
|
248
|
+
return { data, loading, error };
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Store Organization
|
|
253
|
+
|
|
254
|
+
### When to Use Stores
|
|
255
|
+
|
|
256
|
+
**Priority Order**: Redux > Local State
|
|
257
|
+
|
|
258
|
+
#### Use Redux When:
|
|
259
|
+
|
|
260
|
+
- State is global and shared across many components
|
|
261
|
+
- State needs to persist across navigation
|
|
262
|
+
- State needs time-travel debugging
|
|
263
|
+
- Complex state updates with middleware
|
|
264
|
+
|
|
265
|
+
#### Use Local State When:
|
|
266
|
+
|
|
267
|
+
- State is component-specific
|
|
268
|
+
- State doesn't need to be shared
|
|
269
|
+
- Simple state management
|
|
270
|
+
|
|
271
|
+
**Zustand 政策**: Zustand 僅既有模組保留,新功能請用 Redux 或 Local State。
|
|
272
|
+
|
|
273
|
+
See [State Management](./state-management.md) for detailed guidelines.
|
|
274
|
+
|
|
275
|
+
## Atomic Design Principles
|
|
276
|
+
|
|
277
|
+
### Component Hierarchy
|
|
278
|
+
|
|
279
|
+
Atomic Design organizes components into five levels:
|
|
280
|
+
|
|
281
|
+
1. **Atoms**: Basic building blocks (buttons, inputs, labels)
|
|
282
|
+
2. **Molecules**: Simple combinations of atoms (form fields, search bars)
|
|
283
|
+
3. **Organisms**: Complex UI components (headers, forms, tables)
|
|
284
|
+
4. **Templates**: Page-level layouts
|
|
285
|
+
5. **Pages**: Specific instances of templates
|
|
286
|
+
|
|
287
|
+
### Directory Structure
|
|
288
|
+
|
|
289
|
+
**Rule**: Organize components by Atomic Design levels.
|
|
290
|
+
|
|
291
|
+
**Structure**:
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
components/
|
|
295
|
+
├── atoms/ # Basic building blocks
|
|
296
|
+
│ ├── Button.tsx
|
|
297
|
+
│ ├── Input.tsx
|
|
298
|
+
│ └── Label.tsx
|
|
299
|
+
├── molecules/ # Simple combinations
|
|
300
|
+
│ ├── FormField.tsx
|
|
301
|
+
│ └── SearchBar.tsx
|
|
302
|
+
├── organisms/ # Complex components
|
|
303
|
+
│ ├── Header.tsx
|
|
304
|
+
│ └── DataTable.tsx
|
|
305
|
+
├── templates/ # Page layouts
|
|
306
|
+
│ └── MainLayout.tsx
|
|
307
|
+
└── pages/ # Specific pages
|
|
308
|
+
└── HomePage.tsx
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Project-Specific Structure
|
|
312
|
+
|
|
313
|
+
This project uses a modified structure:
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
components/
|
|
317
|
+
├── common/ # Reusable utility components
|
|
318
|
+
├── dumbs/ # Presentational components (no logic)
|
|
319
|
+
├── smarts/ # Container components (with logic)
|
|
320
|
+
└── module/ # Feature modules
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Rule**: Follow project structure conventions.
|
|
324
|
+
|
|
325
|
+
- **dumbs/**: Presentational components without business logic
|
|
326
|
+
- **smarts/**: Container components with state and business logic
|
|
327
|
+
- **common/**: Shared utility components
|
|
328
|
+
- **module/**: Feature-specific components grouped by functionality
|
|
329
|
+
|
|
330
|
+
### Component Classification Examples
|
|
331
|
+
|
|
332
|
+
#### Dumb Component (Presentational)
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
// components/dumbs/Button.tsx
|
|
336
|
+
export interface ButtonProps {
|
|
337
|
+
label: string;
|
|
338
|
+
onClick: () => void;
|
|
339
|
+
disabled?: boolean;
|
|
340
|
+
variant?: 'primary' | 'secondary';
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function Button({ label, onClick, disabled = false, variant = 'primary' }: ButtonProps): JSX.Element {
|
|
344
|
+
return (
|
|
345
|
+
<button onClick={onClick} disabled={disabled} className={clsx('btn', `btn-${variant}`)}>
|
|
346
|
+
{label}
|
|
347
|
+
</button>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
#### Smart Component (Container)
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// components/smarts/UserProfile.tsx
|
|
356
|
+
interface UserProfileProps {
|
|
357
|
+
userId: string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function UserProfile({ userId }: UserProfileProps): JSX.Element {
|
|
361
|
+
const user = useUser(userId);
|
|
362
|
+
const posts = useUserPosts(userId);
|
|
363
|
+
const { updateUser } = useUserActions();
|
|
364
|
+
|
|
365
|
+
if (!user) {
|
|
366
|
+
return <LoadingSpinner />;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div>
|
|
371
|
+
<UserHeader user={user} />
|
|
372
|
+
<UserPosts posts={posts} />
|
|
373
|
+
<UserActions onUpdate={updateUser} />
|
|
374
|
+
</div>
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Layout Organization
|
|
380
|
+
|
|
381
|
+
### Avoid Excessive Nesting
|
|
382
|
+
|
|
383
|
+
**Rule**: Keep component nesting levels reasonable (max 3-4 levels).
|
|
384
|
+
|
|
385
|
+
**Bad**:
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
function App() {
|
|
389
|
+
return (
|
|
390
|
+
<div>
|
|
391
|
+
<div>
|
|
392
|
+
<div>
|
|
393
|
+
<div>
|
|
394
|
+
<div>
|
|
395
|
+
<Component />
|
|
396
|
+
</div>
|
|
397
|
+
</div>
|
|
398
|
+
</div>
|
|
399
|
+
</div>
|
|
400
|
+
</div>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
**Good**:
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
function App() {
|
|
409
|
+
return (
|
|
410
|
+
<Layout>
|
|
411
|
+
<Header />
|
|
412
|
+
<MainContent>
|
|
413
|
+
<Component />
|
|
414
|
+
</MainContent>
|
|
415
|
+
<Footer />
|
|
416
|
+
</Layout>
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### Split Complex Layouts
|
|
422
|
+
|
|
423
|
+
**Rule**: Break down complex layouts into smaller, focused components.
|
|
424
|
+
|
|
425
|
+
**Example**:
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
// Instead of one large component
|
|
429
|
+
function ComplexDashboard() {
|
|
430
|
+
return <div>{/* 200 lines of JSX */}</div>;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Split into focused components
|
|
434
|
+
function Dashboard() {
|
|
435
|
+
return (
|
|
436
|
+
<DashboardLayout>
|
|
437
|
+
<DashboardHeader />
|
|
438
|
+
<DashboardSidebar />
|
|
439
|
+
<DashboardContent>
|
|
440
|
+
<StatsPanel />
|
|
441
|
+
<ChartsPanel />
|
|
442
|
+
<ActivityFeed />
|
|
443
|
+
</DashboardContent>
|
|
444
|
+
</DashboardLayout>
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
## File Organization
|
|
450
|
+
|
|
451
|
+
### File Naming
|
|
452
|
+
|
|
453
|
+
**Rule**: Follow project naming conventions.
|
|
454
|
+
|
|
455
|
+
- **Components**: `PascalCase.tsx` (e.g., `AppButton.tsx`)
|
|
456
|
+
- **Hooks**: `camelCase.ts` starting with "use" (e.g., `useInputStatus.ts`)
|
|
457
|
+
- **Utilities**: `camelCase.ts` (e.g., `constants.ts`, `utils.ts`)
|
|
458
|
+
- **Stores**: `camelCase.ts` with "Store" suffix (e.g., `guitarMatchStore.ts`)
|
|
459
|
+
- **Types**: `types.ts` or `interfaces.ts`
|
|
460
|
+
|
|
461
|
+
### Import Organization
|
|
462
|
+
|
|
463
|
+
**Rule**: Organize imports in specific order.
|
|
464
|
+
|
|
465
|
+
1. External libraries (React, third-party)
|
|
466
|
+
2. Internal modules (aliased with `@/`)
|
|
467
|
+
3. Types (using `import type`)
|
|
468
|
+
4. Relative imports
|
|
469
|
+
5. Styles
|
|
470
|
+
|
|
471
|
+
**Example**:
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
import React, { useState, useEffect } from 'react';
|
|
475
|
+
import { twMerge } from 'tailwind-merge';
|
|
476
|
+
import clsx from 'clsx';
|
|
477
|
+
|
|
478
|
+
import ClickOutsideHandler from '@/src/components/dumbs/click-outside-handler';
|
|
479
|
+
import { useParameterComponentProps } from '@/src/components/shared/store';
|
|
480
|
+
|
|
481
|
+
import type { MousePos } from '@/src/utils/mouseRx/types';
|
|
482
|
+
import type { AppButtonProps } from './types';
|
|
483
|
+
|
|
484
|
+
import './styles.css';
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Barrel Exports
|
|
488
|
+
|
|
489
|
+
**Rule**: Use `index.ts` for clean imports.
|
|
490
|
+
|
|
491
|
+
**Example**:
|
|
492
|
+
|
|
493
|
+
```typescript
|
|
494
|
+
// components/common/index.ts
|
|
495
|
+
export { default as AppButton } from './AppButton';
|
|
496
|
+
export type { AppButtonProps } from './AppButton';
|
|
497
|
+
export { default as EditableText } from './EditableText';
|
|
498
|
+
export type { EditableTextProps } from './EditableText';
|
|
499
|
+
|
|
500
|
+
// Usage
|
|
501
|
+
import { AppButton, EditableText } from '@/src/components/common';
|
|
502
|
+
import type { AppButtonProps } from '@/src/components/common';
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
## Module Organization
|
|
506
|
+
|
|
507
|
+
### Feature-Based Organization
|
|
508
|
+
|
|
509
|
+
**Rule**: Group related components, hooks, and utilities by feature.
|
|
510
|
+
|
|
511
|
+
**Structure**:
|
|
512
|
+
|
|
513
|
+
```
|
|
514
|
+
feature-name/
|
|
515
|
+
├── components/
|
|
516
|
+
│ ├── FeatureComponent.tsx
|
|
517
|
+
│ └── FeatureSubComponent.tsx
|
|
518
|
+
├── hooks/
|
|
519
|
+
│ ├── useFeatureData.ts
|
|
520
|
+
│ └── useFeatureActions.ts
|
|
521
|
+
├── utils/
|
|
522
|
+
│ └── featureUtils.ts
|
|
523
|
+
├── types.ts
|
|
524
|
+
├── constants.ts
|
|
525
|
+
└── index.ts
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
**Example**: MIDI Control Module
|
|
529
|
+
|
|
530
|
+
```
|
|
531
|
+
midi-control/
|
|
532
|
+
├── components/
|
|
533
|
+
│ ├── MidiMapping.tsx
|
|
534
|
+
│ ├── MidiPresetSettings.tsx
|
|
535
|
+
│ └── MidiGlobalSettings.tsx
|
|
536
|
+
├── hooks/
|
|
537
|
+
│ ├── useCcControl.ts
|
|
538
|
+
│ ├── useGlobalMidiMappings.ts
|
|
539
|
+
│ └── useGlobalMidiParameterOptions.ts
|
|
540
|
+
├── utils/
|
|
541
|
+
│ └── midiUtils.ts
|
|
542
|
+
├── types.ts
|
|
543
|
+
├── constants.ts
|
|
544
|
+
└── index.ts
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
## Code Splitting
|
|
548
|
+
|
|
549
|
+
### Component-Level Splitting
|
|
550
|
+
|
|
551
|
+
**Rule**: Split large components into smaller, focused components.
|
|
552
|
+
|
|
553
|
+
**Example**:
|
|
554
|
+
|
|
555
|
+
```typescript
|
|
556
|
+
// Large component (bad)
|
|
557
|
+
function UserDashboard() {
|
|
558
|
+
// 500+ lines of code
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Split into smaller components (good)
|
|
562
|
+
function UserDashboard() {
|
|
563
|
+
return (
|
|
564
|
+
<>
|
|
565
|
+
<UserHeader />
|
|
566
|
+
<UserStats />
|
|
567
|
+
<UserActivity />
|
|
568
|
+
<UserSettings />
|
|
569
|
+
</>
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
### Route-Based Splitting
|
|
575
|
+
|
|
576
|
+
**Rule**: Use dynamic imports for route-based code splitting.
|
|
577
|
+
|
|
578
|
+
**Example**:
|
|
579
|
+
|
|
580
|
+
```typescript
|
|
581
|
+
import { lazy, Suspense } from 'react';
|
|
582
|
+
|
|
583
|
+
const UserProfile = lazy(() => import('./UserProfile'));
|
|
584
|
+
const Settings = lazy(() => import('./Settings'));
|
|
585
|
+
|
|
586
|
+
function App() {
|
|
587
|
+
return (
|
|
588
|
+
<Suspense fallback={<LoadingSpinner />}>
|
|
589
|
+
<Routes>
|
|
590
|
+
<Route path="/profile" element={<UserProfile />} />
|
|
591
|
+
<Route path="/settings" element={<Settings />} />
|
|
592
|
+
</Routes>
|
|
593
|
+
</Suspense>
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
## Summary Checklist
|
|
599
|
+
|
|
600
|
+
When organizing code, ensure:
|
|
601
|
+
|
|
602
|
+
- [ ] Single responsibility principle maintained
|
|
603
|
+
- [ ] Functionality properly classified (hooks, utilities, stores)
|
|
604
|
+
- [ ] Custom hooks follow naming convention (`use` prefix)
|
|
605
|
+
- [ ] Components follow Atomic Design principles
|
|
606
|
+
- [ ] Dumb/smart component separation clear
|
|
607
|
+
- [ ] No excessive nesting (max 3-4 levels)
|
|
608
|
+
- [ ] Complex layouts split into smaller components
|
|
609
|
+
- [ ] Files follow naming conventions
|
|
610
|
+
- [ ] Imports organized in correct order
|
|
611
|
+
- [ ] Barrel exports used for clean imports
|
|
612
|
+
- [ ] Feature-based module organization
|
|
613
|
+
- [ ] Code splitting implemented where appropriate
|
|
614
|
+
|
|
615
|
+
## References
|
|
616
|
+
|
|
617
|
+
- [Atomic Design Methodology](https://atomicdesign.bradfrost.com/)
|
|
618
|
+
- [React Hooks Best Practices](https://react.dev/reference/react)
|
|
619
|
+
- Project Coding Standards: `desktop-team-documentation/instructions/coding-conventions/frontend.md`
|
|
620
|
+
- [State Management Guidelines](./state-management.md)
|