-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.cursorrules
1070 lines (955 loc) · 31.2 KB
/
.cursorrules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# LMS MVP Project Rules
# This file defines the rules and processes for our Learning Management System project
# Template Preservation Guidelines
template_preservation:
holy_files:
- payload.config.ts:
rules:
- 'Maintain original import structure and order'
- 'Keep original comments and placeholders'
- 'Use defaultLexical from fields directory'
- 'Preserve getServerSideURL utility'
- 'No type annotations in this file'
- 'No plugin configurations (move to plugins.ts)'
- 'No direct editor configurations'
- 'Minimal comments, only from original template'
- 'Use standard Node.js imports (no node: prefix)'
- 'Keep file-type imports compatible with Payload version'
import_structure:
order:
1: 'Database adapter (mongooseAdapter)'
2: 'Core dependencies (sharp, path, payload, url)'
3: 'Collections'
4: 'Globals'
5: 'Plugins and utilities'
6: 'Spaces module imports (last)'
modifications:
allowed:
- 'Adding Spaces collections to collections array'
- 'Adding Settings to globals array'
- 'Adding Spaces imports at the end'
forbidden:
- 'Adding type imports'
- 'Adding generateTitle/URL functions'
- 'Modifying original template comments'
- 'Adding new plugin configurations'
- 'Using node: protocol imports'
- plugins.ts:
rules:
- 'Keep all plugin configurations here'
- 'Maintain original plugin order'
- 'Keep type annotations for plugin configs'
- 'Preserve SEO title/URL generation'
structure:
- 'Import all plugins first'
- 'Import types for configurations'
- 'Define helper functions'
- 'Export plugins array'
spaces_integration:
collections_integration:
- 'Add Spaces collections after template collections'
- 'Maintain original collection order'
- 'No collection configuration in payload.config.ts'
globals_integration:
- 'Add Settings global last in globals array'
- 'Keep original globals order (Header, Footer)'
imports_organization:
- 'Group Spaces imports separately'
- 'Place Spaces imports after template imports'
- 'Use consistent import style'
# Technology Stack Requirements
technologies:
frontend:
- framework: 'Next.js@15.0.0'
- styling: 'tailwindcss@latest'
- ui:
- 'shadcn-ui@latest'
- 'aceternity-ui@latest'
- 'magic-ui@latest'
- 'vaul@latest'
- 'sonner@latest'
- 'cmdk@latest'
- state: 'nuqs@latest'
- forms: '@hookform/resolvers@latest'
- validation: 'zod@latest'
- animation:
- 'framer-motion@latest'
- '@legendapp/motion@latest'
- '@formkit/auto-animate@latest'
backend:
- cms: 'payload@3.0.0'
- orm: 'drizzle-orm@latest'
- database: 'neon@latest'
- auth:
current: 'payload-auth@3.0.0'
future: 'clerk@latest'
- ai: '@vercel/ai@latest'
- payments: 'stripe@latest'
- uploads: 'uploadthing@latest'
- email: 'resend@latest'
- realtime: 'pusher@latest'
deployment:
- platform: 'vercel@latest'
- monitoring:
- 'sentry@latest'
- '@google-cloud/logging@latest'
- '@google-cloud/opentelemetry-cloud-monitoring-exporter@latest'
- '@google-cloud/opentelemetry-cloud-trace-exporter@latest'
- analytics: 'vercel-analytics@latest'
compatibility:
notes:
- 'Payload CMS 3.0 requires Next.js 15 for optimal performance'
- 'Server Actions are fully supported in Next.js 15'
- 'App Router is the recommended approach'
- 'React Server Components are fully utilized'
- 'nuqs provides URL-based state management compatible with RSC'
# State Management Guidelines
state:
principles:
- 'Prefer server-side state management over client-side'
- 'Use URL state for shareable and bookmarkable UI states'
- 'Leverage React Server Components for data fetching'
- 'Minimize client-side JavaScript'
urlState:
usage:
- 'Search parameters and filters'
- 'Pagination state'
- 'Tab selections'
- 'Modal states'
- 'Sort orders'
- 'View preferences'
implementation:
- 'Use nuqs for type-safe URL state management'
- 'Define searchParams types with Zod schemas'
- 'Implement default values for all URL parameters'
- 'Handle URL parameter validation'
benefits:
- 'SEO-friendly state management'
- 'Shareable URLs with complete state'
- 'Reduced client-side JavaScript'
- 'Better caching capabilities'
- 'Native browser history support'
serverState:
patterns:
- 'Use Server Components for data fetching'
- 'Implement server actions for mutations'
- 'Cache responses appropriately'
- 'Handle loading and error states'
clientState:
limitations:
- 'Restrict to ephemeral UI state only'
- 'Use React.useState for temporary form state'
- 'Avoid redundant client-side state'
- 'Prefer URL state when possible'
# Collections Structure
collections:
core:
- Tenants
- Users
- Courses
- Modules
- Lessons
- Quizzes
- Assignments
- Submissions
gamification:
- Points
- Badges
- Achievements
- Streaks
- Leaderboard
communication:
- Notifications
- Collaborations
- Announcements
- SupportTickets
settings:
- TenantSettings
- StudentSettings
- LearningPaths
# File Structure
structure:
app:
- '(auth): Authentication routes'
- '(dashboard): Protected dashboard routes'
- 'api: API routes when necessary'
- 'public: Static assets'
components:
- 'ui: Reusable UI components'
- 'forms: Form components'
- 'layouts: Layout components'
lib:
- 'db: Database configuration'
- 'utils: Utility functions'
- 'validation: Schema validation'
types:
- 'Global type definitions'
# Code Standards
standards:
general:
- 'Use TypeScript strict mode'
- 'Implement proper error handling'
- 'Add comprehensive logging'
- 'Document all public APIs'
- 'Follow SOLID principles'
nextjs:
- 'Use server components by default'
- 'Implement proper data fetching patterns'
- 'Optimize for performance'
- 'Follow app router best practices'
database:
- 'Use Drizzle migrations'
- 'Implement proper indexing'
- 'Handle database errors gracefully'
- 'Use transactions where needed'
security:
- 'Implement proper authentication'
- 'Use role-based access control'
- 'Sanitize all inputs'
- 'Protect sensitive data'
testing:
- 'Write tests for critical paths'
- 'Maintain good test coverage'
- 'Use proper test isolation'
- 'Mock external dependencies'
# Multi-Agent Development Process
agents:
architect:
role: 'System Design & Architecture'
responsibilities:
- 'Review and approve architectural decisions'
- 'Ensure scalability and performance'
- 'Maintain system consistency'
- 'Plan data structures and relationships'
triggers:
- 'New feature proposal'
- 'Architecture changes'
- 'Performance optimization requests'
- 'Database schema updates'
developer:
role: 'Code Implementation'
responsibilities:
- 'Write clean, maintainable code'
- 'Implement features according to specs'
- 'Handle error cases and edge conditions'
- 'Optimize database queries'
triggers:
- 'New feature request'
- 'Bug fix needed'
- 'Code optimization required'
- 'Performance issues'
reviewer:
role: 'Code Review & Quality'
responsibilities:
- 'Review code for best practices'
- 'Check for security vulnerabilities'
- 'Ensure code style consistency'
- 'Verify state management patterns'
checks:
- 'Code style compliance'
- 'Security best practices'
- 'Performance implications'
- 'Test coverage'
- 'URL state management'
tester:
role: 'Testing & Validation'
responsibilities:
- 'Write and maintain tests'
- 'Verify feature functionality'
- 'Regression testing'
- 'Load testing'
testTypes:
- 'Unit tests'
- 'Integration tests'
- 'E2E tests'
- 'Performance tests'
- 'Load tests'
security:
role: 'Security Compliance'
responsibilities:
- 'Review security implications'
- 'Ensure data protection'
- 'Audit authentication/authorization'
- 'Monitor security events'
checks:
- 'Authentication flows'
- 'Data encryption'
- 'API security'
- 'Input validation'
- 'Rate limiting'
# Development Workflow
workflow:
featureImplementation:
steps:
1:
agent: 'architect'
action: 'Review feature proposal'
output: 'Architecture decision document'
stateConsiderations:
- 'Determine if state should be URL-based'
- 'Plan server component structure'
- 'Identify client/server state boundaries'
- 'Consider data persistence needs'
2:
agent: 'developer'
action: 'Implement feature'
requirements:
- 'Follow Next.js 15 app router patterns'
- 'Use server actions over API routes'
- 'Implement URL state management with nuqs'
- 'Add proper loading and error states'
- 'Implement proper error handling'
- 'Add logging and monitoring'
3:
agent: 'reviewer'
action: 'Code review'
checks:
- 'Code quality'
- 'Performance'
- 'Security'
- 'Documentation'
- 'State management'
4:
agent: 'tester'
action: 'Testing'
requirements:
- 'Unit tests for utilities'
- 'Integration tests for API'
- 'E2E tests for critical flows'
- 'Load testing for scalability'
5:
agent: 'security'
action: 'Security review'
focus:
- 'Data protection'
- 'Authentication'
- 'Authorization'
- 'Rate limiting'
bugFix:
steps:
1:
agent: 'developer'
action: 'Reproduce and fix'
requirements:
- 'Document reproduction steps'
- 'Add regression test'
2:
agent: 'reviewer'
action: 'Review fix'
checks:
- 'Fix completeness'
- 'No new issues introduced'
3:
agent: 'tester'
action: 'Verify fix'
requirements:
- 'Test fix effectiveness'
- 'Run regression tests'
# Error Handling
errors:
levels:
- 'fatal: System crash level'
- 'error: Operation failure'
- 'warn: Potential issues'
- 'info: General information'
- 'debug: Debug information'
handling:
- 'Use custom error classes'
- 'Implement proper error boundaries'
- 'Log errors with context'
- 'Provide user-friendly messages'
# Deployment Guidelines
deployment:
vercel:
configuration:
- 'Use Edge Functions where appropriate'
- 'Configure proper caching strategies'
- 'Set up proper environment variables'
- 'Configure deployment regions'
monitoring:
- 'Set up error tracking with Sentry'
- 'Configure OpenTelemetry for tracing'
- 'Implement custom logging'
- 'Monitor Core Web Vitals'
database:
neon:
- 'Configure connection pooling'
- 'Set up read replicas'
- 'Implement query optimization'
- 'Configure automated backups'
security:
measures:
- 'Implement rate limiting'
- 'Set up CORS policies'
- 'Configure CSP headers'
- 'Enable WAF protection'
# Performance Requirements
performance:
metrics:
- 'Time to First Byte (TTFB) < 100ms'
- 'First Contentful Paint (FCP) < 1.5s'
- 'Largest Contentful Paint (LCP) < 2.5s'
- 'First Input Delay (FID) < 100ms'
- 'Cumulative Layout Shift (CLS) < 0.1'
optimization:
- 'Implement proper code splitting'
- 'Use React Suspense boundaries'
- 'Optimize images and assets'
- 'Minimize client-side JavaScript'
- 'Utilize edge caching'
# Commit Guidelines
commits:
format: 'type(scope): description'
types:
- 'feat: New feature'
- 'fix: Bug fix'
- 'docs: Documentation'
- 'style: Code style'
- 'refactor: Code refactor'
- 'test: Testing'
- 'chore: Maintenance'
# Backup and Recovery
backup:
database:
- 'Automated daily backups'
- 'Point-in-time recovery'
- 'Cross-region replication'
- 'Backup retention policy'
assets:
- 'Media file backups'
- 'Document versioning'
- 'Metadata backup'
- 'Recovery procedures'
monitoring:
- 'Backup success monitoring'
- 'Recovery testing schedule'
- 'Audit logging'
- 'Alert configuration'
# Authentication Strategy
auth:
phase1:
provider: 'Payload Built-in Auth'
features:
- 'Email/password authentication'
- 'Role-based access control'
- 'Session management'
- 'Password reset flow'
- 'Email verification'
implementation:
- "Use Payload's built-in auth system"
- 'Implement custom auth endpoints in Next.js'
- 'Set up proper session handling'
- 'Configure secure password policies'
- 'Set up email templates for auth flows'
phase2:
provider: 'Clerk'
features:
- 'Social authentication'
- 'Multi-factor authentication'
- 'User management dashboard'
- 'Advanced security features'
- 'Authentication analytics'
migration:
- 'Plan user data migration strategy'
- 'Set up Clerk webhooks'
- 'Update auth middleware'
- 'Migrate existing users'
- 'Update frontend components'
security:
- 'Implement CSRF protection'
- 'Set secure cookie policies'
- 'Configure rate limiting'
- 'Set up proper session timeouts'
- 'Implement audit logging'
# UI and Animation Patterns
ui_patterns:
floating:
description: 'Elements that float and respond to user interaction'
implementations:
- 'Floating navigation with Framer Motion'
- 'Hover cards using shadcn/ui + Aceternity'
- 'Animated tooltips with Magic UI'
- 'Context menus with radix-ui animations'
libraries:
- 'framer-motion'
- 'aceternity-ui'
- 'magic-ui'
- 'vaul'
morphing:
description: 'Elements that transform and change shape'
implementations:
- 'Shape-shifting buttons with Framer Motion'
- 'Expanding cards using Aceternity UI'
- 'Transitioning layouts with Motion One'
- 'Fluid backgrounds with Magic UI'
libraries:
- 'framer-motion'
- 'aceternity-ui'
- 'motion-one'
- 'magic-ui'
micro_interactions:
description: 'Small, subtle animations that provide feedback'
implementations:
- 'Button click effects with tailwindcss-animate'
- 'Input focus states with shadcn/ui'
- 'Loading spinners with Lucide icons'
- 'Progress indicators with Sonner'
libraries:
- 'tailwindcss-animate'
- 'shadcn-ui'
- 'lucide-react'
- 'sonner'
scroll_animations:
description: 'Animations triggered by scroll events'
implementations:
- 'Parallax effects with Framer Motion'
- 'Scroll-triggered reveals with Aceternity'
- 'Smooth transitions with Motion One'
- 'Intersection animations with Magic UI'
libraries:
- 'framer-motion'
- 'aceternity-ui'
- 'motion-one'
- 'magic-ui'
animation_patterns:
layout:
description: 'Page and layout transition animations'
implementations:
- 'Page transitions with Framer Motion'
- 'Route changes using Next.js + Motion One'
- 'Modal animations with Vaul'
- 'List reordering with Auto Animate'
libraries:
- 'framer-motion'
- 'motion-one'
- 'vaul'
- '@formkit/auto-animate'
feedback:
description: 'User feedback animations'
implementations:
- 'Loading states with Lucide'
- 'Success/error animations with Sonner'
- 'Progress indicators with shadcn/ui'
- 'Notification toasts with Magic UI'
libraries:
- 'lucide-react'
- 'sonner'
- 'shadcn-ui'
- 'magic-ui'
interaction:
description: 'User interaction animations'
implementations:
- 'Hover effects with tailwindcss-animate'
- 'Click responses with Framer Motion'
- 'Drag and drop with Motion One'
- 'Gesture animations with Magic UI'
libraries:
- 'tailwindcss-animate'
- 'framer-motion'
- 'motion-one'
- 'magic-ui'
# Component Animation Guidelines
component_animations:
principles:
- 'Use subtle animations by default'
- 'Ensure animations are accessible (respect reduced-motion)'
- 'Keep animations under 300ms for micro-interactions'
- 'Use spring animations for natural feel'
- 'Maintain consistent animation patterns'
performance:
- 'Use CSS transforms over position properties'
- 'Animate on compositor-only properties'
- 'Implement proper will-change hints'
- 'Use requestAnimationFrame for JS animations'
- 'Lazy load heavy animation libraries'
accessibility:
- 'Respect prefers-reduced-motion'
- "Ensure animations don't cause vestibular issues"
- 'Provide alternative static states'
- 'Keep animations subtle and purposeful'
- 'Allow animation opt-out'
# Spaces Module Integration
spaces:
changes:
- 'Update collections structure'
- 'Add real-time specific requirements'
- 'All Payload Specific Types are found in /src/spaces/types exceptions are found in /src/spaces/types/'
- 'Minimize changes to the existing Payload CMS official Website Template'
- 'Use modals found in /src/spaces/modals for UX CRUD operations'
- 'Update state management for real-time features'
- 'Add Socket.IO specific configurations'
theme:
colors:
background:
primary: 'bg-gradient-to-br from-[#7364c0] to-[#02264a]'
dark: 'dark:from-[#000C2F] dark:to-[#003666]'
input:
background: 'bg-[#383A40] dark:bg-[#383A40]'
text: 'text-zinc-200'
text:
primary: 'text-white'
secondary: 'text-zinc-200'
muted: 'text-zinc-400'
accent:
primary: 'bg-[#7364c0]'
secondary: 'bg-[#02264a]'
components:
chat:
messages:
container: 'bg-gradient-to-br from-[#7364c0] to-[#02264a] dark:from-[#000C2F] dark:to-[#003666]'
welcome:
icon: 'bg-zinc-700'
text: 'text-white'
input:
container: 'bg-gradient-to-br from-[#7364c0] to-[#02264a] dark:from-[#000C2F] dark:to-[#003666]'
box: 'bg-[#383A40] dark:bg-[#383A40] text-zinc-200'
header:
container: 'bg-gradient-to-br from-[#7364c0] to-[#02264a] dark:from-[#000C2F] dark:to-[#003666]'
sidebar:
container: 'bg-gradient-to-br from-[#7364c0] to-[#02264a] dark:from-[#000C2F] dark:to-[#003666]'
modals:
container: 'bg-gradient-to-br from-[#7364c0] to-[#02264a] dark:from-[#000C2F] dark:to-[#003666]'
rules:
- 'All Spaces components should use the defined gradient backgrounds'
- 'Keep Payload admin UI using default Payload styling'
- 'Use dark mode variants for better accessibility'
- 'Maintain consistent blue gradient theme across all Spaces components'
- 'Input elements should use darker solid backgrounds for contrast'
- 'Text should be properly contrasted against gradient backgrounds'
scope:
included:
- 'All components under /src/spaces/*'
- 'All pages under /src/app/(spaces)/*'
- 'All Spaces-specific modals and overlays'
excluded:
- 'Payload admin dashboard'
- 'Payload collection views'
- 'Default Payload components'
- 'Core CMS functionality'
# Troubleshooting Guidelines
troubleshooting:
path_resolution:
common_issues:
- issue: 'Module not found errors'
fix:
- 'Use @/ prefix instead of src/ for imports'
- 'Ensure path exists in tsconfig.json paths'
- 'Check case sensitivity of file paths'
- 'Verify file extensions match'
- issue: 'Import path inconsistencies'
fix:
- 'Standardize on @/ prefix for all internal imports'
- 'Use relative paths only for same-directory imports'
- 'Update all src/ prefixes to @/'
- 'Check tsconfig.json path mappings'
import_standards:
paths:
- '@/*: Absolute imports from src directory'
- './: Relative imports from same directory'
- '../: Relative imports from parent directory'
- '@/components/: UI components'
- '@/utilities/: Utility functions'
- '@/types/: Type definitions'
- '@/spaces/: Spaces module'
conventions:
- 'Always use @/ prefix for src directory imports'
- 'Keep relative imports to minimum'
- 'Group imports by type/source'
- 'Maintain consistent order'
tsconfig_paths:
required:
- '@/*: ["./src/*"]'
- 'payload/types: ["./node_modules/payload/types", "./src/types/payload-custom"]'
- 'payload/config: ["./node_modules/payload/dist/config"]'
- '@payload-config: ["./src/payload.config.ts"]'
webpack:
node_imports:
issue: 'UnhandledSchemeError with node: protocol imports'
fix:
- 'Use standard import paths (e.g., fs instead of node:fs)'
- 'Update webpack configuration to handle node: imports if needed'
- 'Add node polyfills in next.config.js if required'
file_type:
issue: 'fileTypeFromFile import error from file-type package'
fix:
- 'Use compatible version of file-type package'
- 'Update import statement to match exported members'
- 'Add proper webpack resolution for file-type package'
next_js:
cache:
issue: 'Webpack cache errors and pack file strategy failures'
fix:
- 'Clear .next/cache directory'
- 'Run with clean cache: NEXT_SKIP_CACHE=1'
- 'Ensure proper file permissions'
hot_reload:
issue: 'Fast Refresh errors requiring full reload'
fix:
- 'Check for circular dependencies'
- 'Verify export/import consistency'
- 'Ensure proper module boundaries'
payload:
type_generation:
issue: 'Payload type generation errors'
fix:
- 'Run payload generate:types after collection changes'
- 'Ensure proper TypeScript configuration'
- 'Check for circular type dependencies'
cors:
issue: '500 errors on API routes'
fix:
- 'Verify CORS configuration matches environment'
- 'Check serverURL configuration'
- 'Validate authentication setup'
# Authentication Path Guidelines
auth_paths:
standardization:
routes:
- path: '/login'
purpose: 'Main authentication entry point'
handling:
- 'All auth-related redirects should point here'
- 'Maintain single source of truth for auth flow'
- 'Handle both /sign-in and /login redirects'
- path: '/sign-in'
purpose: 'Clerk authentication route'
handling:
- 'Should redirect to /login'
- 'Update middleware to handle redirect'
- 'Maintain Clerk integration compatibility'
redirects:
rules:
- 'All authentication redirects go to /login'
- 'Maintain redirect chain in middleware'
- 'Handle both relative and absolute paths'
- 'Preserve query parameters'
implementation:
middleware:
- 'Add redirect mapping in middleware'
- 'Handle auth state consistently'
- 'Preserve return URLs'
- 'Log redirect chains'
error_handling:
auth_failures:
- issue: '500 errors on auth routes'
fix:
- 'Check auth provider configuration'
- 'Verify environment variables'
- 'Ensure consistent redirect paths'
- 'Log auth flow errors'
- issue: 'Redirect loops'
fix:
- 'Map all auth paths to /login'
- 'Update middleware redirect logic'
- 'Clear auth state if needed'
- 'Add maximum redirect count'
session:
- issue: 'Session validation failures'
fix:
- 'Check session cookie configuration'
- 'Verify auth provider setup'
- 'Ensure proper CORS settings'
- 'Validate session middleware'
# Middleware Guidelines
middleware:
auth:
rules:
- 'Handle all auth-related paths'
- 'Maintain consistent redirect chain'
- 'Preserve query parameters'
- 'Log redirect decisions'
implementation:
- pattern: |
export async function middleware(request: NextRequest) {
// Auth path standardization
if (request.nextUrl.pathname === '/sign-in') {
return NextResponse.redirect(new URL('/login', request.url))
}
// Other auth checks
if (request.nextUrl.pathname.startsWith('/spaces')) {
const { user } = await checkSession()
if (!user) {
return NextResponse.redirect(new URL('/login', request.url))
}
}
}
paths:
protected:
- '/spaces/*'
- '/dashboard/*'
- '/settings/*'
auth:
- '/login'
- '/sign-in'
- '/sign-up'
- '/forgot-password'
public:
- '/'
- '/about'
- '/contact'
# Development Environment
environment:
next_config:
webpack:
- 'Configure proper node polyfills'
- 'Handle node: protocol imports'
- 'Set up proper module resolution'
- 'Configure file-type package resolution'
experimental:
- 'Enable necessary experimental features'
- 'Configure proper serverActions'
- 'Set up proper middleware handling'
dependencies:
payload:
version: '3.0.0'
peer_dependencies:
- 'next@15.0.0'
- 'react@18.2.0'
- 'react-dom@18.2.0'
critical:
- 'file-type: Use compatible version'
- 'sharp: Required for image processing'
- 'mongodb: Required for database'
typescript:
config:
- 'Enable strict mode'
- 'Configure proper module resolution'
- 'Set up proper path aliases'
- 'Handle node module types'
# Real-time Communication Patterns
realtime:
sse:
principles:
- 'Use Server-Sent Events (SSE) for real-time updates'
- 'Prefer SSE over WebSockets for unidirectional data flow'
- 'Maintain consistent authentication via cookies'
- 'Implement proper cleanup and reconnection logic'
- 'Messages belong to channels, channels belong to spaces'
- 'Space membership is enforced at channel level'
implementation:
auth:
- 'Use withCredentials: true for cookie-based auth'
- 'Rely on Payload built-in cookie authentication'
- 'No manual token handling in SSE connections'
- 'Let Next.js/Payload handle cookie management'
data_relationships:
- 'Messages are linked to channels directly'
- 'Channels are linked to spaces'
- 'Space membership check happens at channel level'
- 'No direct space check needed for messages'
connection:
- 'Implement proper connection cleanup'
- 'Handle reconnection with exponential backoff'
- 'Maximum 3 retry attempts'
- 'Maximum 5 second delay between retries'
state:
- 'Use Set for message deduplication'
- 'Maintain message order with timestamps'
- 'Track last message ID for pagination'
- 'Clear message state on cleanup'
error_handling:
- 'Provide clear error messages to users'
- 'Log connection errors for debugging'
- 'Handle unmounted component cleanup'
- 'Reset retry count on successful messages'
endpoints:
- path: '/api/messages/sse'
auth: 'Required'
params:
- 'channelId or conversationId'
- 'spaceId'
- 'lastMessageId (optional)'
features:
- 'Keep-alive ping every 30 seconds'
- 'Initial message load on connect'
- 'Real-time message updates'
- 'Proper error responses'
components:
hooks:
- name: 'useMessages'
params:
- 'chatId: string'
- 'type: channel | conversation'
- 'spaceId: string'
state:
- 'messages: MessageType[]'
- 'error: string | null'
refs:
- 'messageSet: Set<string>'
- 'eventSource: EventSource'
- 'retryTimeout: NodeJS.Timeout'
- 'retryCount: number'
- 'mounted: boolean'
- 'lastMessageId: string'
chat:
- name: 'ChatMessages'
props:
- 'name: string'
- 'member: ExtendedMember'
- 'chatId: string'
- 'type: channel | conversation'
- 'socketQuery: { spaceId, channelId?, conversationId? }'
features:
- 'Real-time message updates'