create-tigra 1.1.0 → 2.0.1

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 (243) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +80 -87
  3. package/bin/create-tigra.js +259 -308
  4. package/package.json +49 -41
  5. package/template/_claude/QUICK_REFERENCE.md +193 -0
  6. package/template/_claude/README.md +53 -0
  7. package/template/_claude/commands/create-client.md +881 -0
  8. package/template/_claude/commands/create-server.md +383 -0
  9. package/template/_claude/rules/client/01-project-structure.md +133 -0
  10. package/template/_claude/rules/client/02-components-and-types.md +146 -0
  11. package/template/_claude/rules/client/03-data-and-state.md +156 -0
  12. package/template/_claude/rules/client/04-design-system.md +185 -0
  13. package/template/_claude/rules/client/05-security.md +55 -0
  14. package/template/_claude/rules/client/06-ux-checklist.md +81 -0
  15. package/template/_claude/rules/client/core.md +42 -0
  16. package/template/_claude/rules/global/core.md +77 -0
  17. package/template/_claude/rules/server/core.md +50 -0
  18. package/template/_claude/rules/server/database.md +124 -0
  19. package/template/_claude/rules/server/project-conventions.md +150 -0
  20. package/template/_claude/rules/server/response-handling.md +144 -0
  21. package/template/client/.env.example +5 -0
  22. package/template/client/README.md +36 -0
  23. package/template/client/components.json +23 -0
  24. package/template/client/eslint.config.mjs +18 -0
  25. package/template/client/next.config.ts +34 -0
  26. package/template/client/package.json +44 -0
  27. package/template/client/postcss.config.mjs +7 -0
  28. package/template/client/src/app/(auth)/layout.tsx +18 -0
  29. package/template/client/src/app/(auth)/login/page.tsx +13 -0
  30. package/template/client/src/app/(auth)/register/page.tsx +13 -0
  31. package/template/client/src/app/(main)/dashboard/page.tsx +22 -0
  32. package/template/client/src/app/(main)/layout.tsx +11 -0
  33. package/template/client/src/app/error.tsx +27 -0
  34. package/template/client/src/app/favicon.ico +0 -0
  35. package/template/client/src/app/globals.css +145 -0
  36. package/template/client/src/app/layout.tsx +36 -0
  37. package/template/client/src/app/loading.tsx +11 -0
  38. package/template/client/src/app/not-found.tsx +23 -0
  39. package/template/client/src/app/page.tsx +45 -0
  40. package/template/client/src/app/providers.tsx +43 -0
  41. package/template/client/src/components/common/ConfirmDialog.tsx +56 -0
  42. package/template/client/src/components/common/EmptyState.tsx +31 -0
  43. package/template/client/src/components/common/LoadingSpinner.tsx +30 -0
  44. package/template/client/src/components/common/Pagination.tsx +55 -0
  45. package/template/client/src/components/layout/Footer.tsx +17 -0
  46. package/template/client/src/components/layout/Header.tsx +173 -0
  47. package/template/client/src/components/layout/MainLayout.tsx +18 -0
  48. package/template/client/src/components/ui/alert-dialog.tsx +196 -0
  49. package/template/client/src/components/ui/badge.tsx +48 -0
  50. package/template/client/src/components/ui/button.tsx +64 -0
  51. package/template/client/src/components/ui/card.tsx +92 -0
  52. package/template/client/src/components/ui/input.tsx +21 -0
  53. package/template/client/src/components/ui/label.tsx +24 -0
  54. package/template/client/src/components/ui/select.tsx +190 -0
  55. package/template/client/src/components/ui/skeleton.tsx +13 -0
  56. package/template/client/src/components/ui/table.tsx +116 -0
  57. package/template/client/src/features/auth/components/AuthInitializer.tsx +55 -0
  58. package/template/client/src/features/auth/components/LoginForm.tsx +107 -0
  59. package/template/client/src/features/auth/components/RegisterForm.tsx +178 -0
  60. package/template/client/src/features/auth/hooks/useAuth.ts +84 -0
  61. package/template/client/src/features/auth/services/auth.service.ts +52 -0
  62. package/template/client/src/features/auth/store/authSlice.ts +38 -0
  63. package/template/client/src/features/auth/types/auth.types.ts +32 -0
  64. package/template/client/src/hooks/useDebounce.ts +14 -0
  65. package/template/client/src/hooks/useLocalStorage.ts +55 -0
  66. package/template/client/src/hooks/useMediaQuery.ts +27 -0
  67. package/template/client/src/lib/api/api.types.ts +34 -0
  68. package/template/client/src/lib/api/axios.config.ts +98 -0
  69. package/template/client/src/lib/constants/api-endpoints.ts +18 -0
  70. package/template/client/src/lib/constants/app.constants.ts +12 -0
  71. package/template/client/src/lib/constants/routes.ts +9 -0
  72. package/template/client/src/lib/utils/error.ts +32 -0
  73. package/template/client/src/lib/utils/format.ts +37 -0
  74. package/template/client/src/lib/utils/security.ts +34 -0
  75. package/template/client/src/lib/utils.ts +6 -0
  76. package/template/client/src/middleware.ts +57 -0
  77. package/template/client/src/store/hooks.ts +7 -0
  78. package/template/client/src/store/index.ts +12 -0
  79. package/template/client/src/types/index.ts +3 -0
  80. package/template/client/tsconfig.json +34 -0
  81. package/template/gitignore +34 -0
  82. package/template/server/.dockerignore +66 -0
  83. package/template/server/.env.example +96 -69
  84. package/template/server/.env.production.example +90 -0
  85. package/template/server/Dockerfile +94 -0
  86. package/template/server/docker-compose.yml +82 -111
  87. package/template/server/docs/logging.md +62 -0
  88. package/template/server/eslint.config.mjs +17 -0
  89. package/template/server/package.json +68 -81
  90. package/template/server/phpmyadmin-config.php +26 -0
  91. package/template/server/postman_collection.json +666 -0
  92. package/template/server/prisma/schema.prisma +77 -93
  93. package/template/server/prisma/seed.ts +46 -142
  94. package/template/server/scripts/flush-redis.ts +41 -0
  95. package/template/server/src/app.ts +243 -71
  96. package/template/server/src/config/env.ts +67 -94
  97. package/template/server/src/libs/auth.ts +88 -0
  98. package/template/server/src/libs/cleanup.ts +35 -0
  99. package/template/server/src/libs/cookies.ts +46 -0
  100. package/template/server/src/libs/logger.ts +33 -60
  101. package/template/server/src/libs/monitoring.ts +205 -0
  102. package/template/server/src/libs/password.ts +38 -0
  103. package/template/server/src/libs/prisma.ts +68 -0
  104. package/template/server/src/libs/redis.ts +60 -79
  105. package/template/server/src/libs/requestLogger.ts +66 -0
  106. package/template/server/src/libs/storage/file-storage.service.ts +211 -0
  107. package/template/server/src/libs/storage/file-validator.ts +97 -0
  108. package/template/server/src/libs/storage/filename-sanitizer.ts +71 -0
  109. package/template/server/src/libs/storage/image-optimizer.service.ts +144 -0
  110. package/template/server/src/modules/auth/__tests__/auth.service.test.ts +365 -0
  111. package/template/server/src/modules/auth/auth.controller.ts +90 -141
  112. package/template/server/src/modules/auth/auth.repo.ts +120 -218
  113. package/template/server/src/modules/auth/auth.routes.ts +96 -83
  114. package/template/server/src/modules/auth/auth.schemas.ts +35 -137
  115. package/template/server/src/modules/auth/auth.service.ts +286 -329
  116. package/template/server/src/modules/auth/session.repo.ts +110 -0
  117. package/template/server/src/modules/users/users.controller.ts +120 -0
  118. package/template/server/src/modules/users/users.repo.ts +77 -0
  119. package/template/server/src/modules/users/users.routes.ts +89 -0
  120. package/template/server/src/modules/users/users.schemas.ts +21 -0
  121. package/template/server/src/modules/users/users.service.ts +169 -0
  122. package/template/server/src/server.ts +58 -139
  123. package/template/server/src/shared/errors/AppError.ts +21 -0
  124. package/template/server/src/shared/errors/errors.ts +43 -0
  125. package/template/server/src/shared/responses/paginatedResponse.ts +38 -0
  126. package/template/server/src/shared/responses/successResponse.ts +17 -0
  127. package/template/server/src/shared/schemas/pagination.schema.ts +12 -0
  128. package/template/server/src/shared/types/index.ts +26 -0
  129. package/template/server/src/test/setup.ts +74 -38
  130. package/template/server/tsconfig.json +27 -89
  131. package/template/server/uploads/avatars/.gitkeep +1 -0
  132. package/template/server/vitest.config.ts +43 -98
  133. package/template/.agent/rules/client/01-project-structure.md +0 -326
  134. package/template/.agent/rules/client/02-component-patterns.md +0 -249
  135. package/template/.agent/rules/client/03-typescript-rules.md +0 -226
  136. package/template/.agent/rules/client/04-state-management.md +0 -474
  137. package/template/.agent/rules/client/05-api-integration.md +0 -129
  138. package/template/.agent/rules/client/06-forms-validation.md +0 -129
  139. package/template/.agent/rules/client/07-common-patterns.md +0 -150
  140. package/template/.agent/rules/client/08-color-system.md +0 -93
  141. package/template/.agent/rules/client/09-security-rules.md +0 -97
  142. package/template/.agent/rules/client/10-testing-strategy.md +0 -370
  143. package/template/.agent/rules/global/ai-edit-safety.md +0 -38
  144. package/template/.agent/rules/server/01-db-and-migrations.md +0 -242
  145. package/template/.agent/rules/server/02-general-rules.md +0 -111
  146. package/template/.agent/rules/server/03-migrations.md +0 -20
  147. package/template/.agent/rules/server/04-pagination.md +0 -130
  148. package/template/.agent/rules/server/05-project-conventions.md +0 -71
  149. package/template/.agent/rules/server/06-response-handling.md +0 -173
  150. package/template/.agent/rules/server/07-testing-strategy.md +0 -506
  151. package/template/.agent/rules/server/08-observability.md +0 -180
  152. package/template/.agent/rules/server/10-background-jobs-v2.md +0 -185
  153. package/template/.agent/rules/server/11-rate-limiting-v2.md +0 -210
  154. package/template/.agent/rules/server/12-performance-optimization.md +0 -567
  155. package/template/.claude/rules/client-01-project-structure.md +0 -327
  156. package/template/.claude/rules/client-02-component-patterns.md +0 -250
  157. package/template/.claude/rules/client-03-typescript-rules.md +0 -227
  158. package/template/.claude/rules/client-04-state-management.md +0 -475
  159. package/template/.claude/rules/client-05-api-integration.md +0 -130
  160. package/template/.claude/rules/client-06-forms-validation.md +0 -130
  161. package/template/.claude/rules/client-07-common-patterns.md +0 -151
  162. package/template/.claude/rules/client-08-color-system.md +0 -94
  163. package/template/.claude/rules/client-09-security-rules.md +0 -98
  164. package/template/.claude/rules/client-10-testing-strategy.md +0 -371
  165. package/template/.claude/rules/global-ai-edit-safety.md +0 -39
  166. package/template/.claude/rules/server-01-db-and-migrations.md +0 -243
  167. package/template/.claude/rules/server-02-general-rules.md +0 -112
  168. package/template/.claude/rules/server-03-migrations.md +0 -21
  169. package/template/.claude/rules/server-04-pagination.md +0 -131
  170. package/template/.claude/rules/server-05-project-conventions.md +0 -72
  171. package/template/.claude/rules/server-06-response-handling.md +0 -174
  172. package/template/.claude/rules/server-07-testing-strategy.md +0 -507
  173. package/template/.claude/rules/server-08-observability.md +0 -181
  174. package/template/.claude/rules/server-10-background-jobs-v2.md +0 -186
  175. package/template/.claude/rules/server-11-rate-limiting-v2.md +0 -211
  176. package/template/.claude/rules/server-12-performance-optimization.md +0 -568
  177. package/template/.cursor/rules/client-01-project-structure.mdc +0 -327
  178. package/template/.cursor/rules/client-02-component-patterns.mdc +0 -250
  179. package/template/.cursor/rules/client-03-typescript-rules.mdc +0 -227
  180. package/template/.cursor/rules/client-04-state-management.mdc +0 -475
  181. package/template/.cursor/rules/client-05-api-integration.mdc +0 -130
  182. package/template/.cursor/rules/client-06-forms-validation.mdc +0 -130
  183. package/template/.cursor/rules/client-07-common-patterns.mdc +0 -151
  184. package/template/.cursor/rules/client-08-color-system.mdc +0 -94
  185. package/template/.cursor/rules/client-09-security-rules.mdc +0 -98
  186. package/template/.cursor/rules/client-10-testing-strategy.mdc +0 -371
  187. package/template/.cursor/rules/global-ai-edit-safety.mdc +0 -39
  188. package/template/.cursor/rules/server-01-db-and-migrations.mdc +0 -243
  189. package/template/.cursor/rules/server-02-general-rules.mdc +0 -112
  190. package/template/.cursor/rules/server-03-migrations.mdc +0 -21
  191. package/template/.cursor/rules/server-04-pagination.mdc +0 -131
  192. package/template/.cursor/rules/server-05-project-conventions.mdc +0 -72
  193. package/template/.cursor/rules/server-06-response-handling.mdc +0 -174
  194. package/template/.cursor/rules/server-07-testing-strategy.mdc +0 -507
  195. package/template/.cursor/rules/server-08-observability.mdc +0 -181
  196. package/template/.cursor/rules/server-09-api-documentation-v2.mdc +0 -169
  197. package/template/.cursor/rules/server-10-background-jobs-v2.mdc +0 -186
  198. package/template/.cursor/rules/server-11-rate-limiting-v2.mdc +0 -211
  199. package/template/.cursor/rules/server-12-performance-optimization.mdc +0 -568
  200. package/template/CLAUDE.md +0 -207
  201. package/template/server/.tsc-aliasrc.json +0 -13
  202. package/template/server/IMPORT_FIX_CHECKLIST.md +0 -98
  203. package/template/server/IMPORT_FIX_COMPLETE.md +0 -89
  204. package/template/server/README.md +0 -183
  205. package/template/server/REMAINING_IMPORT_FIXES.md +0 -150
  206. package/template/server/SECURITY.md +0 -190
  207. package/template/server/Tigra-API.postman_collection.json +0 -733
  208. package/template/server/biome.json +0 -42
  209. package/template/server/scripts/fix-all-imports.ps1 +0 -52
  210. package/template/server/scripts/fix-imports-reference.ps1 +0 -16
  211. package/template/server/scripts/fix-imports.mjs +0 -55
  212. package/template/server/scripts/setup-env.js +0 -50
  213. package/template/server/scripts/wait-for-db.js +0 -60
  214. package/template/server/src/hooks/request-timing.hook.ts +0 -26
  215. package/template/server/src/libs/auth/authenticate.middleware.ts +0 -22
  216. package/template/server/src/libs/auth/rbac.middleware.test.ts +0 -134
  217. package/template/server/src/libs/auth/rbac.middleware.ts +0 -147
  218. package/template/server/src/libs/db.ts +0 -76
  219. package/template/server/src/libs/error-handler.ts +0 -89
  220. package/template/server/src/libs/queue.ts +0 -79
  221. package/template/server/src/modules/admin/admin.controller.ts +0 -122
  222. package/template/server/src/modules/admin/admin.routes.ts +0 -62
  223. package/template/server/src/modules/admin/admin.schemas.ts +0 -35
  224. package/template/server/src/modules/admin/admin.service.ts +0 -167
  225. package/template/server/src/modules/auth/auth.integration.test.ts +0 -150
  226. package/template/server/src/modules/auth/auth.service.test.ts +0 -119
  227. package/template/server/src/modules/auth/auth.types.ts +0 -97
  228. package/template/server/src/modules/resources/resources.controller.ts +0 -218
  229. package/template/server/src/modules/resources/resources.repo.ts +0 -253
  230. package/template/server/src/modules/resources/resources.routes.ts +0 -116
  231. package/template/server/src/modules/resources/resources.schemas.ts +0 -146
  232. package/template/server/src/modules/resources/resources.service.ts +0 -218
  233. package/template/server/src/modules/resources/resources.types.ts +0 -73
  234. package/template/server/src/plugins/rate-limit.plugin.ts +0 -21
  235. package/template/server/src/plugins/security.plugin.ts +0 -21
  236. package/template/server/src/routes/health.routes.ts +0 -31
  237. package/template/server/src/types/fastify.d.ts +0 -36
  238. package/template/server/src/utils/errors.ts +0 -108
  239. package/template/server/src/utils/pagination.ts +0 -120
  240. package/template/server/src/utils/response.ts +0 -110
  241. package/template/server/src/workers/file.worker.ts +0 -106
  242. package/template/server/tsconfig.build.json +0 -30
  243. package/template/server/tsconfig.test.json +0 -22
