Skip to content

⚛️ 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.


Important: Make sure you’re in your main project folder (not inside the backend folder).

Terminal window
npm create vite@latest openai-frontend --template react
cd openai-frontend

Why Vite? It’s lightning fast, has hot reloading, and builds are instant. Much better than Create React App.


Install the core packages:

Terminal window
npm install

Add chat-specific packages:

Terminal window
npm install lucide-react react-markdown

Add Tailwind CSS:

Terminal window
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 formatting
  • tailwindcss - Modern CSS without writing CSS files

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

Replace the contents of src/index.css:

@import "tailwindcss";

That’s it! Tailwind’s new version is much simpler to set up.


Start your frontend:

Terminal window
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 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

❌ “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

Now you have two servers running:

Backend (Port 8000):

Terminal window
# In your openai-backend folder
npm run dev

Frontend (Port 5173):

Terminal window
# In your openai-frontend folder
npm 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!