# AI Code Generation Guidelines **For AI Assistants**: This document contains strict rules for generating code in the Syndarix project. Follow these rules to ensure generated code matches the design system perfectly. --- ## 🎯 Core Rules ### ALWAYS Do 1. ✅ **Import from `@/components/ui/*`** ```tsx import { Button } from '@/components/ui/button'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; ``` 2. ✅ **Use semantic color tokens** ```tsx className = 'bg-primary text-primary-foreground'; className = 'text-destructive'; className = 'bg-muted text-muted-foreground'; ``` 3. ✅ **Use `cn()` utility for className merging** ```tsx import { cn } from '@/lib/utils'; className={cn("base-classes", conditional && "conditional-classes", className)} ``` 4. ✅ **Follow spacing scale** (multiples of 4: 0, 1, 2, 3, 4, 6, 8, 12, 16) ```tsx className = 'p-4 space-y-6 mb-8'; ``` 5. ✅ **Add accessibility attributes** ```tsx ``` 6. ✅ **Use component variants** ```tsx Error message ``` 7. ✅ **Compose from shadcn/ui primitives** ```tsx // Don't create custom card components // Use Card + CardHeader + CardTitle + CardContent ``` 8. ✅ **Use mobile-first responsive design** ```tsx className = 'text-2xl sm:text-3xl lg:text-4xl'; className = 'grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3'; ``` --- ### NEVER Do 1. ❌ **NO arbitrary colors** ```tsx // ❌ WRONG className = 'bg-blue-500 text-white'; // ✅ CORRECT className = 'bg-primary text-primary-foreground'; ``` 2. ❌ **NO arbitrary spacing values** ```tsx // ❌ WRONG className = 'p-[13px] mb-[17px]'; // ✅ CORRECT className = 'p-4 mb-4'; ``` 3. ❌ **NO inline styles** ```tsx // ❌ WRONG style={{ margin: '10px', color: '#3b82f6' }} // ✅ CORRECT className="m-4 text-primary" ``` 4. ❌ **NO custom CSS classes** (use Tailwind utilities) ```tsx // ❌ WRONG
// ✅ CORRECT
``` 5. ❌ **NO mixing component libraries** ```tsx // ❌ WRONG - Don't use Material-UI, Ant Design, etc. import { Button } from '@mui/material'; // ✅ CORRECT - Only shadcn/ui import { Button } from '@/components/ui/button'; ``` 6. ❌ **NO skipping accessibility** ```tsx // ❌ WRONG // ✅ CORRECT ``` 7. ❌ **NO creating custom variants without CVA** ```tsx // ❌ WRONG ``` --- ## 📐 Layout Patterns ### Page Container ```tsx
{/* Content */}
``` ### Dashboard Grid ```tsx
{items.map((item) => ( ... ))}
``` ### Form Layout ```tsx Form Title
{/* Form fields */}
``` ### Centered Content ```tsx
{/* Readable content width */}
``` --- ## 🧩 Component Templates ### Custom Component Template ```tsx import { cn } from '@/lib/utils'; import { Card } from '@/components/ui/card'; interface MyComponentProps { variant?: 'default' | 'compact'; className?: string; children: React.ReactNode; } export function MyComponent({ variant = 'default', className, children }: MyComponentProps) { return ( {children} ); } ``` ### Component with CVA (class-variance-authority) ```tsx import { cva, type VariantProps } from 'class-variance-authority'; import { cn } from '@/lib/utils'; const componentVariants = cva( 'base-classes-here', // base { variants: { variant: { default: 'bg-primary text-primary-foreground', destructive: 'bg-destructive text-destructive-foreground', }, size: { sm: 'h-8 px-3 text-xs', default: 'h-10 px-4 text-sm', lg: 'h-12 px-6 text-base', }, }, defaultVariants: { variant: 'default', size: 'default', }, } ); interface ComponentProps extends React.HTMLAttributes, VariantProps {} export function Component({ variant, size, className, ...props }: ComponentProps) { return
; } ``` --- ## 📝 Form Pattern Template ```tsx import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Alert } from '@/components/ui/alert'; const formSchema = z.object({ email: z.string().email('Invalid email address'), password: z.string().min(8, 'Password must be at least 8 characters'), }); type FormData = z.infer; export function MyForm() { const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { email: '', password: '', }, }); const onSubmit = async (data: FormData) => { // Handle submission }; return (
{/* Email Field */}
{form.formState.errors.email && (

{form.formState.errors.email.message}

)}
{/* Submit Button */}
); } ``` --- ## 🎨 Color Token Reference **Always use these semantic tokens:** | Token | Usage | | -------------------------------------------- | --------------------- | | `bg-primary text-primary-foreground` | Primary buttons, CTAs | | `bg-secondary text-secondary-foreground` | Secondary actions | | `bg-destructive text-destructive-foreground` | Delete, errors | | `bg-muted text-muted-foreground` | Disabled states | | `bg-accent text-accent-foreground` | Hover states | | `bg-card text-card-foreground` | Card backgrounds | | `text-foreground` | Body text | | `text-muted-foreground` | Secondary text | | `border-border` | Borders | | `ring-ring` | Focus rings | --- ## 📏 Spacing Reference **Use these spacing values (multiples of 4px):** | Class | Value | Pixels | Usage | | ----- | ------ | ------ | ---------------- | | `2` | 0.5rem | 8px | Tight spacing | | `4` | 1rem | 16px | Standard spacing | | `6` | 1.5rem | 24px | Section spacing | | `8` | 2rem | 32px | Large gaps | | `12` | 3rem | 48px | Section dividers | | `16` | 4rem | 64px | Page sections | --- ## 🔑 Decision Trees ### When to use Grid vs Flex? ``` Need equal-width columns? → Use Grid className="grid grid-cols-3 gap-6" Need flexible item sizes? → Use Flex className="flex gap-4" Need 2D layout (rows + columns)? → Use Grid className="grid grid-cols-2 grid-rows-3 gap-4" Need 1D layout (single row OR column)? → Use Flex className="flex flex-col gap-4" ``` ### When to use Margin vs Padding? ``` Spacing between sibling elements? → Use gap or space-y className="flex gap-4" className="space-y-4" Internal element spacing? → Use padding className="p-4" External element spacing? → Avoid margins, use parent gap // ❌ Child with margin
// ✅ Parent with gap
``` --- ## 🚨 Common Mistakes to Avoid ### ❌ Mistake 1: Hardcoding colors ```tsx // ❌ WRONG
Error
// ✅ CORRECT Error message ``` ### ❌ Mistake 2: Arbitrary spacing ```tsx // ❌ WRONG
// ✅ CORRECT
``` ### ❌ Mistake 3: Missing accessibility ```tsx // ❌ WRONG // ✅ CORRECT ``` ### ❌ Mistake 4: Creating custom components unnecessarily ```tsx // ❌ WRONG - Custom component for simple composition function MyCard({ title, children }) { return
{children}
; } // ✅ CORRECT - Use shadcn/ui primitives {title} {children} ; ``` ### ❌ Mistake 5: Not using cn() utility ```tsx // ❌ WRONG
// ✅ CORRECT
``` --- ## 📚 Reference Documentation Before generating code, check these resources: 1. **[Quick Start](./00-quick-start.md)** - Essential patterns 2. **[Components](./02-components.md)** - All shadcn/ui components 3. **[Layouts](./03-layouts.md)** - Layout patterns 4. **[Spacing](./04-spacing-philosophy.md)** - Spacing rules 5. **[Forms](./06-forms.md)** - Form patterns 6. **[Reference](./99-reference.md)** - Quick lookup tables --- ## ✅ Code Generation Checklist Before outputting code, verify: - [ ] All imports from `@/components/ui/*` - [ ] Using semantic color tokens (no `bg-blue-500`) - [ ] Using spacing scale (multiples of 4) - [ ] Using `cn()` for className merging - [ ] Accessibility attributes included - [ ] Mobile-first responsive design - [ ] Composing from shadcn/ui primitives - [ ] Following established patterns from docs - [ ] No inline styles - [ ] No arbitrary values --- ## 🤖 AI Assistant Configuration ### For Claude Code / Cursor Add this to your project context: ``` When generating React/Next.js components: 1. Always import from @/components/ui/* 2. Use semantic tokens (bg-primary, text-destructive) 3. Use cn() utility for classNames 4. Follow spacing scale (4, 8, 12, 16, 24, 32) 5. Add accessibility (labels, ARIA) 6. Use component variants (variant="destructive") 7. Reference: /docs/design-system/08-ai-guidelines.md ``` ### For GitHub Copilot Add to `.github/copilot-instructions.md`: ```markdown # Component Guidelines - Import from @/components/ui/\* - Use semantic colors: bg-primary, text-destructive - Spacing: multiples of 4 (p-4, mb-6, gap-8) - Use cn() for className merging - Add accessibility attributes - See /docs/design-system/08-ai-guidelines.md ``` --- ## 📊 Examples ### ✅ Good Component (AI Generated) ```tsx import { cn } from '@/lib/utils'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; interface DashboardCardProps { title: string; value: string; trend?: 'up' | 'down'; className?: string; } export function DashboardCard({ title, value, trend, className }: DashboardCardProps) { return ( {title}
{value}
{trend && (

{trend === 'up' ? '↑' : '↓'} Trend

)}
); } ``` **Why it's good:** - ✅ Imports from `@/components/ui/*` - ✅ Uses semantic tokens - ✅ Uses `cn()` utility - ✅ Follows spacing scale - ✅ Composes from shadcn/ui primitives - ✅ TypeScript interfaces - ✅ Allows className override --- ## 🎓 Learning Path for AI 1. Read [Quick Start](./00-quick-start.md) - Essential patterns 2. Read this document - Rules and templates 3. Reference [Component Guide](./02-components.md) - All components 4. Check [Reference Tables](./99-reference.md) - Token lookups With these guidelines, you can generate code that perfectly matches the design system. Always prioritize consistency over creativity. --- **Last Updated**: November 2, 2025 **For AI Assistants**: Follow these rules strictly for optimal code generation.