⚛️ React Frontend Setup
Time to build the visual side of your AI chat app! 🎨
We’re using React with Vite (super fast) and Tailwind CSS (beautiful styling without the hassle). Your frontend will be clean, modern, and ready to chat with AI.
🚀 Step 1: Create Your React App
Section titled “🚀 Step 1: Create Your React App”Important: Make sure you’re in your main project folder (not inside the backend folder).
npm create vite@latest openai-frontend --template reactcd openai-frontend
Why Vite? It’s lightning fast, has hot reloading, and builds are instant. Much better than Create React App.
📦 Step 2: Install Essential Packages
Section titled “📦 Step 2: Install Essential Packages”Install the core packages:
npm install
Add chat-specific packages:
npm install lucide-react react-markdown
Add Tailwind CSS:
npm install -D tailwindcss @tailwindcss/vite
What each package does:
lucide-react
- Beautiful icons (send buttons, loading spinners, etc.)react-markdown
- Renders AI responses with proper formattingtailwindcss
- Modern CSS without writing CSS files
⚙️ Step 3: Configure Clean Imports
Section titled “⚙️ Step 3: Configure Clean Imports”Tired of imports like ../../../components/Button
? Let’s fix that.
Update vite.config.js
:
import { defineConfig } from 'vite'import react from '@vitejs/plugin-react'import tailwindcss from '@tailwindcss/vite'
export default defineConfig({ resolve: { alias: { '@': '/src', }, }, plugins: [react(), tailwindcss()],})
Now you can import like this:
import Button from '@/components/Button' // ✅ Clean// Instead of: import Button from '../../../components/Button' ❌ Messy
🎨 Step 4: Setup Tailwind CSS
Section titled “🎨 Step 4: Setup Tailwind CSS”Replace the contents of src/index.css
:
@import "tailwindcss";
That’s it! Tailwind’s new version is much simpler to set up.
🧪 Step 5: Test Your Setup
Section titled “🧪 Step 5: Test Your Setup”Start your frontend:
npm run dev
You should see: Local: http://localhost:5173
Test Tailwind by updating src/App.jsx
:
function App() { return ( <div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4"> <div className="bg-white rounded-2xl shadow-xl p-8 max-w-md w-full"> <div className="text-center"> <div className="w-16 h-16 bg-gradient-to-r from-blue-500 to-indigo-600 rounded-full flex items-center justify-center mx-auto mb-4"> <span className="text-2xl">🤖</span> </div> <h1 className="text-2xl font-bold text-gray-800 mb-2"> AI Chat Frontend </h1> <p className="text-gray-600"> Ready to connect to your intelligent backend! </p> <div className="mt-6"> <div className="inline-flex items-center px-4 py-2 bg-green-100 text-green-800 rounded-full text-sm"> ✅ Frontend Ready </div> </div> </div> </div> </div> )}
export default App
Success looks like: A beautiful centered card with gradient background and AI emoji.
📂 Your Project Structure
Section titled “📂 Your Project Structure”Your frontend should look like this:
openai-frontend/├── src/│ ├── App.jsx # Your main component│ ├── index.css # Tailwind imports│ └── main.jsx # React entry point├── vite.config.js # Vite configuration├── package.json # Dependencies└── index.html # HTML template
🔧 Common Issues & Solutions
Section titled “🔧 Common Issues & Solutions”❌ “Vite command not found”
- Make sure Node.js is installed
- Try
npx create vite@latest
instead
❌ “Tailwind styles not working”
- Check
src/index.css
has@import "tailwindcss";
- Restart your dev server (
npm run dev
)
❌ “Import alias not working”
- Restart dev server after changing
vite.config.js
- Make sure the path starts with
@/
❌ “Port already in use”
- Vite will automatically find the next available port (5174, 5175, etc.)
- Or specify a port:
npm run dev -- --port 3000
🌐 Development Workflow
Section titled “🌐 Development Workflow”Now you have two servers running:
Backend (Port 8000):
# In your openai-backend foldernpm run dev
Frontend (Port 5173):
# In your openai-frontend foldernpm run dev
Pro tip: Open two terminal tabs to run both simultaneously.
Perfect! Your frontend is ready for AI integration. ✨
You now have:
- ⚡ Lightning-fast development with Vite
- 🎨 Beautiful styling with Tailwind CSS
- 🧹 Clean imports with path aliases
- 🤖 Modern React setup ready for chat components
👉 Next: Building the Chat Interface - Let’s create the actual chat UI!