# Design Decision: Complete React Example with Actual Code **Date:** 2024-02-24 **Scope:** src/api/routes.py tool_instructions ## Problem Model is still not following instructions: 1. Tries `npm install` before creating package.json 2. Still tries `npx create-react-app` despite being told not to 3. Instructions have placeholders like "..." and "etc." which models don't understand ## Root Cause The current instructions say: ``` TOOL: write ARGUMENTS: {"filePath": "myapp/package.json", "content": "{\"name\": \"myapp\", \"version\": \"1.0.0\", \"dependencies\": {\"react\": \"^18.0.0\", \"react-dom\": \"^18.0.0\"}}"} [Continue with src/index.js, src/App.js, public/index.html, etc.] ``` **Problem:** "etc." and "..." are meaningless to LLMs. They need concrete examples. ## Solution Provide a **complete, working, minimal React example** with actual file contents: 1. Exact sequence: mkdir → write package.json → write src/App.js → write src/index.js → write public/index.html → npm install 2. Actual file content, not placeholders 3. Minimal viable React app (not full create-react-app structure) ## Implementation Replace vague example with complete working code: ``` **COMPLETE REACT HELLO WORLD EXAMPLE:** User: "Create a React Hello World app" Step 1 - Create directory: TOOL: bash ARGUMENTS: {"command": "mkdir myapp"} Step 2 - Create package.json (MUST do this BEFORE npm install): TOOL: write ARGUMENTS: {"filePath": "myapp/package.json", "content": "{\"name\": \"myapp\", \"version\": \"1.0.0\", \"private\": true, \"dependencies\": {\"react\": \"^18.2.0\", \"react-dom\": \"^18.2.0\"}, \"scripts\": {\"start\": \"react-scripts start\", \"build\": \"react-scripts build\"}, \"devDependencies\": {\"react-scripts\": \"5.0.1\"}}"} Step 3 - Create src directory: TOOL: bash ARGUMENTS: {"command": "mkdir myapp/src"} Step 4 - Create App.js: TOOL: write ARGUMENTS: {"filePath": "myapp/src/App.js", "content": "import React from 'react';\n\nfunction App() {\n return (\n
\n

Hello World

\n

Welcome to my React app!

\n
\n );\n}\n\nexport default App;"} Step 5 - Create index.js: TOOL: write ARGUMENTS: {"filePath": "myapp/src/index.js", "content": "import React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport App from './App';\n\nconst root = ReactDOM.createRoot(document.getElementById('root'));\nroot.render();"} Step 6 - Create public directory and index.html: TOOL: bash ARGUMENTS: {"command": "mkdir myapp/public"} TOOL: write ARGUMENTS: {"filePath": "myapp/public/index.html", "content": "\n\n\n \n \n React App\n\n\n
\n\n"} Step 7 - NOW install dependencies (AFTER package.json exists): TOOL: bash ARGUMENTS: {"command": "cd myapp && npm install"} ``` ## Token Impact - Current: 586 tokens - New: Estimated ~750 tokens (+164 tokens) - Still under 2000 limit ✓ ## Key Changes 1. **Explicit sequencing:** "Step 1", "Step 2", etc. 2. **Actual code:** No "..." or "etc." - real working content 3. **Critical note:** "MUST do this BEFORE npm install" 4. **Minimal structure:** Just what's needed for Hello World ## Success Criteria - [ ] Model creates package.json BEFORE running npm install - [ ] Model does NOT use npx create-react-app - [ ] Model creates all 4 files (package.json, App.js, index.js, index.html) - [ ] Model runs npm install last (after files exist)