@kood/claude-code 0.5.3 → 0.5.5
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/dist/index.js +552 -340
- package/package.json +1 -1
- package/templates/.claude/agents/document-writer.md +73 -306
- package/templates/.claude/instructions/agent-patterns/index.md +7 -7
- package/templates/.claude/instructions/document-templates/ralph-templates.md +71 -0
- package/templates/.claude/instructions/index.md +14 -14
- package/templates/.claude/instructions/multi-agent/agent-roster.md +14 -14
- package/templates/.claude/instructions/multi-agent/index.md +4 -4
- package/templates/.claude/skills/docs-creator/AGENTS.md +54 -176
- package/templates/.claude/skills/docs-creator/SKILL.md +98 -464
- package/templates/.claude/skills/docs-refactor/AGENTS.md +61 -190
- package/templates/.claude/skills/docs-refactor/SKILL.md +67 -443
- package/templates/.claude/skills/execute/SKILL.md +540 -13
- package/templates/.claude/skills/plan/SKILL.md +84 -18
- package/templates/.claude/skills/ralph/SKILL.md +17 -14
- package/templates/.claude/skills/refactor/AGENTS.md +269 -0
- package/templates/.claude/skills/refactor/SKILL.md +424 -66
- package/templates/.claude/skills/stitch-design/README.md +34 -0
- package/templates/.claude/skills/stitch-design/SKILL.md +213 -0
- package/templates/.claude/skills/stitch-design/examples/DESIGN.md +154 -0
- package/templates/.claude/skills/stitch-loop/README.md +54 -0
- package/templates/.claude/skills/stitch-loop/SKILL.md +316 -0
- package/templates/.claude/skills/stitch-loop/examples/SITE.md +73 -0
- package/templates/.claude/skills/stitch-loop/examples/next-prompt.md +25 -0
- package/templates/.claude/skills/stitch-loop/resources/baton-schema.md +61 -0
- package/templates/.claude/skills/stitch-loop/resources/site-template.md +104 -0
- package/templates/.claude/skills/stitch-react/README.md +36 -0
- package/templates/.claude/skills/stitch-react/SKILL.md +323 -0
- package/templates/.claude/skills/stitch-react/examples/gold-standard-card.tsx +88 -0
- package/templates/.claude/skills/stitch-react/package-lock.json +231 -0
- package/templates/.claude/skills/stitch-react/package.json +16 -0
- package/templates/.claude/skills/stitch-react/resources/architecture-checklist.md +15 -0
- package/templates/.claude/skills/stitch-react/resources/component-template.tsx +37 -0
- package/templates/.claude/skills/stitch-react/resources/stitch-api-reference.md +14 -0
- package/templates/.claude/skills/stitch-react/resources/style-guide.json +24 -0
- package/templates/.claude/skills/stitch-react/scripts/fetch-stitch.sh +30 -0
- package/templates/.claude/skills/stitch-react/scripts/validate.js +77 -0
- package/templates/hono/CLAUDE.md +28 -28
- package/templates/hono/docs/architecture.md +24 -24
- package/templates/hono/docs/deployment/cloudflare.md +18 -18
- package/templates/hono/docs/deployment/docker.md +13 -13
- package/templates/hono/docs/deployment/index.md +19 -19
- package/templates/hono/docs/deployment/railway.md +32 -32
- package/templates/hono/docs/deployment/vercel.md +29 -29
- package/templates/hono/docs/guides/conventions.md +57 -57
- package/templates/hono/docs/guides/env-setup.md +47 -47
- package/templates/hono/docs/guides/getting-started.md +27 -27
- package/templates/hono/docs/library/hono/error-handling.md +11 -11
- package/templates/hono/docs/library/hono/index.md +4 -4
- package/templates/hono/docs/library/hono/middleware.md +18 -18
- package/templates/hono/docs/library/hono/rpc.md +7 -7
- package/templates/hono/docs/library/hono/validation.md +6 -6
- package/templates/hono/docs/library/prisma/cloudflare-d1.md +29 -29
- package/templates/hono/docs/library/prisma/config.md +16 -16
- package/templates/hono/docs/library/prisma/index.md +32 -32
- package/templates/hono/docs/library/t3-env/index.md +22 -22
- package/templates/hono/docs/library/zod/index.md +31 -31
- package/templates/nextjs/CLAUDE.md +54 -54
- package/templates/nextjs/docs/architecture.md +146 -146
- package/templates/nextjs/docs/design.md +183 -183
- package/templates/nextjs/docs/guides/conventions.md +86 -86
- package/templates/nextjs/docs/guides/getting-started.md +28 -28
- package/templates/nextjs/docs/guides/routes.md +32 -32
- package/templates/nextjs/docs/library/better-auth/index.md +70 -70
- package/templates/nextjs/docs/library/nextjs/app-router.md +43 -43
- package/templates/nextjs/docs/library/nextjs/caching.md +73 -73
- package/templates/nextjs/docs/library/nextjs/index.md +51 -51
- package/templates/nextjs/docs/library/nextjs/middleware.md +41 -41
- package/templates/nextjs/docs/library/nextjs/route-handlers.md +31 -31
- package/templates/nextjs/docs/library/nextjs/server-actions.md +34 -34
- package/templates/nextjs/docs/library/prisma/cloudflare-d1.md +20 -20
- package/templates/nextjs/docs/library/prisma/config.md +18 -18
- package/templates/nextjs/docs/library/prisma/crud.md +17 -17
- package/templates/nextjs/docs/library/prisma/index.md +18 -18
- package/templates/nextjs/docs/library/prisma/relations.md +16 -16
- package/templates/nextjs/docs/library/prisma/schema.md +23 -23
- package/templates/nextjs/docs/library/prisma/setup.md +6 -6
- package/templates/nextjs/docs/library/prisma/transactions.md +10 -10
- package/templates/nextjs/docs/library/tanstack-query/index.md +6 -6
- package/templates/nextjs/docs/library/tanstack-query/invalidation.md +20 -20
- package/templates/nextjs/docs/library/tanstack-query/optimistic-updates.md +4 -4
- package/templates/nextjs/docs/library/tanstack-query/use-mutation.md +15 -15
- package/templates/nextjs/docs/library/tanstack-query/use-query.md +22 -22
- package/templates/nextjs/docs/library/zod/complex-types.md +11 -11
- package/templates/nextjs/docs/library/zod/index.md +8 -8
- package/templates/nextjs/docs/library/zod/transforms.md +11 -11
- package/templates/nextjs/docs/library/zod/validation.md +9 -9
- package/templates/npx/CLAUDE.md +38 -38
- package/templates/npx/docs/library/commander/index.md +12 -12
- package/templates/npx/docs/library/fs-extra/index.md +9 -9
- package/templates/npx/docs/library/prompts/index.md +3 -3
- package/templates/npx/docs/references/patterns.md +12 -12
- package/templates/tanstack-start/CLAUDE.md +54 -54
- package/templates/tanstack-start/docs/architecture.md +128 -128
- package/templates/tanstack-start/docs/design.md +169 -169
- package/templates/tanstack-start/docs/guides/conventions.md +43 -43
- package/templates/tanstack-start/docs/guides/env-setup.md +35 -35
- package/templates/tanstack-start/docs/guides/getting-started.md +19 -19
- package/templates/tanstack-start/docs/guides/hooks.md +45 -45
- package/templates/tanstack-start/docs/guides/routes.md +54 -54
- package/templates/tanstack-start/docs/guides/services.md +45 -45
- package/templates/tanstack-start/docs/library/prisma/cloudflare-d1.md +19 -19
- package/templates/tanstack-start/docs/library/prisma/config.md +16 -16
- package/templates/tanstack-start/docs/library/prisma/crud.md +17 -17
- package/templates/tanstack-start/docs/library/prisma/relations.md +16 -16
- package/templates/tanstack-start/docs/library/prisma/schema.md +23 -23
- package/templates/tanstack-start/docs/library/prisma/setup.md +6 -6
- package/templates/tanstack-start/docs/library/prisma/transactions.md +10 -10
- package/templates/tanstack-start/docs/library/tanstack-query/invalidation.md +19 -19
- package/templates/tanstack-start/docs/library/tanstack-query/optimistic-updates.md +4 -4
- package/templates/tanstack-start/docs/library/tanstack-query/use-mutation.md +14 -14
- package/templates/tanstack-start/docs/library/tanstack-query/use-query.md +21 -21
- package/templates/tanstack-start/docs/library/tanstack-router/error-handling.md +9 -9
- package/templates/tanstack-start/docs/library/tanstack-router/hooks.md +11 -11
- package/templates/tanstack-start/docs/library/tanstack-router/navigation.md +17 -17
- package/templates/tanstack-start/docs/library/tanstack-router/route-context.md +5 -5
- package/templates/tanstack-start/docs/library/tanstack-router/search-params.md +10 -10
- package/templates/tanstack-start/docs/library/tanstack-start/auth-patterns.md +8 -8
- package/templates/tanstack-start/docs/library/tanstack-start/middleware.md +9 -9
- package/templates/tanstack-start/docs/library/tanstack-start/routing.md +6 -6
- package/templates/tanstack-start/docs/library/tanstack-start/server-functions.md +18 -18
- package/templates/tanstack-start/docs/library/tanstack-start/setup.md +4 -4
- package/templates/tanstack-start/docs/library/zod/complex-types.md +11 -11
- package/templates/tanstack-start/docs/library/zod/transforms.md +11 -11
- package/templates/tanstack-start/docs/library/zod/validation.md +9 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Architecture
|
|
2
2
|
|
|
3
|
-
> TanStack Start
|
|
3
|
+
> TanStack Start 애플리케이션 아키텍처
|
|
4
4
|
|
|
5
5
|
<instructions>
|
|
6
6
|
@../guides/conventions.md
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
|
|
14
14
|
<forbidden>
|
|
15
15
|
|
|
16
|
-
|
|
|
17
|
-
|
|
18
|
-
|
|
|
19
|
-
| **Route Export** | `export const IndexRoute`, `const Route` (
|
|
20
|
-
| **API** |
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
| **Barrel Export** |
|
|
16
|
+
| 분류 | 금지 |
|
|
17
|
+
|------|------|
|
|
18
|
+
| **라우트** | Flat 파일 라우트 (`routes/users.tsx`) |
|
|
19
|
+
| **Route Export** | `export const IndexRoute`, `const Route` (export 안함) |
|
|
20
|
+
| **API** | `/api` 라우터 생성 (Server Functions 사용) |
|
|
21
|
+
| **레이어** | Service Layer 건너뛰기, Routes에서 직접 DB 접근 |
|
|
22
|
+
| **검증** | Handler 내부 수동 검증, 인증 로직 분산 |
|
|
23
|
+
| **Barrel Export** | `functions/index.ts` 생성 (Tree Shaking 실패, 서버 라이브러리 Client 오염) |
|
|
24
24
|
|
|
25
25
|
</forbidden>
|
|
26
26
|
|
|
@@ -28,20 +28,20 @@
|
|
|
28
28
|
|
|
29
29
|
<required>
|
|
30
30
|
|
|
31
|
-
|
|
|
32
|
-
|
|
33
|
-
|
|
|
34
|
-
| **Route Export** | `export const Route = createFileRoute(...)`
|
|
35
|
-
|
|
|
36
|
-
| **Route Group** |
|
|
37
|
-
|
|
|
38
|
-
| **beforeLoad** |
|
|
39
|
-
| **loader** |
|
|
40
|
-
| **Server Fn** |
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
31
|
+
| 분류 | 필수 |
|
|
32
|
+
|------|------|
|
|
33
|
+
| **라우트 구조** | 페이지마다 폴더 생성 (`routes/users/index.tsx`) |
|
|
34
|
+
| **Route Export** | `export const Route = createFileRoute(...)` 필수 |
|
|
35
|
+
| **계층 구조** | Routes → Server Functions → Services → Database |
|
|
36
|
+
| **Route Group** | 목록 → `(main)/`, 생성/편집 → 외부 |
|
|
37
|
+
| **페이지 분리** | 100줄+ → `-components`, 200줄+ → `-sections` |
|
|
38
|
+
| **beforeLoad** | 인증 체크, Context 전달, 리다이렉트 |
|
|
39
|
+
| **loader** | 데이터 로딩 (beforeLoad 완료 후 병렬 실행) |
|
|
40
|
+
| **Server Fn** | `createServerFn` 기본 사용 |
|
|
41
|
+
| **검증** | `inputValidator` (POST/PUT/PATCH), Zod 스키마 |
|
|
42
|
+
| **인증** | `middleware` (authMiddleware) |
|
|
43
|
+
| **에러 처리** | `errorComponent` (라우트), `notFoundComponent` (404) |
|
|
44
|
+
| **타입 안전** | TypeScript strict, Prisma 타입 |
|
|
45
45
|
|
|
46
46
|
</required>
|
|
47
47
|
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
│ TanStack Start Server │
|
|
65
65
|
│ ┌────────────────────────────────────────────────────────────┐ │
|
|
66
66
|
│ │ Server Functions │ │
|
|
67
|
-
│ │ routes/-functions/ →
|
|
67
|
+
│ │ routes/-functions/ → 페이지 전용 | functions/ → 글로벌 │ │
|
|
68
68
|
│ └────────────────────────────┬───────────────────────────────┘ │
|
|
69
69
|
│ ┌────────────────────────────▼───────────────────────────────┐ │
|
|
70
70
|
│ │ Services Layer │ │
|
|
@@ -86,32 +86,32 @@
|
|
|
86
86
|
|
|
87
87
|
<route_export_rule>
|
|
88
88
|
|
|
89
|
-
## Route Export
|
|
89
|
+
## Route Export 규칙
|
|
90
90
|
|
|
91
|
-
> ⚠️ **`export const Route`
|
|
91
|
+
> ⚠️ **`export const Route` 필수**
|
|
92
92
|
>
|
|
93
|
-
> TanStack Router
|
|
93
|
+
> TanStack Router는 모든 라우트 파일에서 **정확히 `Route`라는 이름**으로 내보내야 합니다.
|
|
94
94
|
>
|
|
95
|
-
>
|
|
95
|
+
> `tsr generate` 및 `tsr watch` 명령어가 자동으로 경로를 생성하고 업데이트합니다.
|
|
96
96
|
|
|
97
|
-
| ❌
|
|
98
|
-
|
|
97
|
+
| ❌ 금지 | ✅ 필수 |
|
|
98
|
+
|--------|--------|
|
|
99
99
|
| `const Route = createFileRoute(...)` | `export const Route = createFileRoute(...)` |
|
|
100
100
|
| `export const IndexRoute = ...` | `export const Route = ...` |
|
|
101
101
|
| `export default createFileRoute(...)` | `export const Route = createFileRoute(...)` |
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
|
-
// ❌
|
|
104
|
+
// ❌ 금지: export 없음
|
|
105
105
|
const Route = createFileRoute('/users')({
|
|
106
106
|
component: UsersPage,
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
// ❌
|
|
109
|
+
// ❌ 금지: 다른 이름
|
|
110
110
|
export const UsersRoute = createFileRoute('/users')({
|
|
111
111
|
component: UsersPage,
|
|
112
112
|
})
|
|
113
113
|
|
|
114
|
-
// ✅
|
|
114
|
+
// ✅ 필수: 정확히 'Route' 이름으로 export
|
|
115
115
|
export const Route = createFileRoute('/users')({
|
|
116
116
|
component: UsersPage,
|
|
117
117
|
})
|
|
@@ -127,59 +127,59 @@ export const Route = createFileRoute('/users')({
|
|
|
127
127
|
|
|
128
128
|
### 1. Routes Layer
|
|
129
129
|
|
|
130
|
-
> ⚠️
|
|
130
|
+
> ⚠️ **페이지마다 폴더 생성 필수**
|
|
131
131
|
>
|
|
132
|
-
>
|
|
132
|
+
> 모든 페이지는 **반드시 폴더 구조**로 만들어야 합니다. Flat 파일 방식(`routes/users.tsx`)은 금지됩니다.
|
|
133
133
|
>
|
|
134
|
-
>
|
|
134
|
+
> **이유:** -components/, -functions/, -hooks/ 등 페이지 전용 리소스를 체계적으로 관리하기 위함입니다.
|
|
135
135
|
>
|
|
136
|
-
> | ❌
|
|
137
|
-
>
|
|
136
|
+
> | ❌ 금지 | ✅ 필수 |
|
|
137
|
+
> |--------|--------|
|
|
138
138
|
> | `routes/users.tsx` | `routes/users/index.tsx` |
|
|
139
139
|
> | `routes/posts.tsx` | `routes/posts/(main)/index.tsx` |
|
|
140
140
|
|
|
141
141
|
```
|
|
142
142
|
routes/<route-name>/
|
|
143
|
-
├── (main)/ #
|
|
144
|
-
│ ├── index.tsx #
|
|
145
|
-
│ ├── -components/ #
|
|
146
|
-
│ ├── -sections/ # UI
|
|
147
|
-
│ ├── -tabs/ #
|
|
148
|
-
│ ├── -hooks/ #
|
|
149
|
-
│ └── -utils/ #
|
|
150
|
-
├── new/ #
|
|
143
|
+
├── (main)/ # route group (목록 페이지)
|
|
144
|
+
│ ├── index.tsx # 페이지 컴포넌트
|
|
145
|
+
│ ├── -components/ # 페이지 전용 컴포넌트
|
|
146
|
+
│ ├── -sections/ # UI 섹션 분리 (200줄+ 페이지)
|
|
147
|
+
│ ├── -tabs/ # 탭 콘텐츠 분리
|
|
148
|
+
│ ├── -hooks/ # 페이지 전용 훅
|
|
149
|
+
│ └── -utils/ # 상수, 헬퍼
|
|
150
|
+
├── new/ # 생성 페이지 (route group 외부)
|
|
151
151
|
│ └── index.tsx
|
|
152
|
-
├── route.tsx #
|
|
153
|
-
└── -functions/ #
|
|
152
|
+
├── route.tsx # route 설정 (loader, beforeLoad)
|
|
153
|
+
└── -functions/ # 페이지 전용 서버 함수
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
|
|
|
157
|
-
|
|
158
|
-
| **Route Group** | `(main)/` |
|
|
159
|
-
| **-components/** | 100-200
|
|
160
|
-
| **-sections/** | 200
|
|
161
|
-
| **-tabs/** |
|
|
162
|
-
| **route.tsx** |
|
|
156
|
+
| 패턴 | 위치 | 용도 |
|
|
157
|
+
|------|------|------|
|
|
158
|
+
| **Route Group** | `(main)/` | 목록 페이지, URL에 미포함 |
|
|
159
|
+
| **-components/** | 100-200줄 | 페이지 전용 컴포넌트 분리 |
|
|
160
|
+
| **-sections/** | 200줄+ | 논리적 섹션 분리 |
|
|
161
|
+
| **-tabs/** | 탭 UI | 탭 콘텐츠 분리 |
|
|
162
|
+
| **route.tsx** | 레이아웃 | 하위 경로 공통 레이아웃 |
|
|
163
163
|
|
|
164
|
-
#### Layout Routes
|
|
164
|
+
#### Layout Routes 패턴
|
|
165
165
|
|
|
166
|
-
> ⚠️ **
|
|
166
|
+
> ⚠️ **route.tsx로 레이아웃 구성**
|
|
167
167
|
>
|
|
168
|
-
> `route.tsx
|
|
169
|
-
> `index.tsx
|
|
168
|
+
> `route.tsx`는 하위 경로의 공통 레이아웃 역할을 합니다.
|
|
169
|
+
> `index.tsx`는 Route Group `()`으로 묶어야 합니다.
|
|
170
170
|
>
|
|
171
|
-
>
|
|
171
|
+
> **필수:** `route.tsx`는 반드시 `component`를 export해야 합니다.
|
|
172
172
|
>
|
|
173
|
-
> | ❌
|
|
174
|
-
>
|
|
173
|
+
> | ❌ 금지 | ✅ 필수 |
|
|
174
|
+
> |--------|--------|
|
|
175
175
|
> | `export const Route = createFileRoute(...)({})` | `export const Route = createFileRoute(...)({ component: ... })` |
|
|
176
176
|
|
|
177
177
|
```
|
|
178
178
|
routes/
|
|
179
179
|
├── (auth)/
|
|
180
|
-
│ ├── route.tsx #
|
|
180
|
+
│ ├── route.tsx # 레이아웃 (<Outlet />)
|
|
181
181
|
│ ├── (main)/
|
|
182
|
-
│ │ └── index.tsx # /auth (
|
|
182
|
+
│ │ └── index.tsx # /auth (목록/메인)
|
|
183
183
|
│ ├── login/
|
|
184
184
|
│ │ └── index.tsx # /auth/login
|
|
185
185
|
│ └── register/
|
|
@@ -187,13 +187,13 @@ routes/
|
|
|
187
187
|
```
|
|
188
188
|
|
|
189
189
|
```typescript
|
|
190
|
-
// ❌
|
|
190
|
+
// ❌ 금지: component 없음
|
|
191
191
|
export const Route = createFileRoute('/(auth)')({
|
|
192
192
|
beforeLoad: async () => ({ user: await getUser() }),
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
-
// ✅
|
|
196
|
-
// routes/(auth)/route.tsx -
|
|
195
|
+
// ✅ 필수: component 반드시 포함
|
|
196
|
+
// routes/(auth)/route.tsx - 레이아웃
|
|
197
197
|
export const Route = createFileRoute('/(auth)')({
|
|
198
198
|
component: () => (
|
|
199
199
|
<div className="auth-container">
|
|
@@ -202,7 +202,7 @@ export const Route = createFileRoute('/(auth)')({
|
|
|
202
202
|
),
|
|
203
203
|
})
|
|
204
204
|
|
|
205
|
-
// routes/(auth)/(main)/index.tsx -
|
|
205
|
+
// routes/(auth)/(main)/index.tsx - 메인 페이지
|
|
206
206
|
export const Route = createFileRoute('/(auth)/')({
|
|
207
207
|
component: AuthMainPage,
|
|
208
208
|
})
|
|
@@ -217,38 +217,38 @@ export const Route = createFileRoute('/(auth)/login')({
|
|
|
217
217
|
|
|
218
218
|
```
|
|
219
219
|
services/<domain>/
|
|
220
|
-
├── index.ts #
|
|
221
|
-
├── schemas.ts # Zod
|
|
222
|
-
├── queries.ts # GET
|
|
220
|
+
├── index.ts # 진입점 (re-export)
|
|
221
|
+
├── schemas.ts # Zod 스키마
|
|
222
|
+
├── queries.ts # GET 요청
|
|
223
223
|
└── mutations.ts # POST/PUT/PATCH
|
|
224
224
|
```
|
|
225
225
|
|
|
226
226
|
### 3. Server Functions Layer
|
|
227
227
|
|
|
228
228
|
```
|
|
229
|
-
functions/ #
|
|
230
|
-
├── <function-name>.ts #
|
|
229
|
+
functions/ # 글로벌 (재사용)
|
|
230
|
+
├── <function-name>.ts # 파일당 하나
|
|
231
231
|
└── middlewares/
|
|
232
232
|
└── <middleware-name>.ts
|
|
233
233
|
|
|
234
|
-
routes/<route>/-functions/ #
|
|
234
|
+
routes/<route>/-functions/ # 페이지 전용
|
|
235
235
|
└── <function-name>.ts
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
> ⚠️
|
|
238
|
+
> ⚠️ **`functions/index.ts` 생성 금지**
|
|
239
239
|
>
|
|
240
|
-
>
|
|
240
|
+
> `functions/` 폴더에 `index.ts` (barrel export) 파일을 만들지 마세요.
|
|
241
241
|
>
|
|
242
|
-
>
|
|
243
|
-
> 1. **Tree Shaking
|
|
244
|
-
> 2. **Client
|
|
242
|
+
> **문제점:**
|
|
243
|
+
> 1. **Tree Shaking 실패** - 번들러가 사용하지 않는 함수도 포함
|
|
244
|
+
> 2. **Client 번들 오염** - `pg`, `prisma` 등 서버 전용 라이브러리가 클라이언트에 import되어 빌드 에러 발생
|
|
245
245
|
>
|
|
246
246
|
> ```typescript
|
|
247
|
-
> // ❌
|
|
247
|
+
> // ❌ functions/index.ts 만들지 말 것
|
|
248
248
|
> export * from './get-users'
|
|
249
|
-
> export * from './create-post' // pg import →
|
|
249
|
+
> export * from './create-post' // pg import → 클라이언트 빌드 실패
|
|
250
250
|
>
|
|
251
|
-
> // ✅
|
|
251
|
+
> // ✅ 개별 파일에서 직접 import
|
|
252
252
|
> import { getUsers } from '@/functions/get-users'
|
|
253
253
|
> import { createPost } from '@/functions/create-post'
|
|
254
254
|
> ```
|
|
@@ -278,30 +278,30 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
278
278
|
|
|
279
279
|
### beforeLoad vs loader
|
|
280
280
|
|
|
281
|
-
|
|
|
281
|
+
| 항목 | beforeLoad | loader |
|
|
282
282
|
|------|-----------|--------|
|
|
283
|
-
|
|
|
284
|
-
|
|
|
285
|
-
|
|
|
286
|
-
|
|
|
283
|
+
| **실행 순서** | 순차 (outermost → innermost) | 병렬 (beforeLoad 완료 후) |
|
|
284
|
+
| **용도** | 인증, Context 전달, 리다이렉트 | 데이터 로딩 |
|
|
285
|
+
| **블로킹** | 모든 loader 차단 | 다른 loader와 병렬 |
|
|
286
|
+
| **성능 영향** | ⚠️ 높음 | ✅ 낮음 |
|
|
287
287
|
|
|
288
288
|
```
|
|
289
|
-
1. Parent beforeLoad (
|
|
290
|
-
2. Child beforeLoad (
|
|
291
|
-
3. All loaders (
|
|
289
|
+
1. Parent beforeLoad (순차) ──┐
|
|
290
|
+
2. Child beforeLoad (순차) ──┼→ 완료 후
|
|
291
|
+
3. All loaders (병렬) ────────┘
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
-
###
|
|
294
|
+
### 코드 패턴
|
|
295
295
|
|
|
296
296
|
```typescript
|
|
297
|
-
// ✅ beforeLoad:
|
|
297
|
+
// ✅ beforeLoad: 인증 & Context
|
|
298
298
|
beforeLoad: async () => {
|
|
299
299
|
const user = await getUser()
|
|
300
300
|
if (!user) throw redirect({ to: '/login' })
|
|
301
301
|
return { user }
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
// ✅ loader:
|
|
304
|
+
// ✅ loader: 데이터 로딩
|
|
305
305
|
loader: async () => {
|
|
306
306
|
const [users, roles] = await Promise.all([
|
|
307
307
|
getUsers(),
|
|
@@ -311,10 +311,10 @@ loader: async () => {
|
|
|
311
311
|
}
|
|
312
312
|
```
|
|
313
313
|
|
|
314
|
-
| ❌
|
|
315
|
-
|
|
316
|
-
|
|
|
317
|
-
|
|
|
314
|
+
| ❌ 금지 | ✅ 권장 |
|
|
315
|
+
|--------|--------|
|
|
316
|
+
| beforeLoad에서 데이터 로딩 | loader에서 데이터 로딩 |
|
|
317
|
+
| loader 차단 | 병렬 실행 |
|
|
318
318
|
|
|
319
319
|
</route_lifecycle>
|
|
320
320
|
|
|
@@ -324,14 +324,14 @@ loader: async () => {
|
|
|
324
324
|
|
|
325
325
|
## Context Management
|
|
326
326
|
|
|
327
|
-
|
|
|
328
|
-
|
|
329
|
-
|
|
|
330
|
-
|
|
|
331
|
-
|
|
|
327
|
+
| 단계 | 파일 | 작업 |
|
|
328
|
+
|------|------|------|
|
|
329
|
+
| **생성** | `__root.tsx` | `createRootRouteWithContext` |
|
|
330
|
+
| **확장** | `route.tsx` | `beforeLoad` Context 확장 |
|
|
331
|
+
| **사용** | `component` | `useRouteContext()` |
|
|
332
332
|
|
|
333
333
|
```typescript
|
|
334
|
-
// 1. Root:
|
|
334
|
+
// 1. Root: Context 정의
|
|
335
335
|
interface RouterContext {
|
|
336
336
|
user: User | null
|
|
337
337
|
}
|
|
@@ -340,16 +340,16 @@ export const Route = createRootRouteWithContext<RouterContext>()({
|
|
|
340
340
|
beforeLoad: async () => ({ user: await getUser() }),
|
|
341
341
|
})
|
|
342
342
|
|
|
343
|
-
// 2.
|
|
343
|
+
// 2. 확장: Context 확장
|
|
344
344
|
beforeLoad: async ({ context }) => ({
|
|
345
345
|
...context,
|
|
346
346
|
permissions: await getPermissions(context.user.id),
|
|
347
347
|
})
|
|
348
348
|
|
|
349
|
-
// 3.
|
|
349
|
+
// 3. 사용: Component
|
|
350
350
|
const { user, permissions } = useRouteContext({ from: '/dashboard' })
|
|
351
351
|
|
|
352
|
-
// 4.
|
|
352
|
+
// 4. 사용: Loader
|
|
353
353
|
loader: async ({ context }) => {
|
|
354
354
|
if (!context.permissions.includes('users:read')) {
|
|
355
355
|
throw new Error('Unauthorized')
|
|
@@ -366,7 +366,7 @@ loader: async ({ context }) => {
|
|
|
366
366
|
|
|
367
367
|
## Data Flow
|
|
368
368
|
|
|
369
|
-
### Query Flow (
|
|
369
|
+
### Query Flow (읽기)
|
|
370
370
|
|
|
371
371
|
```
|
|
372
372
|
Page → useQuery → Server Function → Prisma → Database
|
|
@@ -387,7 +387,7 @@ export const getUsers = createServerFn()
|
|
|
387
387
|
.handler(async () => prisma.user.findMany())
|
|
388
388
|
```
|
|
389
389
|
|
|
390
|
-
### Mutation Flow (
|
|
390
|
+
### Mutation Flow (쓰기)
|
|
391
391
|
|
|
392
392
|
```
|
|
393
393
|
Form → useMutation → Server Function
|
|
@@ -423,17 +423,17 @@ export const createUser = createServerFn({ method: 'POST' })
|
|
|
423
423
|
|
|
424
424
|
## Server Functions (Advanced)
|
|
425
425
|
|
|
426
|
-
### Server Functions
|
|
426
|
+
### Server Functions 타입
|
|
427
427
|
|
|
428
|
-
|
|
|
429
|
-
|
|
430
|
-
| **createServerFn** |
|
|
431
|
-
| createClientOnlyFn |
|
|
432
|
-
| createIsomorphicFn |
|
|
428
|
+
| 타입 | 실행 위치 | 사용 시나리오 |
|
|
429
|
+
|------|----------|-------------|
|
|
430
|
+
| **createServerFn** | 서버 | DB 접근, 비밀키, 서버 로직 (기본) |
|
|
431
|
+
| createClientOnlyFn | 클라이언트 | localStorage, window |
|
|
432
|
+
| createIsomorphicFn | 양쪽 | 환경별 구현 |
|
|
433
433
|
|
|
434
|
-
|
|
434
|
+
**기본 규칙**: 별도 요청 없으면 `createServerFn` 사용
|
|
435
435
|
|
|
436
|
-
### Middleware
|
|
436
|
+
### Middleware 패턴
|
|
437
437
|
|
|
438
438
|
```typescript
|
|
439
439
|
// 1. authMiddleware
|
|
@@ -444,7 +444,7 @@ export const authMiddleware = createMiddleware()
|
|
|
444
444
|
return next({ context: { ...context, user: session.user } })
|
|
445
445
|
})
|
|
446
446
|
|
|
447
|
-
// 2.
|
|
447
|
+
// 2. 사용
|
|
448
448
|
export const createPost = createServerFn({ method: 'POST' })
|
|
449
449
|
.middleware([authMiddleware])
|
|
450
450
|
.inputValidator(createPostSchema)
|
|
@@ -455,7 +455,7 @@ export const createPost = createServerFn({ method: 'POST' })
|
|
|
455
455
|
})
|
|
456
456
|
```
|
|
457
457
|
|
|
458
|
-
|
|
458
|
+
**실행 순서**: Middleware → inputValidator → handler
|
|
459
459
|
|
|
460
460
|
</server_functions_advanced>
|
|
461
461
|
|
|
@@ -465,11 +465,11 @@ export const createPost = createServerFn({ method: 'POST' })
|
|
|
465
465
|
|
|
466
466
|
## Error Handling
|
|
467
467
|
|
|
468
|
-
|
|
|
469
|
-
|
|
470
|
-
| **errorComponent** |
|
|
468
|
+
| 컴포넌트 | 처리 범위 | 위치 | 필수 |
|
|
469
|
+
|---------|----------|------|-----|
|
|
470
|
+
| **errorComponent** | 라우트 에러 | 각 route | ✅ |
|
|
471
471
|
| **notFoundComponent** | 404 | __root.tsx | ✅ |
|
|
472
|
-
| **pendingComponent** |
|
|
472
|
+
| **pendingComponent** | 로딩 | 각 route | 선택 |
|
|
473
473
|
|
|
474
474
|
```typescript
|
|
475
475
|
// __root.tsx
|
|
@@ -478,29 +478,29 @@ export const Route = createRootRoute({
|
|
|
478
478
|
notFoundComponent: () => <div>404 Not Found</div>,
|
|
479
479
|
})
|
|
480
480
|
|
|
481
|
-
// Route
|
|
481
|
+
// Route 레벨
|
|
482
482
|
export const Route = createFileRoute('/dashboard')({
|
|
483
483
|
errorComponent: ({ error }) => <div>{error.message}</div>,
|
|
484
484
|
})
|
|
485
485
|
|
|
486
|
-
// Loader
|
|
486
|
+
// Loader 에러
|
|
487
487
|
loader: async () => {
|
|
488
488
|
try {
|
|
489
489
|
return { users: await getUsers() }
|
|
490
490
|
} catch (error) {
|
|
491
|
-
throw new Error('
|
|
491
|
+
throw new Error('데이터 로딩 실패')
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
-
// Server Function
|
|
495
|
+
// Server Function 에러
|
|
496
496
|
.handler(async ({ data }) => {
|
|
497
497
|
try {
|
|
498
498
|
return await prisma.user.create({ data })
|
|
499
499
|
} catch (error) {
|
|
500
500
|
if (error.code === 'P2002') {
|
|
501
|
-
throw new Error('
|
|
501
|
+
throw new Error('이미 존재하는 이메일')
|
|
502
502
|
}
|
|
503
|
-
throw new Error('
|
|
503
|
+
throw new Error('사용자 생성 실패')
|
|
504
504
|
}
|
|
505
505
|
})
|
|
506
506
|
```
|