An intelligent, full-stack mental health support chatbot combining BERT-based sentiment analysis (Python) and Google Gemini AI for empathetic, context-aware responses.
- BERT-based sentiment analysis for emotional context detection (Python microservice)
- Google Gemini-2.0-flash powered responses (via backend integration)
- Detects multiple emotional states (depression, anxiety, stress, etc.)
- Crisis detection and immediate help resources
- Chat history and sentiment tracking (MongoDB)
- Secure user authentication and JWT-based sessions
- Admin panel for user and chat management
- Modern, responsive web UI
- Backend: Node.js (Express)
- Frontend: HTML, CSS, JavaScript
- AI/ML:
- BERT-based sentiment analysis (Python Flask service, HuggingFace Transformers, PyTorch)
- Google Gemini-2.0-flash (via @google/generative-ai)
- Database: MongoDB (Mongoose ODM)
- Authentication: JWT
- Security: dotenv, rate limiting, CORS, input validation
mental_health_chatbot/
├── app.js # Main server entry point
├── config/
│ └── db.js # MongoDB connection
├── controllers/ # Route handlers (chat, user, gemini)
├── middleware/ # Auth/admin JWT middlewares
├── models/ # Mongoose schemas (User, Chat)
├── public/ # Frontend (HTML, CSS, JS)
├── routes/ # Express route definitions
├── sentiment_service/ # Python LSTM sentiment microservice
│ ├── app.py # Flask API
│ ├── model/ # Model files (tokenizer, vocab, weights)
│ └── requirements.txt # Python dependencies
├── .env # Environment variables (NOT committed)
├── package.json # Node.js dependencies and scripts
└── README.md
git clone https://github.com/YOUR_USERNAME/mental_health_chatbot.git
cd mental_health_chatbot
npm installcd sentiment_service
pip install -r requirements.txt
cd ..Create a .env file in the root directory:
MONGO_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret
GOOGLE_API_KEY=your_gemini_api_key
PORT=your_port_number
...
- Start backend server:
npm run dev
- Start sentiment service:
npm run sentiment-service
- Or use the provided PowerShell script:
npm run start-all
- Visit [http://localhost:] for the chatbot UI
- Admin panel: [http://localhost:/admin.html]for admin access
POST /api/chat/message— Send message to chatbotGET /api/chat/history— Get user's chat history
POST /api/auth/register— Register new userPOST /api/auth/login— Login user
GET /api/admin/users— List usersPATCH /api/admin/user/:id— Edit userDELETE /api/admin/user/:id— Delete userGET /api/admin/chats— List chats- ...and more
- Sensitive data: All secrets loaded from
.env(never committed) - JWT authentication for all user/admin routes
- Rate limiting and CORS enabled
- Input validation on all endpoints
- Sentiment Service: Python Flask app exposes
/predictendpoint for BERT-based sentiment analysis using HuggingFace Transformers and PyTorch - Gemini Integration: Google Gemini API used for generating empathetic, context-aware responses
- Detects crisis keywords and provides immediate help resources and helplines
This project is for educational and non-commercial use. Please see LICENSE for details.
- Google Gemini for generative AI
- BERT for BERT-based sentiment analysis
- MongoDB for database
Note: If you deploy this project, ensure your
.envand sensitive files are never pushed to public repositories.
The chatbot includes an automated crisis detection system that:
- Identifies potential crisis situations
- Provides immediate helpline information
- Encourages professional help when needed