specialist-agent 2.13.0 → 3.2.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.
Files changed (323) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +33 -207
  3. package/dist/catalog.json +15529 -0
  4. package/dist/hw-worker.mjs +254 -0
  5. package/dist/icones/icone.ico +0 -0
  6. package/dist/icones/icone.png +0 -0
  7. package/dist/interface/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
  8. package/dist/interface/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
  9. package/dist/interface/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
  10. package/dist/interface/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
  11. package/dist/interface/assets/figtree-latin-ext-400-normal-CXAzuTZb.woff2 +0 -0
  12. package/dist/interface/assets/figtree-latin-ext-500-normal-Du0rIuHj.woff2 +0 -0
  13. package/dist/interface/assets/figtree-latin-ext-600-normal-DJlfifZj.woff2 +0 -0
  14. package/dist/interface/assets/figtree-latin-ext-700-normal-CS4sQkGV.woff2 +0 -0
  15. package/dist/interface/assets/index-BIyqZkro.css +1 -0
  16. package/dist/interface/assets/index-zAegy908.js +13 -0
  17. package/dist/interface/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  18. package/dist/interface/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  19. package/dist/interface/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  20. package/dist/interface/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  21. package/dist/interface/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
  22. package/dist/interface/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
  23. package/dist/interface/assets/unbounded-latin-500-normal-4slEIF53.woff2 +0 -0
  24. package/dist/interface/assets/unbounded-latin-700-normal-CaoNriVp.woff2 +0 -0
  25. package/dist/interface/assets/unbounded-latin-ext-500-normal-BTIpesyw.woff2 +0 -0
  26. package/dist/interface/assets/unbounded-latin-ext-700-normal-BLzWLLjG.woff2 +0 -0
  27. package/dist/interface/icones/apple-touch-icon.png +0 -0
  28. package/dist/interface/icones/favicon-32.png +0 -0
  29. package/dist/interface/icones/icone-192.png +0 -0
  30. package/dist/interface/icones/icone-512.png +0 -0
  31. package/dist/interface/icones/icone-mascara-512.png +0 -0
  32. package/dist/interface/index.html +19 -0
  33. package/dist/interface/manifest.webmanifest +19 -0
  34. package/dist/interface/sw.js +63 -0
  35. package/dist/specialist-agent.mjs +6919 -0
  36. package/dist/usage-worker.mjs +174 -0
  37. package/package.json +32 -57
  38. package/.claude-plugin/marketplace.json +0 -52
  39. package/.claude-plugin/plugin.json +0 -37
  40. package/.codex/INSTALL.md +0 -145
  41. package/.cursor-plugin/marketplace.json +0 -52
  42. package/.cursor-plugin/plugin.json +0 -37
  43. package/.opencode/INSTALL.md +0 -127
  44. package/.opencode/opencode.json +0 -186
  45. package/agents/analyst-lite.md +0 -48
  46. package/agents/analyst.md +0 -396
  47. package/agents/api-lite.md +0 -43
  48. package/agents/api.md +0 -427
  49. package/agents/architect-lite.md +0 -104
  50. package/agents/architect.md +0 -571
  51. package/agents/autopilot-lite.md +0 -46
  52. package/agents/autopilot.md +0 -196
  53. package/agents/cloud-lite.md +0 -75
  54. package/agents/cloud.md +0 -213
  55. package/agents/data-lite.md +0 -67
  56. package/agents/data.md +0 -306
  57. package/agents/debugger-lite.md +0 -46
  58. package/agents/debugger.md +0 -410
  59. package/agents/deps-lite.md +0 -41
  60. package/agents/deps.md +0 -363
  61. package/agents/designer-lite.md +0 -67
  62. package/agents/designer.md +0 -195
  63. package/agents/devops-lite.md +0 -67
  64. package/agents/devops.md +0 -205
  65. package/agents/docs-lite.md +0 -42
  66. package/agents/docs.md +0 -454
  67. package/agents/executor-lite.md +0 -61
  68. package/agents/executor.md +0 -695
  69. package/agents/explorer-lite.md +0 -55
  70. package/agents/explorer.md +0 -152
  71. package/agents/finance-lite.md +0 -66
  72. package/agents/finance.md +0 -255
  73. package/agents/i18n-lite.md +0 -44
  74. package/agents/i18n.md +0 -594
  75. package/agents/legal-lite.md +0 -113
  76. package/agents/legal.md +0 -302
  77. package/agents/marketing-lite.md +0 -25
  78. package/agents/marketing.md +0 -188
  79. package/agents/memory.md +0 -166
  80. package/agents/orchestrator-lite.md +0 -40
  81. package/agents/orchestrator.md +0 -512
  82. package/agents/pair-lite.md +0 -38
  83. package/agents/pair.md +0 -310
  84. package/agents/perf-lite.md +0 -42
  85. package/agents/perf.md +0 -320
  86. package/agents/planner-lite.md +0 -59
  87. package/agents/planner.md +0 -272
  88. package/agents/product-lite.md +0 -25
  89. package/agents/product.md +0 -195
  90. package/agents/refactor-lite.md +0 -42
  91. package/agents/refactor.md +0 -467
  92. package/agents/ripple-lite.md +0 -106
  93. package/agents/ripple.md +0 -166
  94. package/agents/scout-lite.md +0 -37
  95. package/agents/scout.md +0 -224
  96. package/agents/security-lite.md +0 -66
  97. package/agents/security.md +0 -252
  98. package/agents/sentry-triage-lite.md +0 -54
  99. package/agents/sentry-triage.md +0 -217
  100. package/agents/starter-lite.md +0 -80
  101. package/agents/starter.md +0 -300
  102. package/agents/support-lite.md +0 -24
  103. package/agents/support.md +0 -191
  104. package/agents/tdd-lite.md +0 -43
  105. package/agents/tdd.md +0 -329
  106. package/agents/tester-lite.md +0 -71
  107. package/agents/tester.md +0 -237
  108. package/cli/architectures.mjs +0 -713
  109. package/cli/detect-architecture.mjs +0 -752
  110. package/cli/generate-architecture.mjs +0 -1096
  111. package/cli/index.mjs +0 -1217
  112. package/cli/recommend-architecture.mjs +0 -870
  113. package/hooks/after-review.mjs +0 -130
  114. package/hooks/after-task.mjs +0 -117
  115. package/hooks/before-plan.mjs +0 -155
  116. package/hooks/before-review.mjs +0 -139
  117. package/hooks/hooks.json +0 -66
  118. package/hooks/lifecycle.json +0 -91
  119. package/hooks/native/auto-dispatch.mjs +0 -207
  120. package/hooks/native/auto-format.mjs +0 -176
  121. package/hooks/native/mcp-discovery.mjs +0 -168
  122. package/hooks/native/security-config.json +0 -38
  123. package/hooks/native/security-guard.mjs +0 -323
  124. package/hooks/native/session-context.mjs +0 -179
  125. package/hooks/native/session-end.mjs +0 -42
  126. package/hooks/native/utils.mjs +0 -62
  127. package/hooks/on-error.mjs +0 -129
  128. package/hooks/session-end.mjs +0 -185
  129. package/hooks/session-start.mjs +0 -154
  130. package/packs/angular/ARCHITECTURE.md +0 -814
  131. package/packs/angular/CLAUDE.md +0 -105
  132. package/packs/angular/agents/builder.md +0 -113
  133. package/packs/angular/agents/doctor.md +0 -187
  134. package/packs/angular/agents/migrator.md +0 -101
  135. package/packs/angular/agents/reviewer.md +0 -252
  136. package/packs/angular/agents-lite/builder.md +0 -65
  137. package/packs/angular/agents-lite/doctor.md +0 -64
  138. package/packs/angular/agents-lite/migrator.md +0 -75
  139. package/packs/angular/agents-lite/reviewer.md +0 -69
  140. package/packs/angular/skills/dev-create-component/SKILL.md +0 -56
  141. package/packs/angular/skills/dev-create-injectable/SKILL.md +0 -60
  142. package/packs/angular/skills/dev-create-module/SKILL.md +0 -49
  143. package/packs/angular/skills/dev-create-service/SKILL.md +0 -34
  144. package/packs/angular/skills/dev-create-test/SKILL.md +0 -78
  145. package/packs/angular/skills/dev-generate-types/SKILL.md +0 -37
  146. package/packs/angular/skills/docs-onboard/SKILL.md +0 -42
  147. package/packs/angular/skills/migration-migrate-component/SKILL.md +0 -42
  148. package/packs/angular/skills/migration-migrate-module/SKILL.md +0 -25
  149. package/packs/angular/skills/review-check-architecture/SKILL.md +0 -67
  150. package/packs/angular/skills/review-fix-violations/SKILL.md +0 -43
  151. package/packs/angular/skills/review-review/SKILL.md +0 -43
  152. package/packs/astro/ARCHITECTURE.md +0 -718
  153. package/packs/astro/CLAUDE.md +0 -106
  154. package/packs/astro/agents/builder.md +0 -123
  155. package/packs/astro/agents/doctor.md +0 -200
  156. package/packs/astro/agents/migrator.md +0 -105
  157. package/packs/astro/agents/reviewer.md +0 -253
  158. package/packs/astro/agents-lite/builder.md +0 -71
  159. package/packs/astro/agents-lite/doctor.md +0 -66
  160. package/packs/astro/agents-lite/migrator.md +0 -71
  161. package/packs/astro/agents-lite/reviewer.md +0 -70
  162. package/packs/astro/skills/dev-create-component/SKILL.md +0 -50
  163. package/packs/astro/skills/dev-create-island/SKILL.md +0 -63
  164. package/packs/astro/skills/dev-create-module/SKILL.md +0 -49
  165. package/packs/astro/skills/dev-create-service/SKILL.md +0 -34
  166. package/packs/astro/skills/dev-create-test/SKILL.md +0 -76
  167. package/packs/astro/skills/dev-generate-types/SKILL.md +0 -37
  168. package/packs/astro/skills/docs-onboard/SKILL.md +0 -51
  169. package/packs/astro/skills/migration-migrate-component/SKILL.md +0 -48
  170. package/packs/astro/skills/migration-migrate-module/SKILL.md +0 -25
  171. package/packs/astro/skills/review-check-architecture/SKILL.md +0 -72
  172. package/packs/astro/skills/review-fix-violations/SKILL.md +0 -43
  173. package/packs/astro/skills/review-review/SKILL.md +0 -45
  174. package/packs/nextjs/ARCHITECTURE.md +0 -1033
  175. package/packs/nextjs/CLAUDE.md +0 -106
  176. package/packs/nextjs/agents/builder.md +0 -132
  177. package/packs/nextjs/agents/doctor.md +0 -226
  178. package/packs/nextjs/agents/migrator.md +0 -101
  179. package/packs/nextjs/agents/reviewer.md +0 -243
  180. package/packs/nextjs/agents-lite/builder.md +0 -74
  181. package/packs/nextjs/agents-lite/doctor.md +0 -74
  182. package/packs/nextjs/agents-lite/migrator.md +0 -75
  183. package/packs/nextjs/agents-lite/reviewer.md +0 -73
  184. package/packs/nextjs/skills/dev-create-component/SKILL.md +0 -82
  185. package/packs/nextjs/skills/dev-create-hook/SKILL.md +0 -90
  186. package/packs/nextjs/skills/dev-create-module/SKILL.md +0 -63
  187. package/packs/nextjs/skills/dev-create-service/SKILL.md +0 -35
  188. package/packs/nextjs/skills/dev-create-test/SKILL.md +0 -106
  189. package/packs/nextjs/skills/dev-generate-types/SKILL.md +0 -37
  190. package/packs/nextjs/skills/docs-onboard/SKILL.md +0 -55
  191. package/packs/nextjs/skills/migration-migrate-component/SKILL.md +0 -58
  192. package/packs/nextjs/skills/migration-migrate-module/SKILL.md +0 -25
  193. package/packs/nextjs/skills/review-check-architecture/SKILL.md +0 -101
  194. package/packs/nextjs/skills/review-fix-violations/SKILL.md +0 -48
  195. package/packs/nextjs/skills/review-review/SKILL.md +0 -47
  196. package/packs/nuxt/ARCHITECTURE.md +0 -831
  197. package/packs/nuxt/CLAUDE.md +0 -111
  198. package/packs/nuxt/agents/builder.md +0 -120
  199. package/packs/nuxt/agents/doctor.md +0 -198
  200. package/packs/nuxt/agents/migrator.md +0 -101
  201. package/packs/nuxt/agents/reviewer.md +0 -255
  202. package/packs/nuxt/agents-lite/builder.md +0 -67
  203. package/packs/nuxt/agents-lite/doctor.md +0 -67
  204. package/packs/nuxt/agents-lite/migrator.md +0 -80
  205. package/packs/nuxt/agents-lite/reviewer.md +0 -71
  206. package/packs/nuxt/skills/dev-create-component/SKILL.md +0 -60
  207. package/packs/nuxt/skills/dev-create-composable/SKILL.md +0 -33
  208. package/packs/nuxt/skills/dev-create-module/SKILL.md +0 -49
  209. package/packs/nuxt/skills/dev-create-service/SKILL.md +0 -34
  210. package/packs/nuxt/skills/dev-create-test/SKILL.md +0 -61
  211. package/packs/nuxt/skills/dev-generate-types/SKILL.md +0 -37
  212. package/packs/nuxt/skills/docs-onboard/SKILL.md +0 -49
  213. package/packs/nuxt/skills/migration-migrate-component/SKILL.md +0 -48
  214. package/packs/nuxt/skills/migration-migrate-module/SKILL.md +0 -25
  215. package/packs/nuxt/skills/review-check-architecture/SKILL.md +0 -71
  216. package/packs/nuxt/skills/review-fix-violations/SKILL.md +0 -43
  217. package/packs/nuxt/skills/review-review/SKILL.md +0 -45
  218. package/packs/react/ARCHITECTURE.md +0 -991
  219. package/packs/react/CLAUDE.md +0 -102
  220. package/packs/react/agents/builder.md +0 -113
  221. package/packs/react/agents/doctor.md +0 -203
  222. package/packs/react/agents/migrator.md +0 -101
  223. package/packs/react/agents/reviewer.md +0 -252
  224. package/packs/react/agents-lite/builder.md +0 -65
  225. package/packs/react/agents-lite/doctor.md +0 -64
  226. package/packs/react/agents-lite/migrator.md +0 -74
  227. package/packs/react/agents-lite/reviewer.md +0 -69
  228. package/packs/react/skills/dev-create-component/SKILL.md +0 -53
  229. package/packs/react/skills/dev-create-hook/SKILL.md +0 -78
  230. package/packs/react/skills/dev-create-module/SKILL.md +0 -51
  231. package/packs/react/skills/dev-create-service/SKILL.md +0 -34
  232. package/packs/react/skills/dev-create-test/SKILL.md +0 -92
  233. package/packs/react/skills/dev-generate-types/SKILL.md +0 -37
  234. package/packs/react/skills/docs-onboard/SKILL.md +0 -42
  235. package/packs/react/skills/migration-migrate-component/SKILL.md +0 -44
  236. package/packs/react/skills/migration-migrate-module/SKILL.md +0 -25
  237. package/packs/react/skills/review-check-architecture/SKILL.md +0 -73
  238. package/packs/react/skills/review-fix-violations/SKILL.md +0 -45
  239. package/packs/react/skills/review-review/SKILL.md +0 -44
  240. package/packs/svelte/ARCHITECTURE.md +0 -975
  241. package/packs/svelte/CLAUDE.md +0 -102
  242. package/packs/svelte/agents/builder.md +0 -114
  243. package/packs/svelte/agents/doctor.md +0 -174
  244. package/packs/svelte/agents/migrator.md +0 -101
  245. package/packs/svelte/agents/reviewer.md +0 -238
  246. package/packs/svelte/agents-lite/builder.md +0 -66
  247. package/packs/svelte/agents-lite/doctor.md +0 -67
  248. package/packs/svelte/agents-lite/migrator.md +0 -82
  249. package/packs/svelte/agents-lite/reviewer.md +0 -70
  250. package/packs/svelte/skills/dev-create-component/SKILL.md +0 -77
  251. package/packs/svelte/skills/dev-create-module/SKILL.md +0 -59
  252. package/packs/svelte/skills/dev-create-service/SKILL.md +0 -35
  253. package/packs/svelte/skills/dev-create-store/SKILL.md +0 -94
  254. package/packs/svelte/skills/dev-create-test/SKILL.md +0 -98
  255. package/packs/svelte/skills/dev-generate-types/SKILL.md +0 -37
  256. package/packs/svelte/skills/docs-onboard/SKILL.md +0 -47
  257. package/packs/svelte/skills/migration-migrate-component/SKILL.md +0 -51
  258. package/packs/svelte/skills/migration-migrate-module/SKILL.md +0 -25
  259. package/packs/svelte/skills/review-check-architecture/SKILL.md +0 -79
  260. package/packs/svelte/skills/review-fix-violations/SKILL.md +0 -47
  261. package/packs/svelte/skills/review-review/SKILL.md +0 -45
  262. package/packs/vue/ARCHITECTURE.md +0 -798
  263. package/packs/vue/CLAUDE.md +0 -102
  264. package/packs/vue/agents/builder.md +0 -112
  265. package/packs/vue/agents/doctor.md +0 -185
  266. package/packs/vue/agents/migrator.md +0 -101
  267. package/packs/vue/agents/reviewer.md +0 -249
  268. package/packs/vue/agents-lite/builder.md +0 -65
  269. package/packs/vue/agents-lite/doctor.md +0 -63
  270. package/packs/vue/agents-lite/migrator.md +0 -73
  271. package/packs/vue/agents-lite/reviewer.md +0 -68
  272. package/packs/vue/skills/dev-create-component/SKILL.md +0 -58
  273. package/packs/vue/skills/dev-create-composable/SKILL.md +0 -31
  274. package/packs/vue/skills/dev-create-module/SKILL.md +0 -50
  275. package/packs/vue/skills/dev-create-service/SKILL.md +0 -34
  276. package/packs/vue/skills/dev-create-test/SKILL.md +0 -62
  277. package/packs/vue/skills/dev-generate-types/SKILL.md +0 -37
  278. package/packs/vue/skills/docs-onboard/SKILL.md +0 -42
  279. package/packs/vue/skills/migration-migrate-component/SKILL.md +0 -41
  280. package/packs/vue/skills/migration-migrate-module/SKILL.md +0 -25
  281. package/packs/vue/skills/review-check-architecture/SKILL.md +0 -73
  282. package/packs/vue/skills/review-fix-violations/SKILL.md +0 -42
  283. package/packs/vue/skills/review-review/SKILL.md +0 -43
  284. package/skills/audit/SKILL.md +0 -231
  285. package/skills/autofix/SKILL.md +0 -166
  286. package/skills/autopilot/SKILL.md +0 -286
  287. package/skills/brainstorm/SKILL.md +0 -298
  288. package/skills/checkpoint/SKILL.md +0 -217
  289. package/skills/codereview/SKILL.md +0 -268
  290. package/skills/commit/SKILL.md +0 -150
  291. package/skills/copywriting/SKILL.md +0 -218
  292. package/skills/cro/SKILL.md +0 -234
  293. package/skills/debug/SKILL.md +0 -210
  294. package/skills/design-review/SKILL.md +0 -217
  295. package/skills/discovery/SKILL.md +0 -218
  296. package/skills/estimate/SKILL.md +0 -154
  297. package/skills/finish/SKILL.md +0 -220
  298. package/skills/grill/SKILL.md +0 -270
  299. package/skills/health/SKILL.md +0 -251
  300. package/skills/improve-architecture/SKILL.md +0 -205
  301. package/skills/learn/SKILL.md +0 -260
  302. package/skills/lint/SKILL.md +0 -126
  303. package/skills/migrate-architecture/SKILL.md +0 -242
  304. package/skills/migrate-framework/SKILL.md +0 -172
  305. package/skills/onboard/SKILL.md +0 -168
  306. package/skills/plan/SKILL.md +0 -141
  307. package/skills/prd/SKILL.md +0 -241
  308. package/skills/recall/SKILL.md +0 -112
  309. package/skills/remember/SKILL.md +0 -108
  310. package/skills/seo-audit/SKILL.md +0 -240
  311. package/skills/tdd/SKILL.md +0 -201
  312. package/skills/tutorial/SKILL.md +0 -346
  313. package/skills/verify/SKILL.md +0 -168
  314. package/skills/worktree/SKILL.md +0 -168
  315. package/skills/write-skill/SKILL.md +0 -225
  316. package/templates/autopilot/PROMPT.md +0 -39
  317. package/templates/autopilot/README.md +0 -122
  318. package/templates/autopilot/devcontainer.json +0 -21
  319. package/templates/industry/ecommerce.md +0 -127
  320. package/templates/industry/fintech.md +0 -161
  321. package/templates/industry/saas.md +0 -134
  322. package/templates/session-memory.json +0 -48
  323. package/templates/skill-template/SKILL.md +0 -90
