An advanced AI-powered emotional support system providing 24/7 anonymous, compassionate conversations to help users navigate life's challenges. Built with cutting-edge AI models and modern web technologies.
- AI-Powered Conversations: Real-time emotional analysis and empathetic responses powered by Google Gemini, RoBERTa, and DialoGPT
- Emotion Detection: Advanced NLP to understand user emotions and feelings in real-time
- Crisis Detection: Intelligent crisis keyword detection with immediate resources and hotline recommendations
- Mental Wellness Tools:
- π΅ Music Suggestions (curated calming playlists)
- π¬οΈ Breathing Exercises (guided relaxation techniques)
- π§ Mental Exercises (cognitive reframing & mindfulness)
- π‘ Mood Insights (emotional pattern analysis)
- π¨ββοΈ Professional Help (connect with licensed therapists)
- Anonymous & Confidential: No user accounts or personal data collection required
- Session Management: Conversation history per session with emotion tracking
- Rate Limiting: Built-in API rate limiting to prevent abuse
- Security: XSS protection, CORS configuration, input sanitization
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (Next.js) β
β ββ Chat Interface (React Components) β
β ββ Real-time Message Display β
β ββ Feature Toggle UI (Music, Breathing, etc.) β
β ββ Emotion Display & Analytics β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ
β HTTPS/HTTP
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββ
β NGINX (Reverse Proxy) β
β ββ SSL/TLS Termination β
β ββ Request Routing (frontend β port 3000, backend β port 5000)β
β ββ Rate Limiting β
β ββ Security Headers β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββ΄βββββββββββββββ
β β
βββββββββΌβββββββββββ ββββββββββββββΌβββββββββ
β BACKEND (Flask) β β AUXILIARY SERVICES β
ββββββββββββββββββββ€ βββββββββββββββββββββββ€
β API Routes: β β β’ PostgreSQL β
β β’ /api/chat β β β’ Redis β
β β’ /api/analyze β β β’ Hugging Face β
β β’ /api/health β β β’ Google Gemini β
β β’ /api/crisis... β β β
β β β β
β Services: β β β
β β’ ChatService β β β
β β’ Middleware β β β
β β’ Error Handler β β β
ββββββββββββββββββββ βββββββββββββββββββββββ
β
ββββ ML Models ββββ¬βββββββββββββββββββ
β β
βββββββββββββΌβββββββ ββββββββΌββββββββββββββ
β Emotion Detector β β Empathy Refiner β
β (RoBERTa) β β (DialoGPT) β
β - 27 emotions β β - Enhanced empathy β
β - Intensity β β - Better responses β
ββββββββββββββββββββ ββββββββββββββββββββββ
β
βββββββββββββ΄βββββββββββ
β Crisis Detector β
β (Pattern Matching) β
β - Hotline detect β
β - Resources β
ββββββββββββββββββββββββ
- Next.js 14.0 - React framework with SSR & static generation
- TypeScript - Type-safe JavaScript
- Tailwind CSS - Utility-first CSS framework
- Lucide React - Beautiful SVG icons
- Axios - HTTP client for API communication
- Framer Motion - Smooth animations
- Chart.js - Data visualization
- Flask 2.3 - Lightweight Python web framework
- Flask-CORS - Cross-origin resource sharing
- Flask-Limiter - Rate limiting
- Transformers (Hugging Face) - Pre-trained ML models
- RoBERTa - Emotion detection (27 emotion classes)
- DialoGPT - Empathetic dialogue generation
- Google Gemini API - Advanced LLM for response generation
- PyTorch - Deep learning framework
- Pydantic - Data validation
- SQLAlchemy - ORM for database operations
- Docker & Docker Compose - Containerization
- PostgreSQL 15 - Relational database
- Redis 7 - Session storage & caching
- Nginx - Reverse proxy & web server
- Gunicorn - WSGI HTTP server for Flask
- User sends message β Frontend (Next.js)
- Frontend sends to Flask API β
/api/chatendpoint - Backend processes message:
- Emotion Detection (RoBERTa)
- Crisis Detection (pattern matching)
- Gemini API (generate initial response)
- Empathy Refiner (DialoGPT enhancement)
- Response returned with metadata:
- Response text
- Detected emotions
- Crisis status
- Session ID
- Frontend displays in chat interface with emotion indicators
- Node.js (v18+)
- Python 3.10+
- Git
The backend handles the AI routing and PyTorch ML models.
# Navigate to project root
cd ai-emotional-support
# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows use: .venv\Scripts\activate
# Install dependencies
pip install -r backend/requirements.txt
# Create .env and add your Gemini key
cp .env.example .env
# Run the backend server
python backend/wsgi.pyThe frontend is a Next.js 14 application.
# Open a new terminal and navigate to frontend
cd ai-emotional-support/frontend
# Install dependencies
npm install
# Run the development server
npm run dev -- -p 3001Access the application at: http://localhost:3001
# Required for core AI functionality
GEMINI_API_KEY=your_google_gemini_api_key
# Optional
FLASK_ENV=developmentThis project includes automated Bash scripts to completely provision and deploy a production-ready environment (Nginx, SSL, PM2, systemd) to a fresh Linode instance.
Execute setup_linode.sh on your fresh Linode server to install Python, Node.js, Nginx, and all system dependencies.
# SSH into your Linode
ssh root@your-linode-ip
# Run the setup script
git clone https://github.com/xyrenExo/ai-emotional-support.git
cd ai-emotional-support
chmod +x setup_linode.sh
./setup_linode.shWhenever you push new code or want to restart the production services, use the deploy.sh script. This handles building the Next.js app and restarting the Python backend cleanly.
chmod +x deploy.sh
./deploy.sh- The deployment scripts automatically configure Nginx as a reverse proxy.
- Frontend binds to
localhost:3000internally, while the backend binds tolocalhost:5000. - Certbot handles automatic SSL generation if a custom domain is configured.
- Cause: Git merge conflict markers in Dockerfile
- Solution: Run
git statusand resolve conflicts
- Cause:
GEMINI_API_KEYnot set or invalid - Solution: Verify
.envfile has valid API key
- Cause: PostgreSQL not running or credentials wrong
- Solution: Check
docker-compose logs postgres
- Cause: CORS misconfiguration
- Solution: Verify
ALLOWED_ORIGINSincludes frontend hostname
- Cause: Internet timeout during Docker build
- Solution: Run
docker-compose build --no-cacheagain
- Response time:
/api/chatshould return in < 5 seconds - Error rate: Monitor HTTP 500 responses
- Model inference time: Logged in
docker-compose logs backend - Database query time: Optimizable with indexing
# View all logs
docker-compose logs
# Follow backend logs
docker-compose logs -f backend
# Follow frontend logs
docker-compose logs -f frontendβ Implemented
- HTTPS/TLS encryption
- CORS whitelisting
- Rate limiting (per IP)
- Input sanitization & validation
- XSS protection
- CSRF protection via session tokens
- Security headers (X-Frame-Options, X-Content-Type-Options)
- User authentication
- Database encryption at rest
- API key rotation
- Audit logging
- Penetration testing
- DDoS protection (Cloudflare, AWS Shield)
emotional-support-ai/
βββ backend/
β βββ app/
β β βββ api/
β β β βββ routes.py # API endpoints
β β β βββ middleware.py # Security & CORS
β β βββ models/
β β β βββ emotion_model.py # RoBERTa emotion detection
β β β βββ crisis_detector.py # Crisis keyword detection
β β β βββ gemini_client.py # Gemini API wrapper
β β β βββ empathy_refiner.py # DialoGPT enhancement
β β βββ services/
β β β βββ chat_service.py # Main chat logic
β β β βββ analysis_service.py# Analytics
β β βββ __init__.py # Flask app factory
β β βββ config.py # Configuration
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend container
β βββ wsgi.py # Gunicorn entry point
βββ frontend/
β βββ src/
β β βββ app/
β β β βββ chat/ # Chat page
β β β βββ layout.tsx # Layout
β β βββ components/ # React components
β β βββ hooks/ # Custom hooks
β β βββ lib/ # Utilities
β β βββ types/ # TypeScript types
β βββ package.json # Node dependencies
β βββ tsconfig.json # TypeScript config
β βββ Dockerfile # Frontend container
βββ nginx/
β βββ nginx.conf # Reverse proxy config
βββ docker-compose.yml # Container orchestration
βββ .env.example # Environment template
βββ README.md # This file
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
- Suicide & Crisis Lifeline: 988 (US)
- Crisis Text Line: Text HOME to 741741
- International Association for Suicide Prevention: https://www.iasp.info/resources/Crisis_Centres/
- User authentication & persistence
- Video/voice chat support
- Integration with calendars for therapy appointments
- AI-powered mood journaling
- Multi-language support
- Mobile app (React Native)
- Real therapist matchmaking
- Advanced analytics dashboard
- Offline mode support
Built with β€οΈ for mental health and well-being
Last Updated: April 2026