This project is a ChatBot application built using the MERN stack (MongoDB, Express.js, React, Node.js) and integrated with the OpenAI API for natural language processing.
- Natural Language Processing: Utilizes the OpenAI API to understand and respond to user input.
- User Authentication: Secure user login and registration using JWT tokens and encrypted passwords.
- Message History: Stores user messages in a database, allowing for message retrieval and deletion.
- Middleware Chains: Protects routes and handles errors effectively.
- Responsive UI: A clean and intuitive user interface built with React.
-
Clone the repository:
git clone https://github.com/your-username/MERN-ChatBot.git cd MERN-ChatBot -
Install dependencies for both the frontend and backend:
# For the backend cd backend npm install # For the frontend cd ../frontend npm install
-
Set up the environment variables (see the Environment Variables section below).
-
Run the application:
npm run dev
-
Open your browser:
- Visit
http://localhost:3000to access the ChatBot application.
- Visit
- Register or log in to start using the ChatBot.
- Interact with the bot by typing messages into the chat interface.
- View your chat history or delete messages as needed.
Create a .env file in the backend directory with the following environment variables:
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
OPENAI_API_KEY=your_openai_api_key
- MongoDB: Database for storing user messages and authentication data.
- Express.js: Backend framework to handle API requests and middleware.
- React: Frontend library for building the user interface.
- Node.js: JavaScript runtime environment for running the server-side code.
- OpenAI API: Provides natural language processing capabilities.
MERN-ChatBot/
│
├── frontend/ # React frontend code
│ ├── public/ # Static files
│ └── src/ # React components, hooks, and pages
│
├── backend/ # Node.js backend code
│ ├── config/ # Configuration files (e.g., database, JWT)
│ ├── controllers/ # Route controllers
│ ├── models/ # Mongoose models
│ ├── routes/ # Express routes
│ ├── middleware/ # Middleware functions
│ └── utils/ # Utility functions
│
└── README.md # This file
- JWT Tokens: Secure authentication with JSON Web Tokens.
- Password Encryption: User passwords are securely hashed before storing them in the database.
- HTTP-Only Cookies: Tokens are stored in HTTP-only cookies to prevent XSS attacks.