@@ -1,991 +0,0 @@
1
- # ARCHITECTURE.md -- Architecture & Patterns Guide
2
-
3
- > This document is the **source of truth** for all subagents.
4
- > Every architectural decision must be documented here.
5
-
6
- ---
7
-
8
- ## 1. Overview
9
-
10
- We are migrating / building a React project following a modern, typed, modular architecture:
11
-
12
- | From | To |
13
- |------|----|
14
- | JavaScript | TypeScript (strict) |
15
- | Class components | Functional components |
16
- | PropTypes | TypeScript interfaces |
17
- | Redux / raw context | Zustand (client state) + TanStack React Query (server state) |
18
- | Manual fetch / Axios inline | Services + Adapters + TanStack React Query |
19
- | Scattered try/catch | Centralized error handling in hooks (queryFn / onError) |
20
- | Structure by file type | Modular architecture by feature |
21
- | HOCs and render props (legacy) | Custom hooks + composition |
22
- | Inconsistent naming | Strict documented conventions |
23
-
24
- ### Core Stack
25
-
26
- - **React 18+** with functional components
27
- - **TypeScript** (strict mode)
28
- - **Zustand** for client state
29
- - **TanStack React Query** for server state
30
- - **Vite** for build tooling
31
- - **React Router 6** for routing
32
- - **Vitest** + **React Testing Library** for tests
33
-
34
- ### Data Flow
35
-
36
- ```
37
- Service (HTTP only) --> Adapter (parse) --> Hook (orchestrate with React Query) --> Component (TSX)
38
- ```
39
-
40
- ---
41
-
42
- ## 2. Directory Structure (Modular Architecture)
43
-
44
- ```
45
- src/
46
- +-- app/ # Application shell
47
- | +-- App.tsx
48
- | +-- main.tsx
49
- | +-- router/
50
- | | +-- index.tsx
51
- | | +-- guards/
52
- | +-- providers/ # QueryClient, Zustand, theme, etc.
53
- |
54
- +-- modules/ # Feature modules (bounded contexts)
55
- | +-- auth/
56
- | | +-- components/
57
- | | +-- hooks/
58
- | | +-- services/
59
- | | +-- adapters/
60
- | | +-- stores/
61
- | | +-- types/
62
- | | +-- pages/
63
- | | +-- __tests__/
64
- | | +-- index.ts # Barrel export (public API)
65
- | |
66
- | +-- marketplace/
67
- | | +-- components/
68
- | | | +-- MarketplaceList.tsx
69
- | | | +-- MarketplaceCard.tsx
70
- | | | +-- MarketplaceFilters.tsx
71
- | | | +-- marketplace-card/ # Sub-components if needed
72
- | | | +-- MarketplaceCardHeader.tsx
73
- | | | +-- MarketplaceCardActions.tsx
74
- | | +-- hooks/
75
- | | | +-- useMarketplaceList.ts
76
- | | | +-- useMarketplaceFilters.ts
77
- | | +-- services/
78
- | | | +-- marketplace-service.ts
79
- | | +-- adapters/
80
- | | | +-- marketplace-adapter.ts
81
- | | +-- stores/
82
- | | | +-- marketplace-store.ts # Client state only (filters, UI)
83
- | | +-- types/
84
- | | | +-- marketplace.types.ts
85
- | | | +-- marketplace.contracts.ts # Zod schemas / app contracts
86
- | | +-- pages/
87
- | | | +-- MarketplacePage.tsx
88
- | | +-- __tests__/
89
- | | +-- index.ts
90
- | |
91
- | +-- [other-module]/
92
- |
93
- +-- shared/ # Shared across modules
94
- | +-- components/ # Generic components (Button, Modal, Table)
95
- | +-- hooks/ # Shared hooks
96
- | +-- services/ # Base API client, interceptors
97
- | +-- adapters/ # Shared adapters
98
- | +-- types/ # Global types
99
- | +-- utils/ # Pure functions, no side effects
100
- | +-- helpers/ # Functions with side effects or DOM
101
- | +-- constants/ # Static values
102
- | +-- providers/ # React context providers
103
- |
104
- +-- assets/ # Static assets (images, fonts, global CSS)
105
- ```
106
-
107
- ### Import Rules Between Layers
108
-
109
- ```
110
- modules/auth <-> shared/ OK Module imports from shared
111
- modules/auth --> modules/market NO Module does NOT import from another module
112
- shared/ --> modules/auth NO Shared does NOT import from modules
113
- app/ --> modules/* OK App imports modules (router, providers)
114
- ```
115
-
116
- If two modules need to share something, move it to `shared/`.
117
-
118
- ---
119
-
120
- ## 3. Naming Conventions
121
-
122
- ### Files and Directories
123
-
124
- | Type | Pattern | Example |
125
- |------|---------|---------|
126
- | Directories | `kebab-case` | `user-settings/` |
127
- | Components | `PascalCase.tsx` | `UserSettingsForm.tsx` |
128
- | Pages | `PascalCase + Page.tsx` | `MarketplacePage.tsx` |
129
- | Hooks | `use + PascalCase.ts` | `useMarketplaceList.ts` |
130
- | Services | `kebab-case-service.ts` | `marketplace-service.ts` |
131
- | Adapters | `kebab-case-adapter.ts` | `marketplace-adapter.ts` |
132
- | Stores | `kebab-case-store.ts` | `marketplace-store.ts` |
133
- | Types | `kebab-case.types.ts` | `marketplace.types.ts` |
134
- | Contracts/Schemas | `kebab-case.contracts.ts` | `marketplace.contracts.ts` |
135
- | Utils | `kebab-case.ts` | `format-date.ts` |
136
- | Helpers | `kebab-case.ts` | `clipboard-helper.ts` |
137
- | Tests | `OriginalName.spec.ts(x)` | `MarketplaceList.spec.tsx` |
138
- | Constants | `kebab-case.constants.ts` | `api-endpoints.constants.ts` |
139
-
140
- ### Code
141
-
142
- | Type | Pattern | Example |
143
- |------|---------|---------|
144
- | Variables / functions | `camelCase` | `getUserById`, `isLoading` |
145
- | Types / Interfaces | `PascalCase` | `UserProfile`, `MarketplaceItem` |
146
- | Enums | `PascalCase` | `UserRole.Admin` |
147
- | Constants | `UPPER_SNAKE_CASE` | `API_BASE_URL`, `MAX_RETRIES` |
148
- | Hooks | `use` + `PascalCase` | `useAuth`, `useMarketplaceList` |
149
- | Store hooks | `use` + `PascalCase` + `Store` | `useMarketplaceStore` |
150
- | Query Keys | `camelCase` array | `['marketplace', 'list', { page }]` |
151
- | Event handlers | `handle` + action | `handleSubmit`, `handleDelete` |
152
- | Callback props | `on` + action | `onSelect`, `onChange` |
153
- | Boolean | `is`/`has`/`can`/`should` | `isLoading`, `hasPermission` |
154
-
155
- ---
156
-
157
- ## 4. Responsibility Layers
158
-
159
- ### 4.1 Services -- Pure HTTP Requests
160
-
161
- Services make **only** the HTTP request. No try/catch, no transformation, no business logic.
162
-
163
- ```typescript
164
- // services/marketplace-service.ts
165
- import { api } from '@/shared/services/api-client'
166
- import type {
167
- MarketplaceListResponse,
168
- MarketplaceItemResponse,
169
- CreateMarketplacePayload,
170
- } from '../types/marketplace.types'
171
-
172
- export const marketplaceService = {
173
- list(params: { page: number; pageSize: number; search?: string }) {
174
- return api.get<MarketplaceListResponse>('/marketplace', { params })
175
- },
176
-
177
- getById(id: string) {
178
- return api.get<MarketplaceItemResponse>(`/marketplace/${id}`)
179
- },
180
-
181
- create(payload: CreateMarketplacePayload) {
182
- return api.post<MarketplaceItemResponse>('/marketplace', payload)
183
- },
184
-
185
- delete(id: string) {
186
- return api.delete(`/marketplace/${id}`)
187
- },
188
- }
189
- ```
190
-
191
- **Service Rules:**
192
- - NO try/catch (caller handles errors)
193
- - NO data transformation (adapter does that)
194
- - NO business logic
195
- - NO store or hook access
196
- - YES HTTP calls with typed request/response
197
- - YES one file per domain/resource
198
- - YES export as object with methods
199
-
200
- ### 4.2 Adapters -- Contract Parsers
201
-
202
- Adapters transform API data to the application's TypeScript contract (and vice-versa). They are **pure functions** with no side effects.
203
-
204
- ```typescript
205
- // adapters/marketplace-adapter.ts
206
- import type {
207
- MarketplaceListResponse,
208
- MarketplaceItemResponse,
209
- } from '../types/marketplace.types'
210
- import type {
211
- MarketplaceItem,
212
- MarketplaceList,
213
- } from '../types/marketplace.contracts'
214
-
215
- export const marketplaceAdapter = {
216
- /**
217
- * API response -> App contract (inbound)
218
- */
219
- toMarketplaceItem(response: MarketplaceItemResponse): MarketplaceItem {
220
- return {
221
- id: response.uuid,
222
- name: response.name,
223
- vendor: response.vendor_name,
224
- category: response.category_slug,
225
- price: response.price_cents / 100,
226
- isActive: response.status === 'active',
227
- createdAt: new Date(response.created_at),
228
- updatedAt: new Date(response.updated_at),
229
- }
230
- },
231
-
232
- toMarketplaceList(response: MarketplaceListResponse): MarketplaceList {
233
- return {
234
- items: response.results.map(marketplaceAdapter.toMarketplaceItem),
235
- totalItems: response.count,
236
- totalPages: Math.ceil(response.count / response.page_size),
237
- currentPage: response.page,
238
- }
239
- },
240
-
241
- /**
242
- * App contract -> API payload (outbound)
243
- */
244
- toCreatePayload(item: CreateMarketplaceInput): CreateMarketplacePayload {
245
- return {
246
- name: item.name,
247
- vendor_name: item.vendor,
248
- category_slug: item.category,
249
- price_cents: Math.round(item.price * 100),
250
- }
251
- },
252
- }
253
- ```
254
-
255
- **Adapter Rules:**
256
- - YES pure functions (input -> output, no side effects)
257
- - YES two directions: API->App (inbound) and App->API (outbound)
258
- - YES rename fields (snake_case API -> camelCase App)
259
- - YES convert types (string->Date, cents->decimal, status->boolean)
260
- - NO HTTP calls
261
- - NO store/hook access
262
- - NO try/catch (failure = wrong type = bug to fix)
263
-
264
- ### 4.3 Types & Contracts
265
-
266
- ```typescript
267
- // types/marketplace.types.ts
268
- // <-- Types that mirror the API exactly as it returns (snake_case)
269
-
270
- export interface MarketplaceItemResponse {
271
- uuid: string
272
- name: string
273
- vendor_name: string
274
- category_slug: string
275
- price_cents: number
276
- status: 'active' | 'inactive' | 'pending'
277
- created_at: string
278
- updated_at: string
279
- }
280
-
281
- export interface MarketplaceListResponse {
282
- count: number
283
- page: number
284
- page_size: number
285
- results: MarketplaceItemResponse[]
286
- }
287
-
288
- export interface CreateMarketplacePayload {
289
- name: string
290
- vendor_name: string
291
- category_slug: string
292
- price_cents: number
293
- }
294
-
295
- // types/marketplace.contracts.ts
296
- // <-- Application contracts (camelCase, correct types)
297
-
298
- export interface MarketplaceItem {
299
- id: string
300
- name: string
301
- vendor: string
302
- category: string
303
- price: number // in currency, not cents
304
- isActive: boolean // derived from status
305
- createdAt: Date
306
- updatedAt: Date
307
- }
308
-
309
- export interface MarketplaceList {
310
- items: MarketplaceItem[]
311
- totalItems: number
312
- totalPages: number
313
- currentPage: number
314
- }
315
-
316
- export interface CreateMarketplaceInput {
317
- name: string
318
- vendor: string
319
- category: string
320
- price: number
321
- }
322
- ```
323
-
324
- ### 4.4 Hooks -- Business Logic + Orchestration
325
-
326
- Custom hooks connect everything: call service, pass through adapter, manage loading/error, and expose data.
327
-
328
- ```typescript
329
- // hooks/useMarketplaceList.ts
330
- import { useMemo } from 'react'
331
- import { useQuery, keepPreviousData } from '@tanstack/react-query'
332
- import { marketplaceService } from '../services/marketplace-service'
333
- import { marketplaceAdapter } from '../adapters/marketplace-adapter'
334
- import type { MarketplaceList } from '../types/marketplace.contracts'
335
-
336
- interface UseMarketplaceListOptions {
337
- page: number
338
- pageSize?: number
339
- search?: string
340
- }
341
-
342
- export function useMarketplaceList(options: UseMarketplaceListOptions) {
343
- const { page, pageSize = 20, search = '' } = options
344
-
345
- const {
346
- data,
347
- isLoading,
348
- isFetching,
349
- error,
350
- refetch,
351
- } = useQuery({
352
- queryKey: ['marketplace', 'list', { page, pageSize, search }],
353
- queryFn: async () => {
354
- const response = await marketplaceService.list({
355
- page,
356
- pageSize,
357
- search,
358
- })
359
- return marketplaceAdapter.toMarketplaceList(response.data)
360
- },
361
- staleTime: 5 * 60 * 1000,
362
- placeholderData: keepPreviousData,
363
- })
364
-
365
- const items = data?.items ?? []
366
- const totalPages = data?.totalPages ?? 0
367
- const isEmpty = !isLoading && items.length === 0
368
-
369
- return {
370
- // Data
371
- items,
372
- totalPages,
373
- // State
374
- isLoading,
375
- isFetching,
376
- isEmpty,
377
- error,
378
- // Actions
379
- refetch,
380
- }
381
- }
382
- ```
383
-
384
- **Hook for Mutations:**
385
-
386
- ```typescript
387
- // hooks/useDeleteMarketplaceItem.ts
388
- import { useMutation, useQueryClient } from '@tanstack/react-query'
389
- import { marketplaceService } from '../services/marketplace-service'
390
-
391
- export function useDeleteMarketplaceItem() {
392
- const queryClient = useQueryClient()
393
-
394
- return useMutation({
395
- mutationFn: (id: string) => marketplaceService.delete(id),
396
- onSuccess: () => {
397
- queryClient.invalidateQueries({ queryKey: ['marketplace'] })
398
- },
399
- onError: (error) => {
400
- // handle error (toast, etc.)
401
- console.error('Failed to delete item:', error)
402
- },
403
- })
404
- }
405
- ```
406
-
407
- **Hook Rules:**
408
- - YES orchestrate: service -> adapter -> React Query
409
- - YES manage loading, error, empty states
410
- - YES return derived data (useMemo for expensive computations)
411
- - YES prefix with `use`
412
- - YES typed return values
413
- - NO JSX/rendering (that belongs to component)
414
- - NO direct API access (service does that)
415
-
416
- ### 4.5 Zustand Stores -- Client State Only
417
-
418
- Zustand is for state that **does not come from the server**: UI state, filters, preferences, auth.
419
-
420
- ```typescript
421
- // stores/marketplace-store.ts
422
- import { create } from 'zustand'
423
-
424
- interface MarketplaceStoreState {
425
- selectedCategory: string | null
426
- viewMode: 'grid' | 'list'
427
- searchQuery: string
428
- }
429
-
430
- interface MarketplaceStoreActions {
431
- setCategory: (category: string | null) => void
432
- setViewMode: (mode: 'grid' | 'list') => void
433
- setSearchQuery: (query: string) => void
434
- clearFilters: () => void
435
- hasActiveFilters: () => boolean
436
- }
437
-
438
- type MarketplaceStore = MarketplaceStoreState & MarketplaceStoreActions
439
-
440
- export const useMarketplaceStore = create<MarketplaceStore>((set, get) => ({
441
- // State
442
- selectedCategory: null,
443
- viewMode: 'grid',
444
- searchQuery: '',
445
-
446
- // Actions
447
- setCategory: (category) => set({ selectedCategory: category }),
448
- setViewMode: (mode) => set({ viewMode: mode }),
449
- setSearchQuery: (query) => set({ searchQuery: query }),
450
-
451
- clearFilters: () =>
452
- set({
453
- selectedCategory: null,
454
- searchQuery: '',
455
- }),
456
-
457
- hasActiveFilters: () => {
458
- const state = get()
459
- return !!state.selectedCategory || !!state.searchQuery
460
- },
461
- }))
462
- ```
463
-
464
- **Zustand Store with Selectors (performance):**
465
-
466
- ```typescript
467
- // In components, use selectors to avoid unnecessary re-renders:
468
- const searchQuery = useMarketplaceStore((state) => state.searchQuery)
469
- const setSearchQuery = useMarketplaceStore((state) => state.setSearchQuery)
470
-
471
- // AVOID destructuring the entire store:
472
- // const { searchQuery, setSearchQuery } = useMarketplaceStore() // BAD: re-renders on any change
473
- ```
474
-
475
- **Store Rules:**
476
- - YES client state only (UI, filters, preferences, session)
477
- - YES use Zustand `create` with typed state and actions
478
- - YES selectors in components (avoid full store destructure)
479
- - YES separate state interface from actions interface
480
- - NO server state (API data goes in TanStack React Query)
481
- - NO HTTP calls inside stores
482
- - NO complex business logic (hooks do that)
483
-
484
- ---
485
-
486
- ## 5. React Components -- Composition Patterns
487
-
488
- ### 5.1 Functional Component Pattern
489
-
490
- ```tsx
491
- // components/MarketplaceList.tsx
492
- import { useState, useMemo, useCallback } from 'react'
493
- import { useMarketplaceList } from '../hooks/useMarketplaceList'
494
- import { useMarketplaceStore } from '../stores/marketplace-store'
495
- import { MarketplaceCard } from './MarketplaceCard'
496
- import type { MarketplaceItem } from '../types/marketplace.contracts'
497
-
498
- interface MarketplaceListProps {
499
- categoryFilter?: string
500
- onSelect: (item: MarketplaceItem) => void
501
- }
502
-
503
- export function MarketplaceList({ categoryFilter, onSelect }: MarketplaceListProps) {
504
- // 1. Stores (with selectors)
505
- const searchQuery = useMarketplaceStore((s) => s.searchQuery)
506
- const viewMode = useMarketplaceStore((s) => s.viewMode)
507
-
508
- // 2. Hooks
509
- const [page, setPage] = useState(1)
510
- const { items, totalPages, isLoading, isEmpty } = useMarketplaceList({
511
- page,
512
- search: searchQuery,
513
- })
514
-
515
- // 3. Local state
516
- const [selectedId, setSelectedId] = useState<string | null>(null)
517
-
518
- // 4. Derived state (useMemo)
519
- const isFirstPage = useMemo(() => page === 1, [page])
520
-
521
- // 5. Handlers (useCallback for stable references)
522
- const handleSelect = useCallback(
523
- (item: MarketplaceItem) => {
524
- setSelectedId(item.id)
525
- onSelect(item)
526
- },
527
- [onSelect],
528
- )
529
-
530
- const handlePageChange = useCallback((newPage: number) => {
531
- setPage(newPage)
532
- }, [])
533
-
534
- // 6. Render
535
- if (isLoading) return <div>Loading...</div>
536
- if (isEmpty) return <div>No items found</div>
537
-
538
- return (
539
- <div>
540
- {items.map((item) => (
541
- <MarketplaceCard
542
- key={item.id}
543
- item={item}
544
- isSelected={item.id === selectedId}
545
- onSelect={handleSelect}
546
- />
547
- ))}
548
- </div>
549
- )
550
- }
551
- ```
552
-
553
- ### 5.2 Stop Prop Drilling -- Component Composition
554
-
555
- **BAD -- Prop Drilling:**
556
- ```tsx
557
- // GrandParent passes props through 3 levels
558
- <Parent user={user} theme={theme} permissions={permissions}>
559
- <Child user={user} theme={theme} permissions={permissions}>
560
- <GrandChild user={user} permissions={permissions} />
561
- </Child>
562
- </Parent>
563
- ```
564
-
565
- **GOOD -- Composition with children / render props:**
566
- ```tsx
567
- // MarketplacePage.tsx (Page)
568
- export function MarketplacePage() {
569
- const [selectedItem, setSelectedItem] = useState<MarketplaceItem | null>(null)
570
-
571
- return (
572
- <PageLayout
573
- header={<MarketplaceFilters />}
574
- sidebar={
575
- selectedItem ? <MarketplaceDetails item={selectedItem} /> : null
576
- }
577
- >
578
- <MarketplaceList
579
- onSelect={setSelectedItem}
580
- renderCard={(item) => <MarketplaceCard item={item} />}
581
- renderEmpty={() => <EmptyState message="No items found" />}
582
- />
583
- </PageLayout>
584
- )
585
- }
586
- ```
587
-
588
- **GOOD -- React Context for shared state:**
589
- ```tsx
590
- // hooks/useMarketplaceContext.tsx
591
- import { createContext, useContext, useState, useCallback, type ReactNode } from 'react'
592
- import type { MarketplaceItem } from '../types/marketplace.contracts'
593
-
594
- interface MarketplaceContextValue {
595
- selectedItem: MarketplaceItem | null
596
- selectItem: (item: MarketplaceItem) => void
597
- clearSelection: () => void
598
- }
599
-
600
- const MarketplaceContext = createContext<MarketplaceContextValue | null>(null)
601
-
602
- export function MarketplaceProvider({ children }: { children: ReactNode }) {
603
- const [selectedItem, setSelectedItem] = useState<MarketplaceItem | null>(null)
604
-
605
- const selectItem = useCallback((item: MarketplaceItem) => {
606
- setSelectedItem(item)
607
- }, [])
608
-
609
- const clearSelection = useCallback(() => {
610
- setSelectedItem(null)
611
- }, [])
612
-
613
- return (
614
- <MarketplaceContext.Provider value={{ selectedItem, selectItem, clearSelection }}>
615
- {children}
616
- </MarketplaceContext.Provider>
617
- )
618
- }
619
-
620
- export function useMarketplaceContext() {
621
- const context = useContext(MarketplaceContext)
622
- if (!context) {
623
- throw new Error('useMarketplaceContext must be used within MarketplaceProvider')
624
- }
625
- return context
626
- }
627
- ```
628
-
629
- ### 5.3 Component Hierarchy
630
-
631
- ```
632
- Pages --> Composition, orchestration, provide context
633
- +-- Layout --> Visual structure (slots via props/children)
634
- +-- Features --> Feature logic (hooks, stores)
635
- +-- Shared --> Pure presentation (props in, callbacks out)
636
- ```
637
-
638
- | Type | Responsibility | Can have logic? | Can have state? |
639
- |------|---------------|-----------------|-----------------|
640
- | **Pages** | Compose components, provide context | Via hooks | Yes (hooks) |
641
- | **Feature Components** | UI + feature logic | Via hooks | Yes (hooks) |
642
- | **Shared Components** | Generic, reusable UI | Minimal (UI only) | Minimal (local) |
643
-
644
- ### 5.4 Component Props Patterns
645
-
646
- ```tsx
647
- // Typed props interface
648
- interface UserCardProps {
649
- name: string
650
- avatarUrl: string
651
- role: 'admin' | 'user'
652
- onEdit?: () => void
653
- }
654
-
655
- // children prop
656
- interface LayoutProps {
657
- children: ReactNode
658
- }
659
-
660
- // Render prop pattern
661
- interface ListProps<T> {
662
- items: T[]
663
- renderItem: (item: T) => ReactNode
664
- renderEmpty?: () => ReactNode
665
- }
666
-
667
- // Forwarding refs
668
- const Input = forwardRef<HTMLInputElement, InputProps>(
669
- ({ label, error, ...rest }, ref) => (
670
- <div>
671
- {label && <label>{label}</label>}
672
- <input ref={ref} {...rest} />
673
- {error && <span>{error}</span>}
674
- </div>
675
- ),
676
- )
677
- ```
678
-
679
- ---
680
-
681
- ## 6. Utils vs Helpers
682
-
683
- ### Utils -- Pure Functions
684
- - No side effects
685
- - Deterministic input -> output
686
- - Testable without mocks
687
- - No dependency on DOM, browser APIs, or React
688
-
689
- ```typescript
690
- // shared/utils/format-date.ts
691
- export function formatDate(date: Date, locale = 'en-US'): string {
692
- return new Intl.DateTimeFormat(locale).format(date)
693
- }
694
-
695
- // shared/utils/currency.ts
696
- export function formatCurrency(value: number, currency = 'USD'): string {
697
- return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(value)
698
- }
699
-
700
- // shared/utils/string.ts
701
- export function slugify(text: string): string {
702
- return text.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '')
703
- }
704
- ```
705
-
706
- ### Helpers -- Functions with Side Effects or DOM
707
- - Interact with browser APIs (clipboard, localStorage, DOM)
708
- - May have side effects
709
- - May need mocks in tests
710
-
711
- ```typescript
712
- // shared/helpers/clipboard-helper.ts
713
- export async function copyToClipboard(text: string): Promise<boolean> {
714
- try {
715
- await navigator.clipboard.writeText(text)
716
- return true
717
- } catch {
718
- return false
719
- }
720
- }
721
-
722
- // shared/helpers/download-helper.ts
723
- export function downloadAsFile(content: string, filename: string): void {
724
- const blob = new Blob([content], { type: 'text/plain' })
725
- const url = URL.createObjectURL(blob)
726
- const a = document.createElement('a')
727
- a.href = url
728
- a.download = filename
729
- a.click()
730
- URL.revokeObjectURL(url)
731
- }
732
-
733
- // shared/helpers/storage-helper.ts
734
- export function getStorageItem<T>(key: string, fallback: T): T {
735
- try {
736
- const item = localStorage.getItem(key)
737
- return item ? (JSON.parse(item) as T) : fallback
738
- } catch {
739
- return fallback
740
- }
741
- }
742
- ```
743
-
744
- ---
745
-
746
- ## 7. Error Handling -- Centralized Pattern
747
-
748
- ### In the Hook Layer (queryFn / onError)
749
-
750
- ```typescript
751
- // Mutations handle errors via onError callback
752
- const { mutate: deleteItem } = useMutation({
753
- mutationFn: (id: string) => marketplaceService.delete(id),
754
- onSuccess: () => {
755
- queryClient.invalidateQueries({ queryKey: ['marketplace'] })
756
- toast.success('Item removed successfully')
757
- },
758
- onError: (error) => {
759
- toast.error(parseApiError(error))
760
- },
761
- })
762
- ```
763
-
764
- ### Centralized Error Parser
765
-
766
- ```typescript
767
- // shared/utils/parse-api-error.ts
768
- import type { AxiosError } from 'axios'
769
-
770
- interface ApiErrorResponse {
771
- message?: string
772
- detail?: string
773
- errors?: Record<string, string[]>
774
- }
775
-
776
- export function parseApiError(error: unknown): string {
777
- if (error instanceof AxiosError) {
778
- const data = error.response?.data as ApiErrorResponse | undefined
779
- if (data?.message) return data.message
780
- if (data?.detail) return data.detail
781
- if (error.response?.status === 403) return 'Permission denied'
782
- if (error.response?.status === 404) return 'Resource not found'
783
- if (error.response?.status === 500) return 'Internal server error'
784
- }
785
- return 'Unexpected error. Please try again.'
786
- }
787
- ```
788
-
789
- ### Global Interceptor (API Client)
790
-
791
- ```typescript
792
- // shared/services/api-client.ts
793
- import axios from 'axios'
794
-
795
- export const api = axios.create({
796
- baseURL: import.meta.env.VITE_API_BASE_URL,
797
- })
798
-
799
- api.interceptors.response.use(
800
- (response) => response,
801
- (error) => {
802
- // Only log and redirect on 401 (session expired)
803
- if (error.response?.status === 401) {
804
- // redirect to login
805
- }
806
- // DO NOT handle other errors here -- let the caller handle them
807
- return Promise.reject(error)
808
- },
809
- )
810
- ```
811
-
812
- ### Error Boundary (React-specific)
813
-
814
- ```tsx
815
- // shared/components/ErrorBoundary.tsx
816
- import { Component, type ReactNode, type ErrorInfo } from 'react'
817
-
818
- interface ErrorBoundaryProps {
819
- fallback: ReactNode | ((error: Error) => ReactNode)
820
- children: ReactNode
821
- }
822
-
823
- interface ErrorBoundaryState {
824
- error: Error | null
825
- }
826
-
827
- export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
828
- state: ErrorBoundaryState = { error: null }
829
-
830
- static getDerivedStateFromError(error: Error): ErrorBoundaryState {
831
- return { error }
832
- }
833
-
834
- componentDidCatch(error: Error, info: ErrorInfo) {
835
- console.error('ErrorBoundary caught:', error, info)
836
- }
837
-
838
- render() {
839
- if (this.state.error) {
840
- const { fallback } = this.props
841
- return typeof fallback === 'function'
842
- ? fallback(this.state.error)
843
- : fallback
844
- }
845
- return this.props.children
846
- }
847
- }
848
- ```
849
-
850
- ---
851
-
852
- ## 8. Barrel Exports (index.ts)
853
-
854
- Each module exports only its **public API**:
855
-
856
- ```typescript
857
- // modules/marketplace/index.ts
858
-
859
- // Pages (for the router)
860
- export { MarketplacePage } from './pages/MarketplacePage'
861
-
862
- // Components reusable by others (rare, avoid)
863
- export { MarketplaceCard } from './components/MarketplaceCard'
864
-
865
- // Types (for consumers that need typing)
866
- export type { MarketplaceItem, MarketplaceList } from './types/marketplace.contracts'
867
-
868
- // DO NOT export:
869
- // - services (internal detail)
870
- // - adapters (internal detail)
871
- // - stores (use via hooks)
872
- // - internal hooks
873
- ```
874
-
875
- ---
876
-
877
- ## 9. SOLID Principles Applied to React
878
-
879
- | Principle | React Application |
880
- |-----------|------------------|
881
- | **S**ingle Responsibility | 1 component = 1 responsibility. 1 hook = 1 domain. 1 service = 1 resource. |
882
- | **O**pen/Closed | Components extensible via children, render props, and composition -- not by internal modification. |
883
- | **L**iskov Substitution | Shared components must work in any context without breaking. |
884
- | **I**nterface Segregation | Specific props, not generic objects. `<UserAvatar src={src} alt={alt} />` not `<UserAvatar user={user} />`. |
885
- | **D**ependency Inversion | Hooks depend on interfaces (types), not implementations. Services consumed via hooks, not imported directly in components. |
886
-
887
- ### SOLID Examples
888
-
889
- **Single Responsibility:**
890
- ```tsx
891
- // BAD: component doing too much
892
- function UserDashboard() {
893
- // fetching data, filtering, rendering chart, rendering table, handling forms...
894
- }
895
-
896
- // GOOD: composed from focused components
897
- function UserDashboard() {
898
- return (
899
- <DashboardLayout>
900
- <UserStats />
901
- <UserActivityChart />
902
- <UserTable />
903
- </DashboardLayout>
904
- )
905
- }
906
- ```
907
-
908
- **Open/Closed:**
909
- ```tsx
910
- // GOOD: extensible via render props and children
911
- interface DataTableProps<T> {
912
- items: T[]
913
- renderRow: (item: T) => ReactNode
914
- renderEmpty?: () => ReactNode
915
- renderHeader?: () => ReactNode
916
- }
917
-
918
- function DataTable<T>({ items, renderRow, renderEmpty, renderHeader }: DataTableProps<T>) {
919
- if (items.length === 0 && renderEmpty) return renderEmpty()
920
- return (
921
- <table>
922
- {renderHeader && <thead>{renderHeader()}</thead>}
923
- <tbody>{items.map(renderRow)}</tbody>
924
- </table>
925
- )
926
- }
927
- ```
928
-
929
- **Interface Segregation:**
930
- ```tsx
931
- // BAD: passing entire object when only a few fields are needed
932
- interface AvatarProps {
933
- user: User // component only uses name and avatarUrl
934
- }
935
-
936
- // GOOD: specific props
937
- interface AvatarProps {
938
- src: string
939
- alt: string
940
- size?: 'sm' | 'md' | 'lg'
941
- }
942
- ```
943
-
944
- ---
945
-
946
- ## 10. Migration Checklist per File
947
-
948
- ### Component (.tsx)
949
- - [ ] Functional component (no class)
950
- - [ ] Props typed via interface
951
- - [ ] Callback props typed (`onSelect`, `onChange`)
952
- - [ ] No prop drilling (use composition / context)
953
- - [ ] < 200 lines total
954
- - [ ] JSX < 100 lines
955
- - [ ] No business logic in JSX
956
- - [ ] Loading / error / empty states
957
- - [ ] No `dangerouslySetInnerHTML` or with sanitization
958
- - [ ] `useCallback` for handlers passed to children
959
- - [ ] `useMemo` for expensive derived state
960
-
961
- ### Hook
962
- - [ ] `use` prefix
963
- - [ ] Typed return value
964
- - [ ] Uses service + adapter (never direct API)
965
- - [ ] TanStack React Query for server state
966
- - [ ] Error handling via onError in query/mutation
967
- - [ ] staleTime set for queries
968
-
969
- ### Service
970
- - [ ] HTTP calls only
971
- - [ ] No try/catch
972
- - [ ] No data transformation
973
- - [ ] Typed request and response
974
-
975
- ### Adapter
976
- - [ ] Pure functions
977
- - [ ] Inbound (API->App) and Outbound (App->API)
978
- - [ ] Naming conversion (snake_case -> camelCase)
979
- - [ ] Type conversion (string->Date, etc.)
980
-
981
- ### Zustand Store
982
- - [ ] Client state only
983
- - [ ] Typed state and actions interfaces
984
- - [ ] Selectors used in components (no full destructure)
985
- - [ ] No HTTP calls
986
-
987
- ### Types
988
- - [ ] `.types.ts` for API types (raw response)
989
- - [ ] `.contracts.ts` for application contracts
990
- - [ ] No `any`
991
- - [ ] No PropTypes (use TypeScript interfaces)