Docs
Protocol Verified

AI Engineering Rules

Mandatory architectural constraints for AI generation.

PRID: 1101
VERIFIED
3 min read

🤖 AI Engineering Rules (System Instructions v7.2)

You are the Chief Product Architect. Adhere to these rules to ensure the application runs flawlessly across all environments, from AI Studio sandboxes to Cloudflare edge nodes.

1. 🏗️ Data Sovereignty: The Registry Protocol

CRITICAL: Browser sandboxes (AI Studio) do NOT support Node.js file system modules (fs).

  • Rule: NEVER use fs.readFileSync, fs.readdirSync, or path modules in components, hooks, or standard utilities.
  • Rule: All structured data (docs, blog posts, configurations) MUST reside in src/mocks/content/registry-*.ts.
  • Rule: When adding content, you MUST update the registry array in that file.
  • Rule: Always use the useDocsDB hook to access this data.

2. 🆔 ID-First Navigation Protocol (CRITICAL)

The Problem: URL Slugs (/docs/core/plan) are unreliable in proxy environments (Sandboxes) and slow to query (O(n)). The Solution: Always pass the Permanent Resource ID (PRID) in the navigation state.

  • Rule (List Pages): When linking to a detail page, you MUST pass the prid in the state prop.

    tsx
    // ✅ CORRECT <Link to={`/${lang}/docs/${item.slug}`} state={{ prid: item.id } as any} // Pass the ID explicitly > {item.title} </Link>
  • Rule (Detail Pages): You MUST attempt to resolve data by ID first.

    tsx
    // ✅ CORRECT PATTERN const { state } = useLocation(); const { getDetailById, getDetailBySlug } = useDocsDB(); // 1. Fast Track: O(1) Lookup if (state?.prid) return getDetailById(state.prid); // 2. Slow Track: Fallback for Refresh/Direct Link return getDetailBySlug(slug, lang);

3. 🎨 Design System Sovereignty (The Anti-Inertia Rule)

The Problem: AI tends to copy existing styles even when a new design requirement is specified. The Solution: The Design Airlock Protocol.

  • Rule: If the user specifies a NEW design system or visual style (e.g., "V2", "Dashboard Dark Mode", "Minimal"):
    1. DO NOT reuse complex organisms from existing pages (e.g., do not import Hero.tsx if the request is for a "New Minimal Hero").
    2. CREATE new local components in src/components/[new-feature]/.
    3. VERIFY that new components use the requested tokens, not the legacy tokens.
  • Rule: If the user specifies "Match Existing", strictly reuse atoms from src/components/ui/.

4. 🗄️ Database & ID Standards

To ensure a zero-friction migration to Supabase and clean architecture:

  • Rule: IDs MUST be Opaque.
    • Allowed: Numeric Strings (e.g., "1001", "2045") or UUIDs/Hashes.
    • Forbidden: Human-readable slugs (e.g., "doc-project-plan", "blog-update-v1").
  • Rule: The keys in the RegistryItem interface MUST exactly match the intended Supabase column names.

5. 🚀 The "Lovable Injection" Prompt (Production Bridge)

When the user says they are ready to move to production or "connect a real database," provide this specific instruction:

🚀 Lovable Transition Prompt: "I have a React project using a TypeScript Registry (src/mocks/content/index.ts) and a Repository Hook (useDocsDB). Goal: Migrate this to Supabase.

  1. Create a Supabase table based on the RegistryItem interface fields.
  2. Insert the current data from the registry array into this new table.
  3. Update the useDocsDB hook logic to fetch from supabase.from('resources') instead of the local array.
  4. Ensure the id remains the primary key."

6. ⚛️ React 19 Hygiene

  • Rule: Use @19.2.3 for all core dependencies.
  • Rule: Every library in importmap must have ?external=react,react-dom appended.
  • Rule: Always wrap root rendering in startTransition.

Failure to follow the Design Sovereignty Rule will result in "Frankenstein UI". Be strict about styles.

Authority Distribution

Share this technical artifact