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,460 @@
|
|
|
1
|
+
# Design Patterns and Coding Conventions - {project_name}
|
|
2
|
+
|
|
3
|
+
This document describes the design patterns and coding conventions used in this NTC-generated Next.js project.
|
|
4
|
+
|
|
5
|
+
## 🎨 Component Design Patterns
|
|
6
|
+
|
|
7
|
+
### Server Component Pattern
|
|
8
|
+
```typescript
|
|
9
|
+
// Default: Server Component (no 'use client' directive)
|
|
10
|
+
interface ComponentProps {
|
|
11
|
+
title: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Component = ({ title }: ComponentProps) => {
|
|
15
|
+
// Server-side logic
|
|
16
|
+
return <div>{title}</div>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default Component
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Client Component Pattern
|
|
23
|
+
```typescript
|
|
24
|
+
'use client'
|
|
25
|
+
|
|
26
|
+
import { useState } from 'react'
|
|
27
|
+
|
|
28
|
+
interface ComponentProps {
|
|
29
|
+
title: string
|
|
30
|
+
onAction: () => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const Component = ({ title, onAction }: ComponentProps) => {
|
|
34
|
+
const [count, setCount] = useState(0)
|
|
35
|
+
|
|
36
|
+
return <div>{title}</div>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default Component
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Custom Hook Pattern
|
|
43
|
+
```typescript
|
|
44
|
+
'use client'
|
|
45
|
+
|
|
46
|
+
const useCustomHook = (param: string) => {
|
|
47
|
+
const [state, setState] = useState<string>('')
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
// Effect logic
|
|
51
|
+
}, [param])
|
|
52
|
+
|
|
53
|
+
return state
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 🔧 Service Layer Pattern
|
|
58
|
+
|
|
59
|
+
### API Service Pattern
|
|
60
|
+
```typescript
|
|
61
|
+
const apiService = {
|
|
62
|
+
get: (url: string, config = {}) => apiClient.get(url, config),
|
|
63
|
+
post: (url: string, data = {}, config = {}) => apiClient.post(url, data, config),
|
|
64
|
+
// ... other methods
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Auth Service Pattern
|
|
69
|
+
```typescript
|
|
70
|
+
export const authService = {
|
|
71
|
+
login: async (credentials: LoginCredentials) => {
|
|
72
|
+
const response = await apiService.post('/auth/login/', credentials)
|
|
73
|
+
if (response.data.token) {
|
|
74
|
+
localStorage.setItem('authToken', response.data.token)
|
|
75
|
+
}
|
|
76
|
+
return response
|
|
77
|
+
},
|
|
78
|
+
logout: () => {
|
|
79
|
+
localStorage.removeItem('authToken')
|
|
80
|
+
},
|
|
81
|
+
// ... other methods
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 📝 TypeScript Patterns
|
|
86
|
+
|
|
87
|
+
### Interface for Props
|
|
88
|
+
```typescript
|
|
89
|
+
interface ButtonProps {
|
|
90
|
+
label: string
|
|
91
|
+
onClick: () => void
|
|
92
|
+
disabled?: boolean
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const Button = ({ label, onClick, disabled = false }: ButtonProps) => {
|
|
96
|
+
return <button onClick={onClick} disabled={disabled}>{label}</button>
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Type Guards
|
|
101
|
+
```typescript
|
|
102
|
+
const isString = (value: unknown): value is string => {
|
|
103
|
+
return typeof value === 'string'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const processValue = (value: unknown) => {
|
|
107
|
+
if (isString(value)) {
|
|
108
|
+
return value.toUpperCase()
|
|
109
|
+
}
|
|
110
|
+
return 'DEFAULT'
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Generic Types
|
|
115
|
+
```typescript
|
|
116
|
+
interface ApiResponse<T> {
|
|
117
|
+
data: T
|
|
118
|
+
status: number
|
|
119
|
+
message: string
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const fetchData = async <T>(url: string): Promise<ApiResponse<T>> => {
|
|
123
|
+
const response = await apiService.get<ApiResponse<T>>(url)
|
|
124
|
+
return response.data
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 🎯 State Management Patterns
|
|
129
|
+
|
|
130
|
+
### Server Component State
|
|
131
|
+
```typescript
|
|
132
|
+
// Server Components can fetch data directly
|
|
133
|
+
const Component = async ({ id }: { id: string }) => {
|
|
134
|
+
const data = await fetchData(id)
|
|
135
|
+
|
|
136
|
+
return <div>{data.name}</div>
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Client Component State
|
|
141
|
+
```typescript
|
|
142
|
+
'use client'
|
|
143
|
+
|
|
144
|
+
const Component = () => {
|
|
145
|
+
const [count, setCount] = useState(0)
|
|
146
|
+
const [loading, setLoading] = useState(false)
|
|
147
|
+
|
|
148
|
+
const increment = () => setCount(prev => prev + 1)
|
|
149
|
+
|
|
150
|
+
return <div>{count}</div>
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Context Pattern (Client Only)
|
|
155
|
+
```typescript
|
|
156
|
+
'use client'
|
|
157
|
+
|
|
158
|
+
interface AppContextType {
|
|
159
|
+
user: User | null
|
|
160
|
+
setUser: (user: User | null) => void
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const AppContext = createContext<AppContextType | undefined>(undefined)
|
|
164
|
+
|
|
165
|
+
export const AppProvider = ({ children }: { children: React.ReactNode }) => {
|
|
166
|
+
const [user, setUser] = useState<User | null>(null)
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<AppContext.Provider value={{ user, setUser }}>
|
|
170
|
+
{children}
|
|
171
|
+
</AppContext.Provider>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const useApp = () => {
|
|
176
|
+
const context = useContext(AppContext)
|
|
177
|
+
if (!context) {
|
|
178
|
+
throw new Error('useApp must be used within AppProvider')
|
|
179
|
+
}
|
|
180
|
+
return context
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## 🔄 Async Pattern
|
|
185
|
+
|
|
186
|
+
### Server Component Async
|
|
187
|
+
```typescript
|
|
188
|
+
const Component = async () => {
|
|
189
|
+
const data = await fetchData()
|
|
190
|
+
|
|
191
|
+
return <div>{data.name}</div>
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Client Component Async
|
|
196
|
+
```typescript
|
|
197
|
+
'use client'
|
|
198
|
+
|
|
199
|
+
const Component = () => {
|
|
200
|
+
const [data, setData] = useState<Data | null>(null)
|
|
201
|
+
const [error, setError] = useState<string | null>(null)
|
|
202
|
+
const [loading, setLoading] = useState(false)
|
|
203
|
+
|
|
204
|
+
const fetchData = async () => {
|
|
205
|
+
setLoading(true)
|
|
206
|
+
setError(null)
|
|
207
|
+
try {
|
|
208
|
+
const response = await apiService.get('/endpoint')
|
|
209
|
+
setData(response.data)
|
|
210
|
+
} catch (err) {
|
|
211
|
+
setError('Failed to fetch data')
|
|
212
|
+
} finally {
|
|
213
|
+
setLoading(false)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
fetchData()
|
|
219
|
+
}, [])
|
|
220
|
+
|
|
221
|
+
if (loading) return <Loading />
|
|
222
|
+
if (error) return <Error message={error} />
|
|
223
|
+
|
|
224
|
+
return <div>{data?.name}</div>
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## 🎨 Layout Pattern
|
|
229
|
+
|
|
230
|
+
### Root Layout Pattern
|
|
231
|
+
```typescript
|
|
232
|
+
export const metadata: Metadata = {
|
|
233
|
+
title: '{project_name}',
|
|
234
|
+
description: 'A modern website built with Next.js',
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export default function RootLayout({
|
|
238
|
+
children,
|
|
239
|
+
}: {
|
|
240
|
+
children: React.ReactNode
|
|
241
|
+
}) {
|
|
242
|
+
return (
|
|
243
|
+
<html lang="en">
|
|
244
|
+
<body>{children}</body>
|
|
245
|
+
</html>
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Nested Layout Pattern
|
|
251
|
+
```typescript
|
|
252
|
+
export default function DashboardLayout({
|
|
253
|
+
children,
|
|
254
|
+
}: {
|
|
255
|
+
children: React.ReactNode
|
|
256
|
+
}) {
|
|
257
|
+
return (
|
|
258
|
+
<div className="dashboard">
|
|
259
|
+
<Sidebar />
|
|
260
|
+
<main>{children}</main>
|
|
261
|
+
</div>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## 🎨 SEO Pattern
|
|
267
|
+
|
|
268
|
+
### Metadata API Pattern
|
|
269
|
+
```typescript
|
|
270
|
+
import { Metadata } from 'next'
|
|
271
|
+
|
|
272
|
+
export const metadata: Metadata = {
|
|
273
|
+
title: 'Page Title',
|
|
274
|
+
description: 'Page description',
|
|
275
|
+
keywords: ['keyword1', 'keyword2'],
|
|
276
|
+
openGraph: {
|
|
277
|
+
title: 'Page Title',
|
|
278
|
+
description: 'Page description',
|
|
279
|
+
type: 'website',
|
|
280
|
+
},
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Dynamic Metadata Pattern
|
|
285
|
+
```typescript
|
|
286
|
+
export async function generateMetadata({ params }: { params: { id: string } }): Promise<Metadata> {
|
|
287
|
+
const data = await fetchData(params.id)
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
title: data.name,
|
|
291
|
+
description: data.description,
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## 📦 File Organization Patterns
|
|
297
|
+
|
|
298
|
+
### App Router Structure
|
|
299
|
+
```
|
|
300
|
+
src/app/
|
|
301
|
+
├── layout.tsx # Root layout
|
|
302
|
+
├── page.tsx # Home page
|
|
303
|
+
├── about/
|
|
304
|
+
│ ├── page.tsx # About page
|
|
305
|
+
│ └── layout.tsx # About layout
|
|
306
|
+
├── blog/
|
|
307
|
+
│ ├── page.tsx # Blog listing
|
|
308
|
+
│ ├── [slug]/
|
|
309
|
+
│ │ └── page.tsx # Blog post
|
|
310
|
+
│ └── layout.tsx # Blog layout
|
|
311
|
+
└── api/ # API routes
|
|
312
|
+
└── route.ts
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Type-Based Structure
|
|
316
|
+
```
|
|
317
|
+
src/
|
|
318
|
+
├── app/ # App Router pages and layouts
|
|
319
|
+
├── components/ # Reusable components
|
|
320
|
+
├── services/ # API services
|
|
321
|
+
├── hooks/ # Custom hooks
|
|
322
|
+
├── types/ # TypeScript types
|
|
323
|
+
├── utils/ # Utility functions
|
|
324
|
+
└── lib/ # Third-party library configurations
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## 🔒 Error Handling Patterns
|
|
328
|
+
|
|
329
|
+
### Error Boundary Pattern
|
|
330
|
+
```typescript
|
|
331
|
+
'use client'
|
|
332
|
+
|
|
333
|
+
class ErrorBoundary extends React.Component<{ children: React.ReactNode }, { hasError: boolean }> {
|
|
334
|
+
constructor(props: { children: React.ReactNode }) {
|
|
335
|
+
super(props)
|
|
336
|
+
this.state = { hasError: false }
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static getDerivedStateFromError() {
|
|
340
|
+
return { hasError: true }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
render() {
|
|
344
|
+
if (this.state.hasError) {
|
|
345
|
+
return <div>Something went wrong</div>
|
|
346
|
+
}
|
|
347
|
+
return this.props.children
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Try-Catch in Async Operations
|
|
353
|
+
```typescript
|
|
354
|
+
const safeAsyncOperation = async () => {
|
|
355
|
+
try {
|
|
356
|
+
const result = await apiService.get('/endpoint')
|
|
357
|
+
return result
|
|
358
|
+
} catch (error) {
|
|
359
|
+
console.error('Operation failed:', error)
|
|
360
|
+
throw error
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## 🚀 Performance Patterns
|
|
366
|
+
|
|
367
|
+
### Dynamic Import Pattern
|
|
368
|
+
```typescript
|
|
369
|
+
const DynamicComponent = dynamic(() => import('./Component'), {
|
|
370
|
+
loading: () => <Loading />,
|
|
371
|
+
ssr: false,
|
|
372
|
+
})
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Image Optimization Pattern
|
|
376
|
+
```typescript
|
|
377
|
+
import Image from 'next/image'
|
|
378
|
+
|
|
379
|
+
<Image
|
|
380
|
+
src="/image.jpg"
|
|
381
|
+
alt="Description"
|
|
382
|
+
width={500}
|
|
383
|
+
height={300}
|
|
384
|
+
priority
|
|
385
|
+
/>
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### Font Optimization Pattern
|
|
389
|
+
```typescript
|
|
390
|
+
import { Inter } from 'next/font/google'
|
|
391
|
+
|
|
392
|
+
const inter = Inter({ subsets: ['latin'] })
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
## 📐 Naming Conventions
|
|
396
|
+
|
|
397
|
+
### Components
|
|
398
|
+
- **File**: `PascalCase.tsx` (e.g., `UserProfile.tsx`)
|
|
399
|
+
- **Component**: `PascalCase` (e.g., `UserProfile`)
|
|
400
|
+
- **Props Interface**: `ComponentProps` (e.g., `UserProfileProps`)
|
|
401
|
+
|
|
402
|
+
### Pages
|
|
403
|
+
- **File**: `page.tsx` (Next.js convention)
|
|
404
|
+
- **Layout**: `layout.tsx` (Next.js convention)
|
|
405
|
+
- **Route**: File-based routing
|
|
406
|
+
|
|
407
|
+
### Hooks
|
|
408
|
+
- **File**: `camelCase.ts` (e.g., `useUserProfile.ts`)
|
|
409
|
+
- **Hook**: `camelCase` starting with `use` (e.g., `useUserProfile`)
|
|
410
|
+
|
|
411
|
+
### Services
|
|
412
|
+
- **File**: `camelCase.ts` (e.g., `apiService.ts`)
|
|
413
|
+
- **Service**: `camelCase` (e.g., `apiService`)
|
|
414
|
+
|
|
415
|
+
### Types
|
|
416
|
+
- **File**: `PascalCase.types.ts` (e.g., `User.types.ts`)
|
|
417
|
+
- **Interface**: `PascalCase` (e.g., `UserProfile`)
|
|
418
|
+
- **Type**: `PascalCase` (e.g., `ApiResponse`)
|
|
419
|
+
|
|
420
|
+
### Constants
|
|
421
|
+
- **File**: `camelCase.ts` (e.g., `constants.ts`)
|
|
422
|
+
- **Constant**: `UPPER_SNAKE_CASE` (e.g., `API_BASE_URL`)
|
|
423
|
+
|
|
424
|
+
## 🎯 Best Practices
|
|
425
|
+
|
|
426
|
+
### Code Organization
|
|
427
|
+
1. Keep components small and focused
|
|
428
|
+
2. Extract reusable logic into custom hooks
|
|
429
|
+
3. Use TypeScript interfaces for all props
|
|
430
|
+
4. Organize imports (external, internal, types)
|
|
431
|
+
5. Use path aliases (`@/`) for internal imports
|
|
432
|
+
|
|
433
|
+
### Performance
|
|
434
|
+
1. Use Server Components by default
|
|
435
|
+
2. Use Client Components only when needed
|
|
436
|
+
3. Implement code splitting with dynamic imports
|
|
437
|
+
4. Optimize images with Next.js Image component
|
|
438
|
+
5. Use streaming for large pages
|
|
439
|
+
|
|
440
|
+
### SEO
|
|
441
|
+
1. Use Metadata API for all pages
|
|
442
|
+
2. Implement proper meta tags
|
|
443
|
+
3. Use semantic HTML elements
|
|
444
|
+
4. Add structured data (JSON-LD)
|
|
445
|
+
5. Optimize page load times
|
|
446
|
+
6. Ensure mobile responsiveness
|
|
447
|
+
|
|
448
|
+
### Accessibility
|
|
449
|
+
1. Use semantic HTML elements
|
|
450
|
+
2. Provide alt text for images
|
|
451
|
+
3. Ensure keyboard navigation
|
|
452
|
+
4. Use ARIA labels where needed
|
|
453
|
+
5. Test with screen readers
|
|
454
|
+
|
|
455
|
+
### Security
|
|
456
|
+
1. Sanitize user input
|
|
457
|
+
2. Use HTTPS in production
|
|
458
|
+
3. Validate data on client and server
|
|
459
|
+
4. Never expose sensitive data
|
|
460
|
+
5. Use environment variables for secrets
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
├── package.json # Node.js dependencies
|
|
13
|
+
├── tsconfig.json # TypeScript configuration
|
|
14
|
+
├── next.config.js # Next.js configuration
|
|
15
|
+
├── README.md # Project documentation
|
|
16
|
+
└── src/ # Source code
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🏗️ Source Directory Structure (`src/`)
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/
|
|
23
|
+
├── app/ # Next.js App Router
|
|
24
|
+
│ ├── layout.tsx # Root layout with SEO metadata
|
|
25
|
+
│ ├── page.tsx # Home page
|
|
26
|
+
│ └── globals.css # Global styles
|
|
27
|
+
├── components/ # Reusable UI components
|
|
28
|
+
│ └── Header.tsx # Header component
|
|
29
|
+
├── services/ # API and external services
|
|
30
|
+
│ └── api.ts # API service with axios
|
|
31
|
+
└── utils/ # Utility functions
|
|
32
|
+
└── constants.ts # Constants and configuration
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 🎯 Key Conventions
|
|
36
|
+
|
|
37
|
+
### File Naming
|
|
38
|
+
- **Components**: `PascalCase` with `.tsx` extension (e.g., `UserProfile.tsx`)
|
|
39
|
+
- **Pages**: `PascalCase` with `.tsx` extension (e.g., `AboutPage.tsx`)
|
|
40
|
+
- **Services**: `camelCase` with `.ts` extension (e.g., `api.ts`)
|
|
41
|
+
- **Utils**: `camelCase` with `.ts` extension (e.g., `formatDate.ts`)
|
|
42
|
+
- **Types**: `PascalCase` with `.ts` extension (e.g., `UserTypes.ts`)
|
|
43
|
+
|
|
44
|
+
### Import Patterns
|
|
45
|
+
- **Components**: `import Component from '@/components/Component'`
|
|
46
|
+
- **Services**: `import { apiService } from '@/services/api'`
|
|
47
|
+
- **Utils**: `import { CONSTANT } from '@/utils/constants'`
|
|
48
|
+
- **Types**: `import { UserType } from '@/types'`
|
|
49
|
+
|
|
50
|
+
### TypeScript Patterns
|
|
51
|
+
- **Props Interface**: Always define interfaces for component props
|
|
52
|
+
- **Generic Types**: Use generics when appropriate for reusable components
|
|
53
|
+
- **Strict Mode**: TypeScript strict mode is enabled
|
|
54
|
+
- **No Any**: Avoid using `any` type, use `unknown` or proper types instead
|
|
55
|
+
|
|
56
|
+
## 🔄 Development Workflow
|
|
57
|
+
|
|
58
|
+
1. **Install dependencies**: `npm install`
|
|
59
|
+
2. **Run development server**: `npm run dev`
|
|
60
|
+
3. **Build for production**: `npm run build`
|
|
61
|
+
4. **Start production server**: `npm start`
|
|
62
|
+
5. **Run linter**: `npm run lint`
|
|
63
|
+
|
|
64
|
+
## 📋 Important Notes for AI
|
|
65
|
+
|
|
66
|
+
- **Always use TypeScript** with proper type definitions
|
|
67
|
+
- **Follow the component structure** when creating new components
|
|
68
|
+
- **Use the apiService** for all API calls
|
|
69
|
+
- **Handle loading and error states** in async operations
|
|
70
|
+
- **Use environment variables** via `process.env.NEXT_PUBLIC_*`
|
|
71
|
+
- **Path aliases**: Use `@` for `src/` directory imports
|
|
72
|
+
- **Next.js App Router**: This project uses the App Router (not Pages Router)
|
|
73
|
+
- **Port**: Development server runs on http://localhost:3000
|
|
74
|
+
- **SEO**: Use Next.js Metadata API for SEO optimization
|
|
75
|
+
- **Server Components**: Use Server Components by default, use Client Components when needed
|