Skip to content

Commit 2eb431c

Browse files
committed
fix: component-architecture.md
1 parent 464485f commit 2eb431c

1 file changed

Lines changed: 62 additions & 2 deletions

File tree

skills/react-clean-architecture-add-component/references/component-architecture.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,46 @@
22

33
This reference defines classification, file layout, and dependency direction in `src/components`.
44

5+
## Design Intent and Principles
6+
7+
The goal of this skill is not only to add React components, but to apply the Container/Presentation pattern consistently with clear separation of responsibilities and dependency direction.
8+
9+
This reference does not define full application-wide architecture. It focuses on design quality at the component boundary.
10+
11+
- Separate rendering responsibilities from logic responsibilities.
12+
- Do not place state management, side effects, or business decisions in the presentation layer.
13+
- Avoid mixing responsibilities across boundaries and keep dependency direction explicit.
14+
515
## Classification
616

717
- Place all components under `src/components`.
818
- Use only two categories:
919
- `ui`: render-only, stateless components.
1020
- `features`: components that include logic.
1121

22+
## Layer Responsibilities
23+
24+
This skill defines layers in two stages.
25+
26+
### 1. Component Type Layer
27+
28+
| Type | Responsibility |
29+
| ---------- | ------------------------------------------------------------------------------------------------------ |
30+
| `ui` | Reusable render-only component. Must not include business logic, side effects, or state management. |
31+
| `features` | Use-case-oriented component. Handles state transitions, event interpretation, and async orchestration. |
32+
33+
### 2. Internal Layer in `features`
34+
35+
| Layer | Responsibility | Primary files |
36+
| -------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
37+
| `container` | Handles state management, side effects, event handling, and data fetching. | `index.tsx`, `use<ComponentName>.tsx`, `types.ts` |
38+
| `presentation` | Receives props and renders UI only. Must not perform external I/O or state updates. | `presentation.tsx`, `presentation.module.scss`, `presentation.stories.tsx` |
39+
40+
Notes:
41+
42+
- `ui` is composed of presentation only.
43+
- `features` must separate container and presentation.
44+
1245
## Reclassification Rule
1346

1447
If the user requests `ui` but the implementation contains any of the following, treat it as `features` and ask for confirmation before creating files:
@@ -39,6 +72,32 @@ Ask using these options:
3972
- Presentation receives props and handles rendering only.
4073
- Keep logic in `use<ComponentName>.tsx`.
4174

75+
### Container/Presentation Separation Rules (Anti-patterns and Decision Examples)
76+
77+
Principles:
78+
79+
- Container is responsible for state management, side effects, event interpretation, and async processing.
80+
- Presentation is responsible only for rendering from received props.
81+
- Keep business decisions and data transformation in container-side code, not in presentation.
82+
83+
Placement rules:
84+
85+
- Place in container: `useState` / `useReducer` / `useEffect`, API calls, context/store read-write, business rule application.
86+
- Place in presentation: JSX rendering and display-only branching (for example: empty, loading, error views).
87+
- Use `types.ts` to define I/O contracts between container and presentation.
88+
89+
Anti-patterns:
90+
91+
- Calling APIs or mutations from presentation.
92+
- Updating context/store directly from presentation.
93+
- Implementing business decisions (authorization checks, state transition decisions, data shaping) in presentation.
94+
- Splitting files formally while keeping practical logic in presentation.
95+
96+
Good / Bad examples:
97+
98+
- Bad: `presentation.tsx` fetches data and manages loading state directly.
99+
- Good: `use<ComponentName>.tsx` manages data fetching and state, and `presentation.tsx` renders only from props such as `isLoading`, `items`, and `onAction`.
100+
42101
## Dependency Direction
43102

44103
- `features` -> `ui`: allowed.
@@ -49,8 +108,9 @@ Ask using these options:
49108
### ui
50109

51110
- `index.tsx`
52-
- `index.stories.tsx`
53-
- `index.module.scss`
111+
- `presentation.tsx`
112+
- `presentation.stories.tsx`
113+
- `presentation.module.scss`
54114

55115
### features
56116

0 commit comments

Comments
 (0)