KumiaiBot is a full-stack AI chatbot web application developed using the MERN stack (MongoDB, Express.js, React.js, and Node.js) and integrated with the OpenAI API to generate intelligent, natural-language responses.
The application provides a ChatGPT-like conversational experience with secure user authentication, persistent user data, responsive UI, and real-time communication between the frontend, backend, database, and OpenAI services.
KumiaiBot was developed as a full-stack AI-powered chatbot application that allows users to register, securely log in, and interact with an AI assistant through a modern web interface.
The application sends user messages from the React frontend to the Node.js/Express backend. The backend securely communicates with the OpenAI API, receives the generated response, and sends it back to the frontend.
User authentication and application data are managed using MongoDB.
May 2024 – June 2024
Full-Stack AI Web Application
- 🤖 AI-powered chatbot using the OpenAI API
- 💬 ChatGPT-like conversational interface
- 👤 User registration
- 🔐 Secure user login
- 🔑 JWT-based authentication
- 🍪 HTTP-only cookies for authentication
- 🗄️ MongoDB database integration
- ⚡ REST API communication
- 🔄 Axios-based frontend/backend communication
- 🎨 React and Material UI interface
- 📱 Responsive web design
- 💾 Persistent user information
- 🧠 Automatically generated AI responses
- 🔒 Backend-based OpenAI API integration
- 🚪 Secure logout functionality
- React.js
- Material UI
- Axios
- JavaScript
- HTML5
- CSS3
- Node.js
- Express.js
- REST API
- JWT
- HTTP-only Cookies
- MongoDB
- MongoDB Atlas / MongoDB Server
- OpenAI API
- OpenAI SDK
- Git
- GitHub
- npm
- Visual Studio Code
┌─────────────────────┐
│ User │
│ Web Browser │
└──────────┬──────────┘
│
│ User Message
▼
┌─────────────────────┐
│ React Frontend │
│ Material UI │
└──────────┬──────────┘
│
│ Axios / REST API
▼
┌─────────────────────┐
│ Node.js + Express │
│ Backend │
└───────┬─────┬───────┘
│ │
┌───────────┘ └──────────────┐
│ │
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ MongoDB │ │ OpenAI API │
│ │ │ │
│ Users / Data │ │ AI Generation │
└──────────────────┘ └────────┬─────────┘
│
│ AI Response
▼
┌─────────────────────┐
│ Express Backend │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ React Frontend │
│ Display Response │
└─────────────────────┘
The exact structure may vary slightly depending on the version of the repository, but the application follows a typical MERN architecture:
chatbot/
│
├── backend/
│ ├── controllers/
│ ├── models/
│ ├── routes/
│ ├── middleware/
│ ├── config/
│ ├── server.js
│ ├── package.json
│ └── .env
│
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── services/
│ │ ├── App.js
│ │ └── index.js
│ ├── public/
│ ├── package.json
│ └── .env
│
├── .gitignore
└── README.md
Follow the steps below to run KumiaiBot locally.
Before running the application, install the following software:
- Node.js
- npm
- Git
- MongoDB or MongoDB Atlas account
- OpenAI API key
You can verify Node.js and npm installation using:
node --versionnpm --versionClone the repository from GitHub:
git clone https://github.com/KumeshaRashmi/chatbot.gitMove into the project directory:
cd chatbotNavigate to the backend directory:
cd backendInstall the required npm packages:
npm installThe backend dependencies include packages such as:
express
mongoose
jsonwebtoken
cookie-parser
cors
dotenv
openai
bcrypt / bcryptjs
The exact dependencies installed by
npm installare defined in the project'spackage.json.
Open another terminal or navigate back to the project root:
cd ..Then move into the frontend directory:
cd frontendInstall the frontend dependencies:
npm installThe frontend uses technologies including:
react
axios
@mui/material
@emotion/react
@emotion/styled
Environment variables are required for sensitive configuration such as the MongoDB connection and OpenAI API key.
OpenAI recommends keeping API keys on the server and storing them through environment variables rather than exposing them in browser-side code.
Inside the backend directory, create:
.env
Add the required configuration:
PORT=5000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_secure_jwt_secret
OPENAI_API_KEY=your_openai_api_keyReplace:
your_mongodb_connection_string
with your MongoDB connection string.
Replace:
your_secure_jwt_secret
with a strong secret used for JWT authentication.
Replace:
your_openai_api_key
with your OpenAI API key.
The official OpenAI JavaScript SDK can be installed with:
npm install openaiand is designed for server-side JavaScript environments such as Node.js.
Never commit your .env file to GitHub.
Add the following to .gitignore:
node_modules/
.env
.env.localYour API key should remain private.
Do not write:
const apiKey = "sk-your-secret-key";inside frontend React components.
Instead, the frontend should communicate with your backend, and the backend should communicate with OpenAI.
React
│
│ User message
▼
Express Backend
│
│ OpenAI API request
▼
OpenAI
│
│ Generated response
▼
Express Backend
│
▼
React
This architecture prevents the OpenAI secret key from being exposed to users.
You can use either:
- Local MongoDB
- MongoDB Atlas
Example MongoDB connection:
MONGODB_URI=mongodb://localhost:27017/kumiaiBotOr a MongoDB Atlas connection:
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/kumiaiBotMake sure your MongoDB server is running before starting the backend.
Navigate to the backend directory:
cd backendStart the server:
npm startOr, if the project uses a development script:
npm run devThe backend should start on something similar to:
http://localhost:5000
Open a new terminal.
Navigate to the frontend:
cd frontendStart the React development server:
npm startThe frontend will normally be available at:
http://localhost:3000
Open the URL in your browser.
Once the application is running:
Create a new user account using the registration page.
Log in using your registered credentials.
After successful authentication, access the chatbot interface.
Enter a question or prompt into the chat input.
For example:
Explain what machine learning is.
The frontend sends the message to the backend using Axios.
React → Axios → Express API
The backend sends the request to the OpenAI API.
Express Backend → OpenAI API
OpenAI generates an AI response.
The backend returns the generated response to React.
OpenAI
↓
Express
↓
Axios
↓
React
↓
Chat Interface
The response is then automatically displayed in the conversation.
KumiaiBot uses JWT-based authentication.
The authentication process works as follows:
User
│
│ Register / Login
▼
React Frontend
│
│ Axios Request
▼
Express Backend
│
├── Validate User
│
├── Check MongoDB
│
└── Generate JWT
│
▼
HTTP-only Cookie
After authentication, protected API requests can be authenticated using the JWT stored in the HTTP-only cookie.
- Secure authentication
- Password-based user accounts
- JWT-based authorization
- HTTP-only cookies
- Protected backend routes
- Persistent user sessions
The chatbot integrates the OpenAI API through the backend.
The basic request flow is:
User Input
│
▼
React Chat Interface
│
▼
Axios POST Request
│
▼
Express API
│
▼
OpenAI SDK
│
▼
OpenAI Model
│
▼
Generated AI Response
│
▼
Express API
│
▼
React
│
▼
Chat Message
The OpenAI API provides the AI-generated natural-language response. The official OpenAI JavaScript SDK supports server-side Node.js applications and can be installed through npm.
A simplified chatbot request can look like:
POST /api/chatRequest:
{
"message": "What is artificial intelligence?"
}Backend:
Receive message
↓
Validate request
↓
Send prompt to OpenAI
↓
Receive generated response
↓
Return response to frontend
Response:
{
"response": "Artificial intelligence is a field of computer science..."
}Axios is used to communicate between the React frontend and Express backend.
Example:
axios.post("/api/chat", {
message: userMessage
});The backend processes the request and returns the AI-generated response.
This separation keeps the frontend responsible for presentation while the backend handles authentication, database operations, and OpenAI API communication.
After starting both servers, test the following functionality:
- User registration
- User login
- Invalid login handling
- JWT authentication
- HTTP-only cookie
- Logout
- Send message
- Receive AI response
- Multiple messages
- Empty message validation
- API error handling
- MongoDB connection
- User creation
- User authentication
- Data persistence
- Responsive layout
- Chat interface
- Login page
- Registration page
- Navigation
- Error messages
If you receive an error related to the API key, check that:
OPENAI_API_KEY=your_api_keyexists in the backend .env file.
Restart the backend after changing environment variables.
OpenAI's documentation recommends configuring the SDK through the OPENAI_API_KEY environment variable.
Check:
MONGODB_URI=your_connection_stringMake sure MongoDB is running and the connection string is correct.
For MongoDB Atlas, ensure that your IP address is permitted in the Atlas network access configuration.
If the frontend cannot communicate with the backend, verify:
- Backend server is running
- Frontend URL is configured correctly
- CORS middleware is enabled
- API endpoint URL is correct
If port 5000 or 3000 is already being used, stop the process using that port or configure a different port.
Example:
PORT=5001The application uses several security mechanisms:
- JWT authentication
- HTTP-only cookies
- Environment variables
- Backend-only OpenAI API communication
- Password hashing
- Protected API routes
- MongoDB authentication
Do not commit:
.env
API keys
JWT secrets
Database passwords
to GitHub.
OpenAI specifically recommends not committing API keys to repositories and recommends environment variables for API-key management.
Possible improvements for future versions include:
- 💾 Persistent chat history
- 🗂️ Multiple conversations
- 📝 Conversation titles
- 🗑️ Delete conversations
- 🔍 Search chat history
- 🌙 Dark/light theme
- 🎙️ Voice input
- 🔊 Text-to-speech
- 📎 File uploads
- 🧠 RAG-based document question answering
- 📊 Usage analytics
- ⚡ Streaming AI responses
- 👥 Multi-user conversation management
- 🛡️ Rate limiting
- 🚀 Cloud deployment
- 🐳 Docker containerization
Through this project, the following technical concepts were practiced:
- Full-stack web application development
- MERN stack development
- REST API development
- React component development
- Material UI
- MongoDB database integration
- User authentication
- JWT authentication
- HTTP-only cookies
- API integration
- OpenAI API integration
- Asynchronous JavaScript
- Axios communication
- Environment variable management
- Backend security
- Git and GitHub
Add screenshots of the application here.
Example:
## Login Page

## Chat Interface

## Registration Page
Recommended screenshots:
- Login page
- Registration page
- Chat interface
- AI-generated response
- Responsive/mobile interface
Kumesha Rashmi
Computer Engineering Undergraduate University of Ruhuna, Sri Lanka
GitHub:
https://github.com/KumeshaRashmi
This project was developed as an academic/personal software development project.
You may modify and extend the project for learning and development purposes.
- React.js
- Node.js
- Express.js
- MongoDB
- Material UI
- Axios
- OpenAI API
For experienced developers, the complete setup can be summarized as:
# Clone repository
git clone https://github.com/KumeshaRashmi/chatbot.git
cd chatbot
# Install backend
cd backend
npm install
# Configure .env
# Add MONGODB_URI
# Add JWT_SECRET
# Add OPENAI_API_KEY
# Start backend
npm startIn another terminal:
cd chatbot/frontend
npm install
npm startThen open:
http://localhost:3000