@haposoft/cafekit 0.3.2 → 0.3.6

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.
@@ -0,0 +1,704 @@
1
+ # Project Detection - Auto-Adapt Impact Analysis
2
+
3
+ Hệ thống tự động detect và adapt Impact Analysis cho nhiều loại projects.
4
+
5
+ ## Project Type Detection
6
+
7
+ ### Detection Strategy
8
+
9
+ ```javascript
10
+ // Auto-detect project type from files and dependencies
11
+ function detectProjectType(projectPath) {
12
+ const indicators = {
13
+ 'react-native': [
14
+ 'package.json contains react-native',
15
+ 'android/ and ios/ folders exist',
16
+ 'App.tsx or App.js exists',
17
+ 'metro.config.js exists'
18
+ ],
19
+ 'react-web': [
20
+ 'package.json contains react and react-dom',
21
+ 'src/index.tsx or src/index.js',
22
+ 'public/index.html',
23
+ 'No android/ios folders'
24
+ ],
25
+ 'nextjs': [
26
+ 'package.json contains next',
27
+ 'pages/ or app/ folder',
28
+ 'next.config.js'
29
+ ],
30
+ 'vue': [
31
+ 'package.json contains vue',
32
+ 'src/main.js or src/main.ts',
33
+ 'vue.config.js or vite.config.js'
34
+ ],
35
+ 'angular': [
36
+ 'package.json contains @angular',
37
+ 'angular.json',
38
+ 'src/app/'
39
+ ],
40
+ 'nodejs-api': [
41
+ 'package.json contains express or fastify or koa',
42
+ 'No frontend framework',
43
+ 'src/routes/ or src/api/'
44
+ ],
45
+ 'nestjs': [
46
+ 'package.json contains @nestjs',
47
+ 'nest-cli.json',
48
+ 'src/main.ts'
49
+ ],
50
+ 'python-django': [
51
+ 'requirements.txt or Pipfile',
52
+ 'manage.py',
53
+ 'settings.py'
54
+ ],
55
+ 'python-fastapi': [
56
+ 'requirements.txt contains fastapi',
57
+ 'main.py with FastAPI'
58
+ ],
59
+ 'laravel': [
60
+ 'composer.json contains laravel',
61
+ 'artisan',
62
+ 'app/Http/'
63
+ ],
64
+ 'rails': [
65
+ 'Gemfile contains rails',
66
+ 'config/routes.rb',
67
+ 'app/controllers/'
68
+ ]
69
+ };
70
+
71
+ // Check each indicator
72
+ for (const [type, checks] of Object.entries(indicators)) {
73
+ if (allChecksPass(checks, projectPath)) {
74
+ return type;
75
+ }
76
+ }
77
+
78
+ return 'generic';
79
+ }
80
+ ```
81
+
82
+ ## Project Profiles
83
+
84
+ ### Profile Structure
85
+
86
+ ```javascript
87
+ // Each project type has a profile
88
+ const projectProfiles = {
89
+ 'react-native': {
90
+ name: 'React Native',
91
+ description: 'Mobile app with React Native',
92
+
93
+ // File patterns
94
+ patterns: {
95
+ backend: ['**/services/**', '**/api/**', '**/utils/**'],
96
+ frontend: ['**/screens/**', '**/components/**', '**/navigation/**'],
97
+ state: ['**/store/**', '**/context/**', '**/hooks/**'],
98
+ config: ['**/*.config.js', '**/app.json', '**/package.json'],
99
+ native: ['**/android/**', '**/ios/**']
100
+ },
101
+
102
+ // Feature detection
103
+ features: {
104
+ 'Authentication': {
105
+ patterns: ['**/screens/Auth/**', '**/screens/Login/**', '**/services/auth/**'],
106
+ keywords: ['login', 'signin', 'authenticate', 'token', 'session']
107
+ },
108
+ 'Navigation': {
109
+ patterns: ['**/navigation/**', '**/routes/**'],
110
+ keywords: ['navigate', 'useNavigation', 'Stack.Screen', 'Tab.Screen']
111
+ },
112
+ 'Storage': {
113
+ patterns: ['**/utils/storage/**', '**/services/storage/**'],
114
+ keywords: ['AsyncStorage', '@react-native-async-storage', 'MMKV']
115
+ },
116
+ 'Camera/Image': {
117
+ patterns: ['**/utils/camera/**', '**/utils/image/**'],
118
+ keywords: ['ImagePicker', 'launchCamera', 'Camera', 'Photo']
119
+ },
120
+ 'Notifications': {
121
+ patterns: ['**/services/notification/**', '**/utils/notification/**'],
122
+ keywords: ['PushNotification', 'messaging', 'FCM', 'notification']
123
+ }
124
+ },
125
+
126
+ // Edge cases
127
+ edgeCases: [
128
+ {
129
+ category: 'Platform-Specific',
130
+ checks: [
131
+ 'Platform.OS checks for iOS/Android',
132
+ 'SafeAreaView usage',
133
+ 'StatusBar handling',
134
+ 'Permission flows (iOS vs Android)'
135
+ ]
136
+ },
137
+ {
138
+ category: 'AsyncStorage',
139
+ checks: [
140
+ 'Try-catch wrappers',
141
+ 'Null checks before JSON.parse',
142
+ 'Storage quota limits',
143
+ 'Migration handling'
144
+ ]
145
+ },
146
+ {
147
+ category: 'Navigation',
148
+ checks: [
149
+ 'Params validation',
150
+ 'canGoBack() checks',
151
+ 'Deep link handling',
152
+ 'State persistence'
153
+ ]
154
+ },
155
+ {
156
+ category: 'Performance',
157
+ checks: [
158
+ 'FlatList optimization (keyExtractor, getItemLayout)',
159
+ 'Image optimization',
160
+ 'Memory leaks (useEffect cleanup)',
161
+ 'Re-render optimization (useMemo, useCallback)'
162
+ ]
163
+ }
164
+ ],
165
+
166
+ // Test priorities
167
+ testPriorities: {
168
+ 'Authentication': 'P0',
169
+ 'Core Features': 'P0',
170
+ 'Navigation': 'P1',
171
+ 'UI Components': 'P1',
172
+ 'Settings': 'P2'
173
+ }
174
+ },
175
+
176
+ 'react-web': {
177
+ name: 'React Web App',
178
+ description: 'Web application with React',
179
+
180
+ patterns: {
181
+ backend: ['**/services/**', '**/api/**', '**/utils/**'],
182
+ frontend: ['**/pages/**', '**/components/**', '**/routes/**'],
183
+ state: ['**/store/**', '**/context/**', '**/hooks/**'],
184
+ config: ['**/*.config.js', '**/package.json'],
185
+ styles: ['**/*.css', '**/*.scss', '**/*.module.css']
186
+ },
187
+
188
+ features: {
189
+ 'Authentication': {
190
+ patterns: ['**/pages/auth/**', '**/components/Auth/**', '**/services/auth/**'],
191
+ keywords: ['login', 'signin', 'authenticate', 'token', 'session']
192
+ },
193
+ 'Routing': {
194
+ patterns: ['**/routes/**', '**/router/**'],
195
+ keywords: ['Route', 'useNavigate', 'useLocation', 'BrowserRouter']
196
+ },
197
+ 'Forms': {
198
+ patterns: ['**/components/Form/**', '**/pages/**/Form/**'],
199
+ keywords: ['useForm', 'Formik', 'react-hook-form', 'validation']
200
+ },
201
+ 'Data Fetching': {
202
+ patterns: ['**/services/**', '**/api/**', '**/hooks/use*Query*'],
203
+ keywords: ['fetch', 'axios', 'useQuery', 'useMutation', 'SWR']
204
+ }
205
+ },
206
+
207
+ edgeCases: [
208
+ {
209
+ category: 'Browser Compatibility',
210
+ checks: [
211
+ 'Cross-browser CSS',
212
+ 'Polyfills for older browsers',
213
+ 'Feature detection',
214
+ 'Graceful degradation'
215
+ ]
216
+ },
217
+ {
218
+ category: 'SEO',
219
+ checks: [
220
+ 'Meta tags',
221
+ 'Server-side rendering',
222
+ 'Semantic HTML',
223
+ 'Accessibility (ARIA)'
224
+ ]
225
+ },
226
+ {
227
+ category: 'Performance',
228
+ checks: [
229
+ 'Code splitting',
230
+ 'Lazy loading',
231
+ 'Image optimization',
232
+ 'Bundle size'
233
+ ]
234
+ }
235
+ ],
236
+
237
+ testPriorities: {
238
+ 'Authentication': 'P0',
239
+ 'Core Features': 'P0',
240
+ 'Forms': 'P1',
241
+ 'UI Components': 'P1',
242
+ 'SEO': 'P2'
243
+ }
244
+ },
245
+
246
+ 'nextjs': {
247
+ name: 'Next.js',
248
+ description: 'React framework with SSR/SSG',
249
+
250
+ patterns: {
251
+ backend: ['**/api/**', '**/lib/**', '**/utils/**'],
252
+ frontend: ['**/pages/**', '**/app/**', '**/components/**'],
253
+ state: ['**/store/**', '**/context/**', '**/hooks/**'],
254
+ config: ['next.config.js', '**/package.json'],
255
+ styles: ['**/*.css', '**/*.scss', '**/*.module.css']
256
+ },
257
+
258
+ features: {
259
+ 'API Routes': {
260
+ patterns: ['**/pages/api/**', '**/app/api/**'],
261
+ keywords: ['NextApiRequest', 'NextApiResponse', 'api handler']
262
+ },
263
+ 'SSR/SSG': {
264
+ patterns: ['**/pages/**', '**/app/**'],
265
+ keywords: ['getServerSideProps', 'getStaticProps', 'generateStaticParams']
266
+ },
267
+ 'Routing': {
268
+ patterns: ['**/pages/**', '**/app/**'],
269
+ keywords: ['useRouter', 'usePathname', 'useSearchParams']
270
+ }
271
+ },
272
+
273
+ edgeCases: [
274
+ {
275
+ category: 'Hydration',
276
+ checks: [
277
+ 'Server/client mismatch',
278
+ 'useEffect for client-only code',
279
+ 'Dynamic imports',
280
+ 'Hydration errors'
281
+ ]
282
+ },
283
+ {
284
+ category: 'Data Fetching',
285
+ checks: [
286
+ 'getServerSideProps errors',
287
+ 'getStaticProps revalidation',
288
+ 'API route error handling',
289
+ 'Loading states'
290
+ ]
291
+ }
292
+ ],
293
+
294
+ testPriorities: {
295
+ 'API Routes': 'P0',
296
+ 'SSR Pages': 'P0',
297
+ 'Client Components': 'P1',
298
+ 'Static Pages': 'P2'
299
+ }
300
+ },
301
+
302
+ 'nodejs-api': {
303
+ name: 'Node.js API',
304
+ description: 'Backend API with Node.js',
305
+
306
+ patterns: {
307
+ backend: ['**/routes/**', '**/controllers/**', '**/services/**', '**/middleware/**'],
308
+ database: ['**/models/**', '**/schemas/**', '**/migrations/**'],
309
+ config: ['**/config/**', '**/*.config.js'],
310
+ tests: ['**/*.test.js', '**/*.spec.js']
311
+ },
312
+
313
+ features: {
314
+ 'Authentication': {
315
+ patterns: ['**/routes/auth/**', '**/middleware/auth/**', '**/services/auth/**'],
316
+ keywords: ['jwt', 'passport', 'authenticate', 'authorize', 'token']
317
+ },
318
+ 'Database': {
319
+ patterns: ['**/models/**', '**/repositories/**'],
320
+ keywords: ['mongoose', 'sequelize', 'prisma', 'typeorm', 'query']
321
+ },
322
+ 'API Endpoints': {
323
+ patterns: ['**/routes/**', '**/controllers/**'],
324
+ keywords: ['router', 'app.get', 'app.post', 'express', 'fastify']
325
+ }
326
+ },
327
+
328
+ edgeCases: [
329
+ {
330
+ category: 'Error Handling',
331
+ checks: [
332
+ 'Try-catch in async routes',
333
+ 'Error middleware',
334
+ 'Validation errors',
335
+ 'Database errors'
336
+ ]
337
+ },
338
+ {
339
+ category: 'Security',
340
+ checks: [
341
+ 'Input validation',
342
+ 'SQL injection prevention',
343
+ 'XSS prevention',
344
+ 'Rate limiting',
345
+ 'CORS configuration'
346
+ ]
347
+ },
348
+ {
349
+ category: 'Performance',
350
+ checks: [
351
+ 'Database query optimization',
352
+ 'Caching strategy',
353
+ 'Connection pooling',
354
+ 'Memory leaks'
355
+ ]
356
+ }
357
+ ],
358
+
359
+ testPriorities: {
360
+ 'Authentication': 'P0',
361
+ 'Core API Endpoints': 'P0',
362
+ 'Database Operations': 'P0',
363
+ 'Middleware': 'P1',
364
+ 'Utilities': 'P2'
365
+ }
366
+ },
367
+
368
+ 'generic': {
369
+ name: 'Generic Project',
370
+ description: 'Auto-detected patterns',
371
+
372
+ patterns: {
373
+ backend: ['**/api/**', '**/services/**', '**/server/**'],
374
+ frontend: ['**/components/**', '**/pages/**', '**/views/**'],
375
+ database: ['**/models/**', '**/schemas/**', '**/migrations/**'],
376
+ config: ['**/*.config.*', '**/package.json', '**/composer.json'],
377
+ tests: ['**/*.test.*', '**/*.spec.*', '**/tests/**']
378
+ },
379
+
380
+ features: {
381
+ // Auto-detect from file names and content
382
+ 'auto-detect': true
383
+ },
384
+
385
+ edgeCases: [
386
+ {
387
+ category: 'General',
388
+ checks: [
389
+ 'Null/undefined handling',
390
+ 'Error handling',
391
+ 'Input validation',
392
+ 'Edge case boundaries'
393
+ ]
394
+ }
395
+ ],
396
+
397
+ testPriorities: {
398
+ 'Core Features': 'P0',
399
+ 'Secondary Features': 'P1',
400
+ 'Utilities': 'P2'
401
+ }
402
+ }
403
+ };
404
+ ```
405
+
406
+ ## Auto-Detection Algorithm
407
+
408
+ ### Step 1: Detect Project Type
409
+
410
+ ```bash
411
+ #!/bin/bash
412
+ # detect-project-type.sh
413
+
414
+ detect_project_type() {
415
+ local project_path=$1
416
+
417
+ # Check React Native
418
+ if [ -f "$project_path/package.json" ] && \
419
+ grep -q "react-native" "$project_path/package.json" && \
420
+ [ -d "$project_path/android" ] && \
421
+ [ -d "$project_path/ios" ]; then
422
+ echo "react-native"
423
+ return
424
+ fi
425
+
426
+ # Check Next.js
427
+ if [ -f "$project_path/package.json" ] && \
428
+ grep -q "next" "$project_path/package.json" && \
429
+ [ -f "$project_path/next.config.js" ]; then
430
+ echo "nextjs"
431
+ return
432
+ fi
433
+
434
+ # Check React Web
435
+ if [ -f "$project_path/package.json" ] && \
436
+ grep -q "react" "$project_path/package.json" && \
437
+ grep -q "react-dom" "$project_path/package.json" && \
438
+ ! [ -d "$project_path/android" ]; then
439
+ echo "react-web"
440
+ return
441
+ fi
442
+
443
+ # Check Node.js API
444
+ if [ -f "$project_path/package.json" ] && \
445
+ (grep -q "express" "$project_path/package.json" || \
446
+ grep -q "fastify" "$project_path/package.json") && \
447
+ ! grep -q "react" "$project_path/package.json"; then
448
+ echo "nodejs-api"
449
+ return
450
+ fi
451
+
452
+ # Check Vue
453
+ if [ -f "$project_path/package.json" ] && \
454
+ grep -q "vue" "$project_path/package.json"; then
455
+ echo "vue"
456
+ return
457
+ fi
458
+
459
+ # Check Django
460
+ if [ -f "$project_path/manage.py" ] && \
461
+ [ -f "$project_path/requirements.txt" ]; then
462
+ echo "python-django"
463
+ return
464
+ fi
465
+
466
+ # Check Laravel
467
+ if [ -f "$project_path/composer.json" ] && \
468
+ grep -q "laravel" "$project_path/composer.json" && \
469
+ [ -f "$project_path/artisan" ]; then
470
+ echo "laravel"
471
+ return
472
+ fi
473
+
474
+ # Default
475
+ echo "generic"
476
+ }
477
+
478
+ PROJECT_TYPE=$(detect_project_type "$1")
479
+ echo "Detected project type: $PROJECT_TYPE"
480
+ ```
481
+
482
+ ### Step 2: Load Profile
483
+
484
+ ```javascript
485
+ // Load profile based on detected type
486
+ function loadProfile(projectType) {
487
+ const profile = projectProfiles[projectType] || projectProfiles['generic'];
488
+
489
+ console.log(`📦 Project Type: ${profile.name}`);
490
+ console.log(`📝 Description: ${profile.description}`);
491
+
492
+ return profile;
493
+ }
494
+ ```
495
+
496
+ ### Step 3: Apply Profile
497
+
498
+ ```javascript
499
+ // Apply profile to impact analysis
500
+ function applyProfile(profile, changedFiles) {
501
+ // 1. Classify files using profile patterns
502
+ const classified = classifyFiles(changedFiles, profile.patterns);
503
+
504
+ // 2. Detect features using profile feature patterns
505
+ const features = detectFeatures(changedFiles, profile.features);
506
+
507
+ // 3. Check edge cases using profile edge case checks
508
+ const edgeCases = checkEdgeCases(changedFiles, profile.edgeCases);
509
+
510
+ // 4. Generate test scenarios with profile priorities
511
+ const testScenarios = generateTests(features, profile.testPriorities);
512
+
513
+ return {
514
+ classified,
515
+ features,
516
+ edgeCases,
517
+ testScenarios
518
+ };
519
+ }
520
+ ```
521
+
522
+ ## Custom Config File (Optional)
523
+
524
+ ### Project-Specific Override
525
+
526
+ ```javascript
527
+ // impact-analysis.config.js (optional, in project root)
528
+
529
+ module.exports = {
530
+ // Override detected type
531
+ projectType: 'react-native', // or auto-detect
532
+
533
+ // Extend or override patterns
534
+ patterns: {
535
+ // Add custom patterns
536
+ 'gift-features': ['**/screens/Gift/**', '**/services/gift/**'],
537
+ 'thankyou-features': ['**/screens/ThankYou/**', '**/services/thankyou/**']
538
+ },
539
+
540
+ // Extend or override features
541
+ features: {
542
+ 'Gift Management': {
543
+ patterns: ['**/screens/Gift/**', '**/services/gift/**'],
544
+ keywords: ['gift', 'present', 'create gift'],
545
+ userActions: ['Create Gift', 'View Gift', 'Edit Gift', 'Delete Gift'],
546
+ priority: 'P0'
547
+ },
548
+ 'Thank You Cards': {
549
+ patterns: ['**/screens/ThankYou/**', '**/services/thankyou/**'],
550
+ keywords: ['thank you', 'card', 'send card'],
551
+ userActions: ['Send Card', 'View Sent Cards', 'Choose Template'],
552
+ priority: 'P0'
553
+ }
554
+ },
555
+
556
+ // Add custom edge cases
557
+ edgeCases: {
558
+ 'Gift Creation': [
559
+ 'Image size > 5MB',
560
+ 'Multiple recipients',
561
+ 'Scheduled delivery',
562
+ 'Offline creation'
563
+ ]
564
+ },
565
+
566
+ // Override test priorities
567
+ testPriorities: {
568
+ 'Gift creation': 'P0',
569
+ 'Thank you sending': 'P0',
570
+ 'Profile update': 'P1'
571
+ },
572
+
573
+ // Custom risk thresholds
574
+ riskThresholds: {
575
+ high: ['Gift creation', 'Payment', 'Authentication'],
576
+ medium: ['Profile', 'Notifications'],
577
+ low: ['Settings', 'About']
578
+ }
579
+ };
580
+ ```
581
+
582
+ ## Usage in Impact Analysis
583
+
584
+ ### Integration Flow
585
+
586
+ ```javascript
587
+ // In impact-analysis workflow
588
+
589
+ async function analyzeImpact(args) {
590
+ // 1. Detect project type
591
+ const projectType = await detectProjectType(process.cwd());
592
+ console.log(`📦 Detected: ${projectType}`);
593
+
594
+ // 2. Load profile
595
+ let profile = loadProfile(projectType);
596
+
597
+ // 3. Check for custom config
598
+ const customConfig = await loadCustomConfig();
599
+ if (customConfig) {
600
+ console.log(`⚙️ Applying custom config`);
601
+ profile = mergeProfile(profile, customConfig);
602
+ }
603
+
604
+ // 4. Detect changes
605
+ const changedFiles = await detectChanges(args);
606
+
607
+ // 5. Apply profile
608
+ const analysis = applyProfile(profile, changedFiles);
609
+
610
+ // 6. Generate report
611
+ const report = generateReport(analysis, profile);
612
+
613
+ return report;
614
+ }
615
+ ```
616
+
617
+ ## Benefits
618
+
619
+ ### 1. Zero Configuration
620
+ - Auto-detect project type
621
+ - Apply appropriate patterns
622
+ - No setup required
623
+
624
+ ### 2. Flexible
625
+ - Works with any project type
626
+ - Extensible via config file
627
+ - Custom patterns supported
628
+
629
+ ### 3. Consistent
630
+ - Same workflow across projects
631
+ - Standardized reports
632
+ - Predictable behavior
633
+
634
+ ### 4. Maintainable
635
+ - Profiles in one place
636
+ - Easy to add new project types
637
+ - Version controlled
638
+
639
+ ## Example Output
640
+
641
+ ```markdown
642
+ # Impact Analysis Report
643
+
644
+ **Project Type:** React Native (thanksgift-react-native)
645
+ **Profile:** Auto-detected + Custom config applied
646
+ **Config:** impact-analysis.config.js found ✓
647
+
648
+ ## 📦 Project Profile
649
+
650
+ - **Type:** React Native Mobile App
651
+ - **Patterns:** 5 categories (backend, frontend, state, config, native)
652
+ - **Features:** 8 detected (Gift Management, Thank You Cards, ...)
653
+ - **Edge Cases:** 4 categories (Platform, AsyncStorage, Navigation, Performance)
654
+ - **Test Priorities:** P0 (2), P1 (3), P2 (2)
655
+
656
+ ## 🎯 Detected Features (Custom)
657
+
658
+ ### Gift Management (P0) ⭐
659
+ **Patterns Matched:**
660
+ - `src/screens/Gift/CreateGift.tsx`
661
+ - `src/services/gift/giftService.ts`
662
+
663
+ **User Actions:**
664
+ - Create Gift
665
+ - Upload Gift Photo
666
+ - View Gift Details
667
+
668
+ **Priority:** P0 (from custom config)
669
+
670
+ ### Thank You Cards (P0) ⭐
671
+ **Patterns Matched:**
672
+ - `src/screens/ThankYou/SendCard.tsx`
673
+ - `src/services/thankyou/cardService.ts`
674
+
675
+ **User Actions:**
676
+ - Send Card
677
+ - Choose Template
678
+ - Add Message
679
+
680
+ **Priority:** P0 (from custom config)
681
+
682
+ ## ⚠️ Edge Cases (Profile: React Native)
683
+
684
+ ### Platform-Specific (from profile)
685
+ - [ ] Platform.OS checks
686
+ - [ ] SafeAreaView usage
687
+ - [ ] Permission flows
688
+
689
+ ### Gift Creation (from custom config)
690
+ - [ ] Image size > 5MB
691
+ - [ ] Multiple recipients
692
+ - [ ] Offline creation
693
+
694
+ ...
695
+ ```
696
+
697
+ ## Next Steps
698
+
699
+ 1. **Implement auto-detection** in skill
700
+ 2. **Add more project profiles** (Vue, Angular, Django, etc.)
701
+ 3. **Support custom config** file
702
+ 4. **Test with multiple projects**
703
+ 5. **Document profile format**
704
+