ntc-dev-kit 1.0.0__py3-none-any.whl
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.
- ntc/__init__.py +5 -0
- ntc/app_creator.py +296 -0
- ntc/cli.py +4 -0
- ntc/cli_enhanced.py +820 -0
- ntc/composer/__init__.py +0 -0
- ntc/composer/main.py +443 -0
- ntc/deployment/__init__.py +0 -0
- ntc/templates/__init__.py +2 -0
- ntc/templates/auth_app/__init__.py +0 -0
- ntc/templates/auth_app/admin.py +24 -0
- ntc/templates/auth_app/apps.py +6 -0
- ntc/templates/auth_app/models.py +30 -0
- ntc/templates/auth_app/serializers.py +101 -0
- ntc/templates/auth_app/urls.py +19 -0
- ntc/templates/auth_app/views.py +175 -0
- ntc/templates/drf_structure/__init__.py +1 -0
- ntc/templates/drf_structure/drf_structure.md +83 -0
- ntc/templates/drf_structure/main.py +389 -0
- ntc/templates/drf_structure/structure.json +126 -0
- ntc/templates/drf_structure/templates/.entry/start_core_backend.sh +37 -0
- ntc/templates/drf_structure/templates/.entry/start_tasks_backend.sh +30 -0
- ntc/templates/drf_structure/templates/CLAUDE.md +194 -0
- ntc/templates/drf_structure/templates/README.md +117 -0
- ntc/templates/drf_structure/templates/apps/app_admin.py +3 -0
- ntc/templates/drf_structure/templates/apps/app_apps.py +6 -0
- ntc/templates/drf_structure/templates/apps/app_models.py +4 -0
- ntc/templates/drf_structure/templates/apps/app_urls.py +8 -0
- ntc/templates/drf_structure/templates/apps/app_views.py +6 -0
- ntc/templates/drf_structure/templates/apps/common_apps.py +6 -0
- ntc/templates/drf_structure/templates/apps/common_models.py +8 -0
- ntc/templates/drf_structure/templates/config/gunicorn_config.py +9 -0
- ntc/templates/drf_structure/templates/config/http.conf +33 -0
- ntc/templates/drf_structure/templates/core/base_model.py +9 -0
- ntc/templates/drf_structure/templates/core/formatter.py +5 -0
- ntc/templates/drf_structure/templates/core/logger.py +8 -0
- ntc/templates/drf_structure/templates/core/pagination.py +6 -0
- ntc/templates/drf_structure/templates/core/response_wrapper.py +7 -0
- ntc/templates/drf_structure/templates/core/services/azure/email/backend.py +108 -0
- ntc/templates/drf_structure/templates/core/services/azure/email/client.py +296 -0
- ntc/templates/drf_structure/templates/core/services/azure/email/notifier.py +102 -0
- ntc/templates/drf_structure/templates/core/services/object_storage.py +285 -0
- ntc/templates/drf_structure/templates/django_project/asgi.py +5 -0
- ntc/templates/drf_structure/templates/django_project/celery.py +8 -0
- ntc/templates/drf_structure/templates/django_project/dev_settings.py +2 -0
- ntc/templates/drf_structure/templates/django_project/django_settings.txt +322 -0
- ntc/templates/drf_structure/templates/django_project/management_command.py +114 -0
- ntc/templates/drf_structure/templates/django_project/prod_settings.py +3 -0
- ntc/templates/drf_structure/templates/django_project/schema.py +7 -0
- ntc/templates/drf_structure/templates/django_project/urls.py +6 -0
- ntc/templates/drf_structure/templates/django_project/wsgi.py +5 -0
- ntc/templates/drf_structure/templates/docker/docker-compose.yml +11 -0
- ntc/templates/drf_structure/templates/knowledge/knowledge_description.md +201 -0
- ntc/templates/drf_structure/templates/knowledge/knowledge_design_pattern.md +722 -0
- ntc/templates/drf_structure/templates/knowledge/knowledge_structure.md +151 -0
- ntc/templates/drf_structure/templates/root/README.md +307 -0
- ntc/templates/drf_structure/templates/root/django_env.txt +98 -0
- ntc/templates/drf_structure/templates/root/django_requirements.txt +24 -0
- ntc/templates/drf_structure/templates/root/gitignore.txt +6 -0
- ntc/templates/drf_structure/templates/root/manage.py +11 -0
- ntc/templates/flutter/.gitignore +44 -0
- ntc/templates/flutter/.knowledge/knowledge_description.md +215 -0
- ntc/templates/flutter/.knowledge/knowledge_design_pattern.md +310 -0
- ntc/templates/flutter/.knowledge/knowledge_structure.md +83 -0
- ntc/templates/flutter/CLAUDE.md +190 -0
- ntc/templates/flutter/__init__.py +0 -0
- ntc/templates/flutter/analysis_options.yaml +9 -0
- ntc/templates/flutter/main.py +187 -0
- ntc/templates/flutter/pubspec.yaml +65 -0
- ntc/templates/flutter/structure.json +51 -0
- ntc/templates/nextjs/.env.example +10 -0
- ntc/templates/nextjs/.gitignore +36 -0
- ntc/templates/nextjs/CLAUDE.md +181 -0
- ntc/templates/nextjs/README.md +94 -0
- ntc/templates/nextjs/__init__.py +0 -0
- ntc/templates/nextjs/knowledge/knowledge_description.md +208 -0
- ntc/templates/nextjs/knowledge/knowledge_design_pattern.md +460 -0
- ntc/templates/nextjs/knowledge/knowledge_structure.md +75 -0
- ntc/templates/nextjs/main.py +224 -0
- ntc/templates/nextjs/package.json +25 -0
- ntc/templates/nextjs/src/app/globals.css +26 -0
- ntc/templates/nextjs/src/app/layout.tsx +59 -0
- ntc/templates/nextjs/src/app/page.tsx +21 -0
- ntc/templates/nextjs/src/components/Header.tsx +16 -0
- ntc/templates/nextjs/src/services/api.ts +81 -0
- ntc/templates/nextjs/src/utils/constants.ts +1 -0
- ntc/templates/nextjs/structure.json +32 -0
- ntc/templates/nextjs/tsconfig.json +27 -0
- ntc/templates/react_admin/.env.example +1 -0
- ntc/templates/react_admin/.gitignore +10 -0
- ntc/templates/react_admin/CLAUDE.md +210 -0
- ntc/templates/react_admin/README.md +72 -0
- ntc/templates/react_admin/__init__.py +0 -0
- ntc/templates/react_admin/index.html +13 -0
- ntc/templates/react_admin/knowledge/knowledge_description.md +202 -0
- ntc/templates/react_admin/knowledge/knowledge_design_pattern.md +448 -0
- ntc/templates/react_admin/knowledge/knowledge_structure.md +97 -0
- ntc/templates/react_admin/main.py +208 -0
- ntc/templates/react_admin/package.json +35 -0
- ntc/templates/react_admin/src/App.tsx +60 -0
- ntc/templates/react_admin/src/components/ProtectedRoute.tsx +16 -0
- ntc/templates/react_admin/src/components/Sidebar.tsx +90 -0
- ntc/templates/react_admin/src/components/TopNav.tsx +44 -0
- ntc/templates/react_admin/src/context/AuthContext.tsx +107 -0
- ntc/templates/react_admin/src/context/ThemeContext.tsx +34 -0
- ntc/templates/react_admin/src/context/WorkspaceContext.tsx +28 -0
- ntc/templates/react_admin/src/hooks/useApi.ts +39 -0
- ntc/templates/react_admin/src/index.css +34 -0
- ntc/templates/react_admin/src/layouts/AuthLayout.tsx +23 -0
- ntc/templates/react_admin/src/layouts/DashboardLayout.tsx +24 -0
- ntc/templates/react_admin/src/main.tsx +5 -0
- ntc/templates/react_admin/src/pages/DashboardPage.tsx +10 -0
- ntc/templates/react_admin/src/pages/auth/LoginPage.tsx +79 -0
- ntc/templates/react_admin/src/pages/auth/RegisterPage.tsx +93 -0
- ntc/templates/react_admin/src/services/api.service.ts +44 -0
- ntc/templates/react_admin/src/services/base.service.ts +193 -0
- ntc/templates/react_admin/structure.json +52 -0
- ntc/templates/react_admin/tsconfig.app.json +25 -0
- ntc/templates/react_admin/tsconfig.json +7 -0
- ntc/templates/react_admin/tsconfig.node.json +19 -0
- ntc/templates/react_admin/vite.config.ts +13 -0
- ntc/templates/react_structure/CLAUDE.md +176 -0
- ntc/templates/react_structure/__init__.py +1 -0
- ntc/templates/react_structure/index.css +21 -0
- ntc/templates/react_structure/index.html +13 -0
- ntc/templates/react_structure/knowledge/knowledge_description.md +170 -0
- ntc/templates/react_structure/knowledge/knowledge_design_pattern.md +411 -0
- ntc/templates/react_structure/knowledge/knowledge_structure.md +74 -0
- ntc/templates/react_structure/main.py +217 -0
- ntc/templates/react_structure/package.json +32 -0
- ntc/templates/react_structure/src/App.tsx +63 -0
- ntc/templates/react_structure/src/components/Header.tsx +51 -0
- ntc/templates/react_structure/src/main.tsx +5 -0
- ntc/templates/react_structure/src/services/api.ts +90 -0
- ntc/templates/react_structure/src/utils/constants.ts +1 -0
- ntc/templates/react_structure/structure.json +65 -0
- ntc/templates/react_structure/tsconfig.app.json +25 -0
- ntc/templates/react_structure/tsconfig.json +7 -0
- ntc/templates/react_structure/tsconfig.node.json +19 -0
- ntc/templates/react_structure/vite.config.ts +12 -0
- ntc/utils/__init__.py +1 -0
- ntc/utils/environment.py +67 -0
- ntc/utils/output.py +41 -0
- ntc_dev_kit-1.0.0.dist-info/METADATA +188 -0
- ntc_dev_kit-1.0.0.dist-info/RECORD +148 -0
- ntc_dev_kit-1.0.0.dist-info/WHEEL +5 -0
- ntc_dev_kit-1.0.0.dist-info/entry_points.txt +2 -0
- ntc_dev_kit-1.0.0.dist-info/licenses/LICENSE +21 -0
- ntc_dev_kit-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
# Design Patterns and Coding Conventions - {project_name}
|
|
2
|
+
|
|
3
|
+
This document describes the design patterns and coding conventions used in this NTC-generated React Admin Dashboard project.
|
|
4
|
+
|
|
5
|
+
## 🎨 Component Design Patterns
|
|
6
|
+
|
|
7
|
+
### Functional Component Pattern
|
|
8
|
+
```typescript
|
|
9
|
+
interface ComponentProps {
|
|
10
|
+
title: string
|
|
11
|
+
onAction: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Component: React.FC<ComponentProps> = ({ title, onAction }) => {
|
|
15
|
+
// Component logic
|
|
16
|
+
return <div>{title}</div>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default Component
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Custom Hook Pattern
|
|
23
|
+
```typescript
|
|
24
|
+
const useCustomHook = (param: string) => {
|
|
25
|
+
const [state, setState] = useState<string>('')
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
// Effect logic
|
|
29
|
+
}, [param])
|
|
30
|
+
|
|
31
|
+
return state
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Context Provider Pattern
|
|
36
|
+
```typescript
|
|
37
|
+
interface ContextType {
|
|
38
|
+
value: string
|
|
39
|
+
setValue: (value: string) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const MyContext = createContext<ContextType | undefined>(undefined)
|
|
43
|
+
|
|
44
|
+
export const MyProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
45
|
+
const [value, setValue] = useState('')
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<MyContext.Provider value={{ value, setValue }}>
|
|
49
|
+
{children}
|
|
50
|
+
</MyContext.Provider>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const useMyContext = () => {
|
|
55
|
+
const context = useContext(MyContext)
|
|
56
|
+
if (!context) {
|
|
57
|
+
throw new Error('useMyContext must be used within MyProvider')
|
|
58
|
+
}
|
|
59
|
+
return context
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Protected Route Pattern
|
|
64
|
+
```typescript
|
|
65
|
+
const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
66
|
+
const { isAuthenticated } = useAuth()
|
|
67
|
+
const navigate = useNavigate()
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!isAuthenticated) {
|
|
71
|
+
navigate('/login')
|
|
72
|
+
}
|
|
73
|
+
}, [isAuthenticated, navigate])
|
|
74
|
+
|
|
75
|
+
if (!isAuthenticated) {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return <>{children}</>
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 🔧 Service Layer Pattern
|
|
84
|
+
|
|
85
|
+
### Base Service Pattern
|
|
86
|
+
```typescript
|
|
87
|
+
const baseService = {
|
|
88
|
+
get: <T>(url: string, config = {}) => axios.get<T>(url, config),
|
|
89
|
+
post: <T>(url: string, data = {}, config = {}) => axios.post<T>(url, data, config),
|
|
90
|
+
// ... other methods
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### API Service Pattern
|
|
95
|
+
```typescript
|
|
96
|
+
interface User {
|
|
97
|
+
id: string
|
|
98
|
+
name: string
|
|
99
|
+
email: string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const apiService = {
|
|
103
|
+
getUsers: () => baseService.get<User[]>('/users'),
|
|
104
|
+
getUser: (id: string) => baseService.get<User>(`/users/${id}`),
|
|
105
|
+
createUser: (data: Partial<User>) => baseService.post<User>('/users', data),
|
|
106
|
+
// ... other methods
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📝 TypeScript Patterns
|
|
111
|
+
|
|
112
|
+
### Interface for Props
|
|
113
|
+
```typescript
|
|
114
|
+
interface ButtonProps {
|
|
115
|
+
label: string
|
|
116
|
+
onClick: () => void
|
|
117
|
+
disabled?: boolean
|
|
118
|
+
variant?: 'primary' | 'secondary'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const Button: React.FC<ButtonProps> = ({ label, onClick, disabled = false, variant = 'primary' }) => {
|
|
122
|
+
return <button onClick={onClick} disabled={disabled}>{label}</button>
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Type Guards
|
|
127
|
+
```typescript
|
|
128
|
+
const isString = (value: unknown): value is string => {
|
|
129
|
+
return typeof value === 'string'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const processValue = (value: unknown) => {
|
|
133
|
+
if (isString(value)) {
|
|
134
|
+
return value.toUpperCase()
|
|
135
|
+
}
|
|
136
|
+
return 'DEFAULT'
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Generic Types
|
|
141
|
+
```typescript
|
|
142
|
+
interface ApiResponse<T> {
|
|
143
|
+
data: T
|
|
144
|
+
status: number
|
|
145
|
+
message: string
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const fetchData = async <T>(url: string): Promise<ApiResponse<T>> => {
|
|
149
|
+
const response = await baseService.get<ApiResponse<T>>(url)
|
|
150
|
+
return response.data
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 🎯 State Management Patterns
|
|
155
|
+
|
|
156
|
+
### TanStack Query Pattern
|
|
157
|
+
```typescript
|
|
158
|
+
const useData = (id: string) => {
|
|
159
|
+
return useQuery({
|
|
160
|
+
queryKey: ['data', id],
|
|
161
|
+
queryFn: () => apiService.getData(id),
|
|
162
|
+
enabled: !!id,
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const useMutationData = () => {
|
|
167
|
+
const queryClient = useQueryClient()
|
|
168
|
+
|
|
169
|
+
return useMutation({
|
|
170
|
+
mutationFn: (data: DataType) => apiService.createData(data),
|
|
171
|
+
onSuccess: () => {
|
|
172
|
+
queryClient.invalidateQueries({ queryKey: ['data'] })
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Context Pattern
|
|
179
|
+
```typescript
|
|
180
|
+
const AuthContext = createContext<AuthContextType | undefined>(undefined)
|
|
181
|
+
|
|
182
|
+
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
183
|
+
const [user, setUser] = useState<User | null>(null)
|
|
184
|
+
const [token, setToken] = useState<string | null>(null)
|
|
185
|
+
|
|
186
|
+
const login = async (credentials: LoginCredentials) => {
|
|
187
|
+
const response = await apiService.login(credentials)
|
|
188
|
+
setToken(response.data.token)
|
|
189
|
+
setUser(response.data.user)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const logout = () => {
|
|
193
|
+
setToken(null)
|
|
194
|
+
setUser(null)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<AuthContext.Provider value={{ user, token, login, logout, isAuthenticated: !!token }}>
|
|
199
|
+
{children}
|
|
200
|
+
</AuthContext.Provider>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## 🔄 Async Pattern with TanStack Query
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const Component: React.FC = () => {
|
|
209
|
+
const { data, isLoading, error } = useQuery({
|
|
210
|
+
queryKey: ['items'],
|
|
211
|
+
queryFn: () => apiService.getItems(),
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const mutation = useMutation({
|
|
215
|
+
mutationFn: (item: Item) => apiService.createItem(item),
|
|
216
|
+
onSuccess: () => {
|
|
217
|
+
queryClient.invalidateQueries({ queryKey: ['items'] })
|
|
218
|
+
},
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
if (isLoading) return <LoadingSpinner />
|
|
222
|
+
if (error) return <ErrorMessage error={error} />
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<div>
|
|
226
|
+
{data?.map(item => <div key={item.id}>{item.name}</div>)}
|
|
227
|
+
<button onClick={() => mutation.mutate({ name: 'New Item' })}>
|
|
228
|
+
Add Item
|
|
229
|
+
</button>
|
|
230
|
+
</div>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 🎨 Layout Pattern
|
|
236
|
+
|
|
237
|
+
### Dashboard Layout Pattern
|
|
238
|
+
```typescript
|
|
239
|
+
const DashboardLayout: React.FC = () => {
|
|
240
|
+
const [sidebarCollapsed, setSidebarCollapsed] = useState(false)
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<div className="dashboard-layout">
|
|
244
|
+
<Sidebar collapsed={sidebarCollapsed} onToggle={() => setSidebarCollapsed(!sidebarCollapsed)} />
|
|
245
|
+
<div className={`main-content ${sidebarCollapsed ? 'collapsed' : ''}`}>
|
|
246
|
+
<TopNav />
|
|
247
|
+
<main>
|
|
248
|
+
<Outlet />
|
|
249
|
+
</main>
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Auth Layout Pattern
|
|
257
|
+
```typescript
|
|
258
|
+
const AuthLayout: React.FC = () => {
|
|
259
|
+
const { isAuthenticated } = useAuth()
|
|
260
|
+
const navigate = useNavigate()
|
|
261
|
+
|
|
262
|
+
useEffect(() => {
|
|
263
|
+
if (isAuthenticated) {
|
|
264
|
+
navigate('/dashboard')
|
|
265
|
+
}
|
|
266
|
+
}, [isAuthenticated, navigate])
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<div className="auth-layout">
|
|
270
|
+
<Outlet />
|
|
271
|
+
</div>
|
|
272
|
+
)
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## 📦 File Organization Patterns
|
|
277
|
+
|
|
278
|
+
### Feature-Based Structure
|
|
279
|
+
```
|
|
280
|
+
src/
|
|
281
|
+
├── features/
|
|
282
|
+
│ ├── users/
|
|
283
|
+
│ │ ├── components/
|
|
284
|
+
│ │ ├── services/
|
|
285
|
+
│ │ └── types/
|
|
286
|
+
│ └── settings/
|
|
287
|
+
│ ├── components/
|
|
288
|
+
│ ├── services/
|
|
289
|
+
│ └── types/
|
|
290
|
+
├── components/ (shared)
|
|
291
|
+
├── services/ (shared)
|
|
292
|
+
└── utils/ (shared)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Type-Based Structure (Current)
|
|
296
|
+
```
|
|
297
|
+
src/
|
|
298
|
+
├── components/ (shared UI)
|
|
299
|
+
├── context/ (global state)
|
|
300
|
+
├── layouts/ (layout components)
|
|
301
|
+
├── pages/ (page components)
|
|
302
|
+
├── services/ (API services)
|
|
303
|
+
├── hooks/ (custom hooks)
|
|
304
|
+
└── utils/ (utilities)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## 🔒 Error Handling Patterns
|
|
308
|
+
|
|
309
|
+
### TanStack Query Error Handling
|
|
310
|
+
```typescript
|
|
311
|
+
const { data, error } = useQuery({
|
|
312
|
+
queryKey: ['items'],
|
|
313
|
+
queryFn: () => apiService.getItems(),
|
|
314
|
+
retry: 3,
|
|
315
|
+
onError: (error) => {
|
|
316
|
+
console.error('Failed to fetch items:', error)
|
|
317
|
+
},
|
|
318
|
+
})
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Service Error Handling
|
|
322
|
+
```typescript
|
|
323
|
+
try {
|
|
324
|
+
const response = await baseService.get('/endpoint')
|
|
325
|
+
return response.data
|
|
326
|
+
} catch (error) {
|
|
327
|
+
console.error('API Error:', error)
|
|
328
|
+
throw error
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## 🚀 Performance Patterns
|
|
333
|
+
|
|
334
|
+
### TanStack Query Caching
|
|
335
|
+
```typescript
|
|
336
|
+
const { data } = useQuery({
|
|
337
|
+
queryKey: ['items'],
|
|
338
|
+
queryFn: () => apiService.getItems(),
|
|
339
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
340
|
+
cacheTime: 10 * 60 * 1000, // 10 minutes
|
|
341
|
+
})
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Memo Pattern
|
|
345
|
+
```typescript
|
|
346
|
+
const ExpensiveComponent: React.FC<{ data: DataType }> = React.memo(({ data }) => {
|
|
347
|
+
return <div>{data.name}</div>
|
|
348
|
+
})
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## 🧐 Routing Patterns
|
|
352
|
+
|
|
353
|
+
### Nested Routes Pattern
|
|
354
|
+
```typescript
|
|
355
|
+
<Route path="/" element={<DashboardLayout />}>
|
|
356
|
+
<Route index element={<DashboardPage />} />
|
|
357
|
+
<Route path="users" element={<UsersPage />} />
|
|
358
|
+
<Route path="settings" element={<SettingsPage />} />
|
|
359
|
+
</Route>
|
|
360
|
+
|
|
361
|
+
<Route path="/auth" element={<AuthLayout />}>
|
|
362
|
+
<Route path="login" element={<LoginPage />} />
|
|
363
|
+
<Route path="register" element={<RegisterPage />} />
|
|
364
|
+
</Route>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Protected Routes Pattern
|
|
368
|
+
```typescript
|
|
369
|
+
<Route
|
|
370
|
+
path="/dashboard"
|
|
371
|
+
element={
|
|
372
|
+
<ProtectedRoute>
|
|
373
|
+
<DashboardPage />
|
|
374
|
+
</ProtectedRoute>
|
|
375
|
+
}
|
|
376
|
+
/>
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## 📐 Naming Conventions
|
|
380
|
+
|
|
381
|
+
### Components
|
|
382
|
+
- **File**: `PascalCase.tsx` (e.g., `UserProfile.tsx`)
|
|
383
|
+
- **Component**: `PascalCase` (e.g., `UserProfile`)
|
|
384
|
+
- **Props Interface**: `ComponentProps` (e.g., `UserProfileProps`)
|
|
385
|
+
|
|
386
|
+
### Pages
|
|
387
|
+
- **File**: `PascalCasePage.tsx` (e.g., `DashboardPage.tsx`)
|
|
388
|
+
- **Component**: `PascalCase` with `Page` suffix (e.g., `DashboardPage`)
|
|
389
|
+
|
|
390
|
+
### Contexts
|
|
391
|
+
- **File**: `PascalContext.tsx` (e.g., `AuthContext.tsx`)
|
|
392
|
+
- **Context**: `PascalContext` (e.g., `AuthContext`)
|
|
393
|
+
- **Hook**: `usePascal` (e.g., `useAuth`)
|
|
394
|
+
|
|
395
|
+
### Hooks
|
|
396
|
+
- **File**: `camelCase.ts` (e.g., `useUserProfile.ts`)
|
|
397
|
+
- **Hook**: `camelCase` starting with `use` (e.g., `useUserProfile`)
|
|
398
|
+
|
|
399
|
+
### Services
|
|
400
|
+
- **File**: `camelCase.service.ts` (e.g., `api.service.ts`)
|
|
401
|
+
- **Service**: `camelCase` (e.g., `apiService`)
|
|
402
|
+
|
|
403
|
+
### Types
|
|
404
|
+
- **File**: `PascalCase.types.ts` (e.g., `User.types.ts`)
|
|
405
|
+
- **Interface**: `PascalCase` (e.g., `UserProfile`)
|
|
406
|
+
- **Type**: `PascalCase` (e.g., `ApiResponse`)
|
|
407
|
+
|
|
408
|
+
### Constants
|
|
409
|
+
- **File**: `camelCase.ts` (e.g., `constants.ts`)
|
|
410
|
+
- **Constant**: `UPPER_SNAKE_CASE` (e.g., `API_BASE_URL`)
|
|
411
|
+
|
|
412
|
+
## 🎯 Best Practices
|
|
413
|
+
|
|
414
|
+
### Code Organization
|
|
415
|
+
1. Keep components small and focused
|
|
416
|
+
2. Extract reusable logic into custom hooks
|
|
417
|
+
3. Use TypeScript interfaces for all props
|
|
418
|
+
4. Organize imports (external, internal, types)
|
|
419
|
+
5. Use path aliases (`@/`) for internal imports
|
|
420
|
+
|
|
421
|
+
### Performance
|
|
422
|
+
1. Use TanStack Query for server state caching
|
|
423
|
+
2. Use React.memo for expensive components
|
|
424
|
+
3. Implement code splitting with React.lazy
|
|
425
|
+
4. Optimize images and assets
|
|
426
|
+
5. Avoid unnecessary re-renders
|
|
427
|
+
|
|
428
|
+
### Accessibility
|
|
429
|
+
1. Use semantic HTML elements
|
|
430
|
+
2. Provide alt text for images
|
|
431
|
+
3. Ensure keyboard navigation
|
|
432
|
+
4. Use ARIA labels where needed
|
|
433
|
+
5. Test with screen readers
|
|
434
|
+
|
|
435
|
+
### Security
|
|
436
|
+
1. Sanitize user input
|
|
437
|
+
2. Use HTTPS in production
|
|
438
|
+
3. Validate data on client and server
|
|
439
|
+
4. Never expose sensitive data
|
|
440
|
+
5. Use environment variables for secrets
|
|
441
|
+
6. Protect routes with authentication
|
|
442
|
+
|
|
443
|
+
### TanStack Query Best Practices
|
|
444
|
+
1. Use meaningful query keys
|
|
445
|
+
2. Implement proper error handling
|
|
446
|
+
3. Configure staleTime and cacheTime
|
|
447
|
+
4. Use optimistic updates for mutations
|
|
448
|
+
5. Implement retry logic for failed requests
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Project Structure - {project_name}
|
|
2
|
+
|
|
3
|
+
This document describes the complete project structure and organization for AI assistants to understand how to work with this codebase.
|
|
4
|
+
|
|
5
|
+
## 📁 Root Directory Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
{project_name}/
|
|
9
|
+
├── .env.example # Environment variables example
|
|
10
|
+
├── .gitignore # Git ignore patterns
|
|
11
|
+
├── .knowledge/ # AI documentation (this directory)
|
|
12
|
+
├── index.html # HTML entry point
|
|
13
|
+
├── package.json # Node.js dependencies
|
|
14
|
+
├── tsconfig.json # TypeScript configuration
|
|
15
|
+
├── tsconfig.app.json # TypeScript app configuration
|
|
16
|
+
├── tsconfig.node.json # TypeScript node configuration
|
|
17
|
+
├── vite.config.ts # Vite build configuration
|
|
18
|
+
├── README.md # Project documentation
|
|
19
|
+
└── src/ # Source code
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 🏗️ Source Directory Structure (`src/`)
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
src/
|
|
26
|
+
├── main.tsx # Application entry point
|
|
27
|
+
├── App.tsx # Root component with routing
|
|
28
|
+
├── index.css # Global styles
|
|
29
|
+
├── components/ # Reusable UI components
|
|
30
|
+
│ ├── ProtectedRoute.tsx # Route protection wrapper
|
|
31
|
+
│ ├── Sidebar.tsx # Sidebar navigation
|
|
32
|
+
│ └── TopNav.tsx # Top navigation bar
|
|
33
|
+
├── context/ # React Context providers
|
|
34
|
+
│ ├── AuthContext.tsx # Authentication state
|
|
35
|
+
│ ├── ThemeContext.tsx # Theme state
|
|
36
|
+
│ └── WorkspaceContext.tsx # Workspace state
|
|
37
|
+
├── layouts/ # Layout components
|
|
38
|
+
│ ├── DashboardLayout.tsx # Main dashboard layout
|
|
39
|
+
│ └── AuthLayout.tsx # Authentication layout
|
|
40
|
+
├── pages/ # Page components
|
|
41
|
+
│ ├── auth/ # Authentication pages
|
|
42
|
+
│ │ ├── LoginPage.tsx
|
|
43
|
+
│ │ └── RegisterPage.tsx
|
|
44
|
+
│ └── DashboardPage.tsx # Dashboard page
|
|
45
|
+
├── services/ # API and external services
|
|
46
|
+
│ ├── base.service.ts # Axios base service
|
|
47
|
+
│ └── api.service.ts # Typed API endpoints
|
|
48
|
+
├── hooks/ # Custom React hooks
|
|
49
|
+
│ └── useApi.ts # TanStack Query hooks
|
|
50
|
+
└── utils/ # Utility functions
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 🎯 Key Conventions
|
|
54
|
+
|
|
55
|
+
### File Naming
|
|
56
|
+
- **Components**: `PascalCase` with `.tsx` extension (e.g., `UserProfile.tsx`)
|
|
57
|
+
- **Pages**: `PascalCase` with `Page` suffix (e.g., `DashboardPage.tsx`)
|
|
58
|
+
- **Contexts**: `PascalCase` with `Context` suffix (e.g., `AuthContext.tsx`)
|
|
59
|
+
- **Services**: `camelCase` with `.service.ts` extension (e.g., `api.service.ts`)
|
|
60
|
+
- **Hooks**: `camelCase` with `.ts` extension (e.g., `useApi.ts`)
|
|
61
|
+
- **Types**: `PascalCase` with `.ts` extension (e.g., `UserTypes.ts`)
|
|
62
|
+
|
|
63
|
+
### Import Patterns
|
|
64
|
+
- **Components**: `import Component from '@/components/Component'`
|
|
65
|
+
- **Services**: `import { apiService } from '@/services/api.service'`
|
|
66
|
+
- **Contexts**: `import { useAuth } from '@/context/AuthContext'`
|
|
67
|
+
- **Hooks**: `import { useApi } from '@/hooks/useApi'`
|
|
68
|
+
- **Utils**: `import { CONSTANT } from '@/utils/constants'`
|
|
69
|
+
|
|
70
|
+
### TypeScript Patterns
|
|
71
|
+
- **Props Interface**: Always define interfaces for component props
|
|
72
|
+
- **Generic Types**: Use generics when appropriate for reusable components
|
|
73
|
+
- **Strict Mode**: TypeScript strict mode is enabled
|
|
74
|
+
- **No Any**: Avoid using `any` type, use `unknown` or proper types instead
|
|
75
|
+
|
|
76
|
+
## 🔄 Development Workflow
|
|
77
|
+
|
|
78
|
+
1. **Install dependencies**: `npm install`
|
|
79
|
+
2. **Run development server**: `npm run dev`
|
|
80
|
+
3. **Build for production**: `npm run build`
|
|
81
|
+
4. **Preview production build**: `npm run preview`
|
|
82
|
+
5. **Run linter**: `npm run lint`
|
|
83
|
+
|
|
84
|
+
## 📋 Important Notes for AI
|
|
85
|
+
|
|
86
|
+
- **Always use TypeScript** with proper type definitions
|
|
87
|
+
- **Follow the component structure** when creating new components
|
|
88
|
+
- **Use the apiService** for all API calls
|
|
89
|
+
- **Use TanStack Query** for data fetching and caching
|
|
90
|
+
- **Handle loading and error states** in async operations
|
|
91
|
+
- **Use environment variables** via `import.meta.env.VITE_*`
|
|
92
|
+
- **Path aliases**: Use `@` for `src/` directory imports
|
|
93
|
+
- **Vite**: This project uses Vite as the build tool
|
|
94
|
+
- **Port**: Development server runs on http://localhost:5173
|
|
95
|
+
- **React Router v7**: Uses the latest React Router for routing
|
|
96
|
+
- **Context API**: Use React Context for global state management
|
|
97
|
+
- **Protected Routes**: Use `ProtectedRoute` component for authenticated pages
|