An interactive AI web app built using React (Vite) for the frontend and Node.js + Express for the backend, powered by the OpenAI API.
Deployed live at π openai-project-blue.vercel.app
This project demonstrates how to integrate OpenAIβs API with a full-stack web app.
Users can send prompts through an elegant chat interface β the backend processes requests and fetches intelligent responses from OpenAIβs API, returning them in real-time to the frontend.
Frontend:
- React (with Vite)
- HTML, CSS, JavaScript
- React Hooks & Context API
- Fetch API for backend communication
Backend:
- Node.js
- Express.js
- Mongoose (for handling message threads)
- dotenv (for environment variables)
- CORS enabled
Other Tools:
- Nodemon (for development)
- Vercel (deployment platform)
OPENAI_Project/
β
βββ Backend/
β βββ models/
β β βββ Thread.js # Mongoose model for storing chat threads
β βββ routes/
β β βββ chat.js # Express route for OpenAI API requests
β βββ utils/
β β βββ openAi.js # Handles OpenAI API calls
β βββ server.js # Main Express server
β βββ package.json
β βββ .gitignore
β
βββ Frontend/
βββ public/
βββ src/
β βββ components/ # UI components (Chat window, Input box, etc.)
β βββ context/ # MyContext for managing app state
β βββ App.jsx # Main React app entry point
| βββ Sidebar.jsx
| βββ ChatWindow.jsx
| βββ Chat.jsx
βββ index.html
βββ vite.config.js
βββ package.json
βββ .env (not committed)
βββ README.md
git clone https://github.com/Ayemen18/OPENAI_Project.git
cd OPENAI_Projectcd Backend
npm installCreate a .env file in the Backend directory:
OPENAI_API_KEY=your_openai_api_key_here
MONGODB_URI=your_mongo_connection_stringStart the backend server:
npm run devcd ../Frontend
npm install
npm run devThe frontend should start at:
http://localhost:5173
The backend runs on:
http://localhost:8080
You can try the live version here:
π https://openai-project-blue.vercel.app/
- The user enters a prompt in the chat UI.
- The frontend sends this prompt (and a thread ID) to the backend via an API call.
- The backend:
- Validates input.
- Checks if a thread exists in MongoDB.
- Sends the message to OpenAIβs API using the
openAi.jsutility. - Returns the AI-generated response.
- The frontend displays the response in a conversation format.
β
Real-time AI responses
β
Chat thread storage via MongoDB
β
React Context API for managing global state
β
Secure backend API key handling
β
Easy local development setup
β
Deployed on Vercel for global access
npm run dev # Starts backend with Nodemonnpm run dev # Starts Vite dev server
npm run build # Builds production-ready frontendBoth Frontend and Backend use environment variables.
Create a .env file in the backend with your OpenAI key and database connection string.
The frontend may include a base URL for API calls if required.
Method: POST
Description: Sends a user prompt and receives an AI-generated response.
{
"threadid": "12345",
"message": "Explain what artificial intelligence is."
}{
"reply": "Artificial Intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems..."
}| Code | Message | Description |
|---|---|---|
| 400 | "missing required fields" | threadid or message not provided |
| 500 | "internal server error" | Server or API call failure |
The app is live on Vercel.
If youβre deploying a similar setup:
- Deploy frontend via Vercel (
Frontend/directory as root). - Deploy backend separately (Render, Railway, or Vercel Serverless Functions).
- Ensure API endpoints in frontend point to the live backend URL.
Contributions are welcome!
If you find bugs or have suggestions:
- Fork this repo
- Create a new branch (
feature-branch) - Commit changes
- Submit a pull request
Developed by Ayemen
Full Stack Developer passionate about learning and building AI-powered web apps.
This project is licensed under the MIT License.