SafeSpace is a Flutter-based mobile application focused on mental health, counseling, and safe community interactions.
The app provides users with a supportive platform to connect with counselors, access resources, and engage in anonymous group discussions.
- π Authentication β Secure sign-up and sign-in with Supabase
- π§ Entertainment & Relaxation β Meditation, music, and interactive exercises
- π€ AI Chatbot β Intelligent mental health assistant powered by Groq LLM with real-time responses
- π§ Mental State Analysis β Automatic analysis of user messages to predict mental health states
- π‘ AI Suggestions β Personalized wellness recommendations based on dominant mental state
- π¨ββοΈ Doctor Recommendations β Smart matching with mental health professionals based on mental state
- π¬ Entertainment Recommendations β Curated content matching user's emotional needs
- π Crisis Detection β Immediate crisis response with emergency hotline numbers
- π¨ββοΈ Counselor Channeling β Book appointments and connect via Google Meet (Future development)
- π Forum / Blog β Share thoughts, stories, and mental health tips (Future development)
- π¬ Anonymous Group Chat β Engage in peer-to-peer conversations safely (Future development)
- Frontend: Flutter (Dart)
- Backend: FastAPI (Python) with Groq LLM integration
- Database: Supabase (PostgreSQL) with real-time subscriptions
- Authentication: Supabase Auth
- Storage: Supabase Storage
- AI/ML:
- Groq API (LLaMA 3.1 for conversational AI)
- Mental state prediction with heuristic fallback
- Transformers & PyTorch for NLP
- Real-time: Supabase WebSocket subscriptions
- Integrations: Google Meet API (Future)
- Install Flutter (>=3.27.3)
- Install Dart
- Setup Supabase Project
- Configure your API Keys and Environment Variables
# Clone the repository
git clone https://github.com/DhanukaRathnayaka/Final_Year_Project.git
# Navigate to project directory
cd Final_Year_Project
# Get Flutter dependencies
flutter pub get
# Set up your Supabase configuration
# Create a new file lib/supabase_config.dart with your Supabase credentials:
# ```dart
# const supabaseUrl = 'YOUR_SUPABASE_URL';
# const supabaseAnonKey = 'YOUR_SUPABASE_ANON_KEY';
# ```
# Run the Flutter app
flutter runIf you don't want to run the backend locally and instead use the deployed API (for example, https://backend-t3db.onrender.com), the Flutter app already supports a compile-time switch.
Run with the deployed backend by passing a dart-define flag:
# Web
flutter run -d chrome --dart-define=USE_DEPLOYED_BACKEND=true
# Android or iOS
flutter run --dart-define=USE_DEPLOYED_BACKEND=trueThis instructs the app to use the configured deployed URL. If you want to hardcode the deployed URL without the flag, see lib/config.dart and set useDeployedBackend to true.
Note: The deployed backend has CORS enabled (see lib/Backend/app.py), so there should be no origin issues when accessing it from web or mobile clients. If you experience any CORS errors, open the deployed API logs and ensure allow_origins is configured correctly.
The backend server is located in the lib/Backend directory and consists of:
- FastAPI server for the main API
- Mental Health Chatbot with sentiment analysis
- Supabase integration for data storage
# Navigate to backend directory
cd lib/Backend
# Create and activate virtual environment
python -m venv venv
.\venv\Scripts\activate # On Windows
# source venv/bin/activate # On Linux/Mac
# Install dependencies
pip install -r requirements.txt
# Install additional AI-related packages
pip install transformers torch numpy fastapi uvicorn python-dotenv supabaseCreate a .env file in the lib/Backend directory:
# Supabase Configuration
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_service_key
# Groq API Configuration (Required for AI Chatbot)
GROQ_API_KEY=your_groq_api_key
# Optional - OpenAI API
OPENAI_API_KEY=your_openai_api_key
# Debug Mode
DEBUG=falseNote: To get a Groq API key, visit Groq Console
Create the following tables in your Supabase database:
Core Tables:
conversationsβ Store chat conversations and sessionsmessagesβ Store individual messages in conversationsusersβ User profiles and metadata
Mental Health Analysis:
mental_state_reportsβ Store mental state analysis results with dominant state and confidence
Recommendations:
doctorsβ Mental health professionals databaseentertainmentsβ Entertainment content (music, videos, exercises)suggestionsβ Daily wellness suggestions databaserecommended_doctorβ User-doctor assignmentsrecommended_entertainmentsβ User entertainment recommendationsrecommended_suggestionsβ User suggestion recommendations
For detailed schema and RLS policies, see the documentation files in the project root.
# From the lib/Backend directory
uvicorn app:app --reload --port 8000The backend API will be available at: π http://localhost:8000
Interactive API docs will be available at: π http://localhost:8000/docs
Deployed API docs (Render): π https://backend-t3db.onrender.com/docs#/
- POST
/api/chatβ Send message to AI chatbot
- POST
/api/predict-mental-stateβ Predict mental state from text
- GET
/ai-suggestions/suggestions/{user_id}β Get personalized AI suggestions - GET
/recommend_entertainment/api/suggestions/{user_id}β Get entertainment recommendations - POST
/recommendβ Get doctor recommendations - GET
/api/suggestions/{user_id}β Get combined suggestions
For detailed API documentation, visit the API Documentation.
Comprehensive documentation is available:
- Backend & Chatbot Flow β Complete system architecture and flows
- Architecture Diagrams β Visual representations of all processes
- Implementation Guide β Setup, configuration, and troubleshooting
The SafeSpace system works as follows:
- User Authentication β User logs in via Supabase Auth
- Chat Initiation β User starts conversation with AI chatbot
- Real-time Messaging β Messages sync via Supabase real-time subscriptions
- AI Processing β Groq LLM generates compassionate responses
- Mental State Analysis β After 5+ messages, system analyzes mental state
- Personalized Recommendations β Based on dominant mental state:
- AI-generated wellness suggestions
- Entertainment content matching mood
- Doctor matching by specialization
- Crisis Detection β If crisis keywords detected, immediate hotline numbers provided
- Kavindu Dedunupitiya β Project Lead and UX UI Designer ( 22UG1-0812 )
- Dhanuka Rathnayaka β Fullstack Developer ( 22UG1-0828 )
- Gayanga Bandara β Fullstack Developer (22UG1-0285)