@@ -1,129 +0,0 @@
1
- ---
2
- trigger: always_on
3
- ---
4
-
5
- > **SCOPE**: These rules apply specifically to the **client** directory.
6
-
7
- # Forms & Validation
8
-
9
- ## Form Handling with React Hook Form + Zod + Ant Design
10
-
11
- To maintain the project's logic and architecture while using Ant Design, use **React Hook Form (RHF)** for state management and **Zod** for validation, connecting them to **Ant Design** components via the `Controller` component.
12
-
13
- ### Basic Form Pattern
14
-
15
- ```tsx
16
- // features/auth/components/LoginForm.tsx
17
- import { useForm, Controller } from 'react-hook-form';
18
- import { zodResolver } from '@hookform/resolvers/zod';
19
- import { z } from 'zod';
20
- import { Button, Input, Form } from 'antd';
21
-
22
- const loginSchema = z.object({
23
- email: z.string().email('Invalid email'),
24
- password: z.string().min(8, 'Password must be at least 8 characters'),
25
- });
26
-
27
- type LoginFormData = z.infer<typeof loginSchema>;
28
-
29
- export const LoginForm = ({ onSubmit, isSubmitting }) => {
30
- const { control, handleSubmit, formState: { errors } } = useForm<LoginFormData>({
31
- resolver: zodResolver(loginSchema),
32
- });
33
-
34
- return (
35
- <Form layout="vertical" onFinish={handleSubmit(onSubmit)}>
36
- <Form.Item
37
- label="Email"
38
- validateStatus={errors.email ? 'error' : ''}
39
- help={errors.email?.message}
40
- >
41
- <Controller
42
- name="email"
43
- control={control}
44
- render={({ field }) => <Input {...field} type="email" placeholder="Email" />}
45
- />
46
- </Form.Item>
47
-
48
- <Form.Item
49
- label="Password"
50
- validateStatus={errors.password ? 'error' : ''}
51
- help={errors.password?.message}
52
- >
53
- <Controller
54
- name="password"
55
- control={control}
56
- render={({ field }) => <Input.Password {...field} placeholder="Password" />}
57
- />
58
- </Form.Item>
59
-
60
- <Button type="primary" htmlType="submit" loading={isSubmitting} block>
61
- Login
62
- </Button>
63
- </Form>
64
- );
65
- };
66
- ```
67
-
68
- ### Complete Form Example (Resources)
69
-
70
- ```tsx
71
- const resourceSchema = z.object({
72
- title: z.string().min(1, 'Title is required'),
73
- price: z.coerce.number().min(0, 'Price must be positive'),
74
- category: z.string().min(1, 'Category is required'),
75
- });
76
-
77
- type ResourceFormData = z.infer<typeof resourceSchema>;
78
-
79
- export const CreateResourceForm = ({ onSubmit, isSubmitting }) => {
80
- const { control, handleSubmit, formState: { errors } } = useForm<ResourceFormData>({
81
- resolver: zodResolver(resourceSchema),
82
- });
83
-
84
- return (
85
- <Form layout="vertical" onFinish={handleSubmit(onSubmit)}>
86
- <Form.Item label="Title" validateStatus={errors.title ? 'error' : ''} help={errors.title?.message}>
87
- <Controller name="title" control={control} render={({ field }) => <Input {...field} />} />
88
- </Form.Item>
89
-
90
- <Form.Item label="Price" validateStatus={errors.price ? 'error' : ''} help={errors.price?.message}>
91
- <Controller name="price" control={control} render={({ field }) => <Input type="number" {...field} />} />
92
- </Form.Item>
93
-
94
- <Button type="primary" htmlType="submit" loading={isSubmitting}>
95
- Create Resource
96
- </Button>
97
- </Form>
98
- );
99
- };
100
- ```
101
-
102
- ## Form with Select (Ant Design)
103
-
104
- ```tsx
105
- import { Select } from 'antd';
106
-
107
- <Form.Item label="Category" validateStatus={errors.category ? 'error' : ''} help={errors.category?.message}>
108
- <Controller
109
- name="category"
110
- control={control}
111
- render={({ field }) => (
112
- <Select {...field} placeholder="Select Category">
113
- <Select.Option value="cat1">Category 1</Select.Option>
114
- <Select.Option value="cat2">Category 2</Select.Option>
115
- </Select>
116
- )}
117
- />
118
- </Form.Item>
119
- ```
120
-
121
- ## Form with File Upload (Ant Design)
122
-
123
- Use Ant Design's `Upload` component, often manually handling the file list to sync with RHF if needed, or using a local state and calling an upload service.
124
-
125
- ## Validation Best Practices
126
- - ✅ **Consistent Schemas**: Keep Zod schemas in a dedicated `schemas/` folder within features.
127
- - ✅ **Error Mapping**: Map API validation errors back to RHF fields using `setError`.
128
- - ✅ **Loading States**: Use Ant Design's `loading` prop on buttons.
129
- - ✅ **User Experience**: Don't show validation errors until the field is "touched" or the form is submitted.
@@ -1,150 +0,0 @@
1
- ---
2
- trigger: always_on
3
- ---
4
-
5
- > **SCOPE**: These rules apply specifically to the **client** directory.
6
-
7
- # Common Patterns & Utilities
8
-
9
- ## Custom Hooks
10
-
11
- ### useAuth Hook
12
- Standard pattern for authentication state and methods.
13
-
14
- ```tsx
15
- // features/auth/hooks/useAuth.ts
16
- export const useAuth = () => {
17
- const dispatch = useAppDispatch();
18
- const { user, isAuthenticated } = useAppSelector((state) => state.auth);
19
-
20
- const login = async (data: LoginRequest) => {
21
- const response = await authService.login(data);
22
- dispatch(setCredentials(response));
23
- };
24
-
25
- const logout = () => {
26
- dispatch(logoutAction());
27
- };
28
-
29
- return { user, isAuthenticated, login, logout };
30
- };
31
- ```
32
-
33
- ## Common Components (Ant Design)
34
-
35
- ### Pagination
36
- Use Ant Design's `Pagination` component.
37
-
38
- ```tsx
39
- import { Pagination } from 'antd';
40
-
41
- export const CustomPagination = ({ current, total, onChange }) => (
42
- <Pagination
43
- current={current}
44
- total={total}
45
- onChange={onChange}
46
- showSizeChanger={false}
47
- />
48
- );
49
- ```
50
-
51
- ### Empty State
52
- Use Ant Design's `Empty` component.
53
-
54
- ```tsx
55
- import { Empty, Button } from 'antd';
56
-
57
- export const NoData = ({ message, onAction, actionText }) => (
58
- <Empty
59
- description={message}
60
- image={Empty.PRESENTED_IMAGE_SIMPLE}
61
- >
62
- {onAction && (
63
- <Button type="primary" onClick={onAction}>
64
- {actionText}
65
- </Button>
66
- )}
67
- </Empty>
68
- );
69
- ```
70
-
71
- ### Confirm Dialog
72
- Use Ant Design's `Modal.confirm`.
73
-
74
- ```tsx
75
- import { Modal } from 'antd';
76
-
77
- const showDeleteConfirm = (onConfirm: () => void) => {
78
- Modal.confirm({
79
- title: 'Are you sure you want to delete this resource?',
80
- content: 'This action cannot be undone.',
81
- okText: 'Yes, Delete',
82
- okType: 'danger',
83
- cancelText: 'No',
84
- onOk() {
85
- onConfirm();
86
- },
87
- });
88
- };
89
- ```
90
-
91
- ## Utility Functions
92
-
93
- ### Format Utils
94
- Standard internationalization utils.
95
-
96
- ```tsx
97
- // lib/utils/format.ts
98
- export const formatCurrency = (amount: number, currency = 'USD') => {
99
- return new Intl.NumberFormat('en-US', {
100
- style: 'currency',
101
- currency,
102
- }).format(amount);
103
- };
104
- ```
105
-
106
- ## Router & App Setup
107
-
108
- ### Router Configuration
109
- ```tsx
110
- // app/router.tsx
111
- export const router = createBrowserRouter([
112
- {
113
- path: '/',
114
- element: <MainLayout />,
115
- children: [
116
- { index: true, element: <HomePage /> },
117
- { path: 'resources', element: <ResourcesPage /> },
118
- { path: 'login', element: <LoginPage /> },
119
- ],
120
- },
121
- ]);
122
- ```
123
-
124
- ## Table Pattern (Ant Design)
125
- Use Ant Design's `Table` component for consistent data display.
126
-
127
- ```tsx
128
- // features/resources/components/ResourceTable.tsx
129
- import { Table, Button, Space } from 'antd';
130
-
131
- export const ResourceTable = ({ data, onEdit, onDelete, loading }) => {
132
- const columns = [
133
- { title: 'Title', dataIndex: 'title', key: 'title' },
134
- { title: 'Category', dataIndex: 'category', key: 'category' },
135
- {
136
- title: 'Actions',
137
- key: 'actions',
138
- render: (_, record) => (
139
- <Space size="middle">
140
- <Button onClick={() => onEdit(record.id)}>Edit</Button>
141
- <Button danger onClick={() => onDelete(record.id)}>Delete</Button>
142
- </Space>
143
- ),
144
- },
145
- ];
146
-
147
- return <Table dataSource={data} columns={columns} loading={loading} rowKey="id" />;
148
- };
149
- ```
150
- I use `Space` for horizontal layout and `Space.Compact` for grouped actions.
@@ -1,93 +0,0 @@
1
- ---
2
- trigger: always_on
3
- ---
4
-
5
- > **SCOPE**: These rules apply specifically to the **client** directory.
6
-
7
- # Color System & Theming
8
-
9
- ## Color Architecture
10
- All colors are defined as **CSS variables** in a global stylesheet and synchronized with **Ant Design's ConfigProvider** for component theming.
11
-
12
- ## CSS Variables Setup
13
-
14
- ```css
15
- /* styles/theme.css */
16
- :root {
17
- --primary-color: #1677ff;
18
- --success-color: #52c41a;
19
- --warning-color: #faad14;
20
- --error-color: #f5222d;
21
- --text-color: rgba(0, 0, 0, 0.88);
22
- --bg-color: #ffffff;
23
- --border-color: #d9d9d9;
24
- }
25
-
26
- [data-theme='dark'] {
27
- --primary-color: #1668dc;
28
- --bg-color: #141414;
29
- --text-color: rgba(255, 255, 255, 0.85);
30
- }
31
- ```
32
-
33
- ## Ant Design Configuration
34
-
35
- ```tsx
36
- // app/providers.tsx
37
- import { ConfigProvider, theme } from 'antd';
38
-
39
- export const AppProviders = ({ children, isDarkMode }) => (
40
- <ConfigProvider
41
- theme={{
42
- algorithm: isDarkMode ? theme.darkAlgorithm : theme.defaultAlgorithm,
43
- token: {
44
- colorPrimary: '#1677ff',
45
- borderRadius: 4,
46
- },
47
- }}
48
- >
49
- {children}
50
- </ConfigProvider>
51
- );
52
- ```
53
-
54
- ## Usage Rules
55
-
56
- ### ✅ CORRECT - Use CSS Variables in Vanilla CSS
57
-
58
- ```css
59
- /* features/resources/components/ResourceCard.css */
60
- .resource-card {
61
- background-color: var(--bg-color);
62
- border: 1px solid var(--border-color);
63
- color: var(--text-color);
64
- }
65
-
66
- .resource-card:hover {
67
- border-color: var(--primary-color);
68
- }
69
- ```
70
-
71
- ### ❌ NEVER Hardcode Colors in Components
72
-
73
- ```tsx
74
- // ❌ BAD
75
- <div style={{ color: '#ff0000' }}>Error</div>
76
-
77
- // ✅ GOOD
78
- <div className="error-text">Error</div> /* defined in CSS using var(--error-color) */
79
- ```
80
-
81
- ## Dark Mode Implementation
82
- Use the `data-theme` attribute on the `html` or `body` tag and sync it with Ant Design's algorithm.
83
-
84
- ## AI Agent Rules
85
-
86
- ### Rule 1: No Hardcoded Colors
87
- Always use `var(--color-name)` in CSS files. Never use hex/rgb values directly in component files.
88
-
89
- ### Rule 2: Semantic Naming
90
- Use functional names like `--primary-color`, `--text-secondary`, not descriptive ones like `--blue`.
91
-
92
- ### Rule 3: Single Source of Truth
93
- Global theme variables must stay in `styles/theme.css`. Components should import their own `.css` files that reference these variables.
@@ -1,97 +0,0 @@
1
- ---
2
- trigger: always_on
3
- ---
4
-
5
- > **SCOPE**: These rules apply specifically to the **client** directory.
6
-
7
- # Frontend Security Rules
8
-
9
- ## Core Security Principles
10
-
11
- 1. **Never trust user input**: Always validate and sanitize data from users.
12
- 2. **Never expose secrets**: API keys, database credentials, and secrets must never be in the client code.
13
- 3. **Always validate and sanitize**: Even if the backend validates, client-side sanitization is essential for UX and defense-in-depth.
14
- 4. **Defense in depth**: Multiple layers of security at every level of the stack.
15
-
16
- ## XSS Prevention
17
-
18
- ### React's Built-in Protection
19
- React automatically escapes values to prevent XSS.
20
-
21
- ```tsx
22
- // ✅ SAFE - React escapes by default
23
- <div>{userInput}</div>
24
-
25
- // ❌ DANGEROUS - Avoid dangerouslySetInnerHTML unless strictly sanitized
26
- <div dangerouslySetInnerHTML={{ __html: userInput }} />
27
- ```
28
-
29
- ### URL Sanitization
30
- Always validate URLs before using them in `href` attributes.
31
-
32
- ```tsx
33
- export const isSafeUrl = (url: string): boolean => {
34
- try {
35
- const parsed = new URL(url);
36
- return ['http:', 'https:', 'mailto:'].includes(parsed.protocol);
37
- } catch {
38
- return false;
39
- }
40
- };
41
- ```
42
-
43
- ## Authentication Token Security
44
-
45
- ### Token Storage
46
- Avoid storing sensitive tokens in `localStorage`. Use Redux for access tokens (in-memory) and `httpOnly` cookies or encrypted storage for long-lived tokens.
47
-
48
- ### Token Transmission
49
- Always use HTTPS and send tokens in the `Authorization` header.
50
-
51
- ```tsx
52
- axios.interceptors.request.use((config) => {
53
- const token = store.getState().auth.tokens?.accessToken;
54
- if (token) {
55
- config.headers.Authorization = `Bearer ${token}`;
56
- }
57
- return config;
58
- });
59
- ```
60
-
61
- ## Input & File Validation
62
-
63
- ### Client + Server Validation
64
- Use Zod for robust client-side validation, matching the backend's expectations.
65
-
66
- ### File Upload Security
67
- Validate file type, size, and extension before uploading.
68
-
69
- ```tsx
70
- const ALLOWED_TYPES = ['image/jpeg', 'image/png', 'image/webp'];
71
- const MAX_SIZE = 5 * 1024 * 1024; // 5MB
72
-
73
- export const validateFile = (file: File) => {
74
- if (!ALLOWED_TYPES.includes(file.type)) return { valid: false, error: 'File type not allowed' };
75
- if (file.size > MAX_SIZE) return { valid: false, error: 'File too large' };
76
- return { valid: true };
77
- };
78
- ```
79
-
80
- ## Environment Variables
81
- - Prefix with `VITE_` for client availability.
82
- - Never commit `.env` files.
83
- - Validate environment variables at runtime using a Zod schema.
84
-
85
- ## AI Agent Security Rules
86
-
87
- ### Rule 1: Never Trust User Input
88
- Never use `dangerouslySetInnerHTML` with raw user input.
89
-
90
- ### Rule 2: Never Expose Secrets
91
- Do not hardcode API keys or credentials. Use `import.meta.env`.
92
-
93
- ### Rule 3: Secure Tokens
94
- Do not recommend plain `localStorage` for sensitive authentication tokens.
95
-
96
- ### Rule 4: Sanitize Content
97
- Sanitize any HTML content with DOMPurify before rendering.