A full-stack mental health web application built with React (Vite), TypeScript, Tailwind CSS, and FastAPI. Features a community feed similar to Facebook, role-based access control, reactions system, and professional comment functionality.
- Firebase Authentication - Secure email/password authentication
- Role-Based Signup - Users can register as: User, Doctor, Therapist, or Psychiatrist
- Community Feed - View and create anonymous posts
- Reaction System - React to posts with Support, Relate, or Care
- Professional Comments - Only healthcare professionals can comment on posts
- Real-time Updates - Firestore integration for live data
- Token-Based Auth - Firebase ID tokens for all API requests
- Backend Validation - Role verification on every request
- Firestore Rules - Database-level security rules
- CORS Protection - Restricted cross-origin requests
- React 19 with Vite
- TypeScript
- Tailwind CSS
- Axios for API calls
- React Router for navigation
- Firebase SDK for authentication and Firestore
- Lucide React for icons
- Python FastAPI
- Uvicorn ASGI server
- Firebase Admin SDK
- Pydantic for data validation
- Firestore for database
mindsathiV2/
βββ src/
β βββ pages/
β β βββ LoginPage.tsx # Login page
β β βββ LoginSignupPage.tsx # Signup page with role selection
β β βββ FeedPage.tsx # Main community feed
β β βββ Home.tsx # Legacy home page
β β βββ Therapy.tsx # Legacy therapy page
β β βββ Chat.tsx # Legacy chat page
β β βββ Professionals.tsx # Legacy professionals page
β β βββ Wellness.tsx # Legacy wellness page
β βββ components/
β β βββ Navbar.tsx # Navigation bar
β β βββ CreatePost.tsx # Post creation component
β β βββ PostCard.tsx # Individual post component
β β βββ ReactionBar.tsx # Reactions UI
β β βββ CommentSection.tsx # Comments UI
β βββ services/
β β βββ api.ts # Axios API client
β βββ context/
β β βββ AuthContext.tsx # Firebase auth context
β βββ config/
β β βββ firebase.ts # Firebase configuration
β βββ types.ts # TypeScript types
β βββ App.tsx # Main app component
β βββ main.tsx # Entry point
β βββ index.css # Global styles
βββ backend/
β βββ main.py # FastAPI app
β βββ firebase_config.py # Firebase setup
β βββ models.py # Pydantic models
β βββ requirements.txt # Python dependencies
β βββ routes/
β β βββ posts.py # Posts endpoints
β β βββ reactions.py # Reactions endpoints
β β βββ comments.py # Comments endpoints
β βββ README.md # Backend documentation
βββ package.json
βββ tsconfig.json
βββ vite.config.ts
βββ .env.example
βββ README.md
- Node.js 18+
- Python 3.10+
- Firebase project (create at https://firebase.google.com)
- npm or yarn
cd mindsathiV2
npm install- Go to Firebase Console
- Create a new project or use existing one
- Enable Authentication:
- Go to Authentication β Sign-in method
- Enable "Email/Password"
- Enable Firestore:
- Go to Firestore Database
- Create database (start in production mode)
- Update security rules (see below)
- Get your Firebase config:
- Go to Project Settings β Your apps β Web app
- Copy the config object
Copy .env.example to .env and fill in your Firebase credentials:
# Frontend Firebase
VITE_FIREBASE_API_KEY=your_api_key
VITE_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your_project_id
VITE_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
VITE_FIREBASE_APP_ID=your_app_id
# API Configuration
VITE_API_BASE_URL=http://localhost:8000/api
# Gemini API (optional)
GEMINI_API_KEY=your_gemini_keycd backend
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
pip install -r requirements.txt-
Download service account key:
- Go to Firebase Console β Project Settings β Service Accounts
- Click "Generate New Private Key"
- Save as
backend/firebase-key.json
-
Create
.envin root directory (for backend):
FIREBASE_SERVICE_ACCOUNT_KEY_PATH=./backend/firebase-key.json
Go to Firestore β Rules and replace with:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Users collection
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
// Posts collection
match /posts/{postId} {
allow create: if request.auth != null;
allow read: if request.auth != null;
allow delete: if request.auth.uid == resource.data.userId;
}
// Reactions collection
match /reactions/{reactionId} {
allow create: if request.auth != null;
allow read: if request.auth != null;
allow delete: if request.auth.uid == resource.data.userId;
}
// Comments collection
match /comments/{commentId} {
allow create: if request.auth != null &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role in ['doctor', 'therapist', 'psychiatrist'];
allow read: if request.auth != null;
allow delete: if request.auth.uid == resource.data.authorId;
}
}
}
npm run devFrontend will be available at: http://localhost:5173
cd backend
# Activate virtual environment
# Windows: venv\Scripts\activate
# macOS/Linux: source venv/bin/activate
python -m uvicorn main:app --reload --port 8000Backend will be available at: http://localhost:8000
API Docs: http://localhost:8000/docs
- Go to
http://localhost:5173/signup - Create an account with:
- Email:
test@example.com - Password:
password123 - Role: Select one (User, Doctor, Therapist, or Psychiatrist)
- Email:
- Login with your credentials
As a User:
- Create posts anonymously
- React to posts (Support, Relate, Care)
- View all posts and reactions
- Cannot comment (restricted to professionals)
As a Professional (Doctor/Therapist/Psychiatrist):
- All user features above
- Comment on posts
- Reply to user concerns
- See your professional badge
POST /api/posts Create post
GET /api/posts Get all posts
GET /api/posts/{id} Get specific post
POST /api/posts/{id}/react Add/remove reaction
GET /api/posts/{id}/reactions Get all reactions
POST /api/posts/{id}/comment Add comment (professionals only)
GET /api/posts/{id}/comments Get comments
DELETE /api/posts/{id}/comments/{cid} Delete comment
GET /api/auth/me Get current user profile (role + alias)
GET /api/feed AI-ranked feed
POST /api/chat Chat with Sathi (chatbot)
GET /api/users/me/mood Mood history (last 30)
POST /api/users/me/mood Log a daily mood (1-5)
All endpoints require Firebase ID token in Authorization header:
Authorization: Bearer {firebase_id_token}
{
"email": "string",
"role": "user | doctor | therapist | psychiatrist",
"createdAt": "timestamp"
}{
"id": "string",
"content": "string",
"userId": "string",
"userRole": "string",
"createdAt": "string (ISO)",
"reactionCounts": {
"support": 0,
"relate": 0,
"care": 0
},
"commentCount": 0
}{
"id": "string",
"postId": "string",
"userId": "string",
"type": "support | relate | care",
"createdAt": "string (ISO)"
}{
"id": "string",
"postId": "string",
"content": "string",
"authorId": "string",
"authorRole": "string",
"createdAt": "string (ISO)"
}β Frontend:
- Firebase SDK token refreshing
- Protected routes
- Automatic token inclusion in API calls
β Backend:
- Token verification on every request
- Role-based access control
- Input validation with Pydantic
- Error handling and logging
β Database:
- Firestore security rules
- User-level data isolation
- Role verification for comments
- Verify
.envvalues match Firebase Console - Check internet connection
- Clear browser cache
# Check Python version
python --version # Should be 3.10+
# Reinstall dependencies
pip install -r requirements.txt
# Run with detailed output
uvicorn main:app --reload --log-level debug- Check if backend is running on port 8000
- Verify
VITE_API_BASE_URLin.env - Check browser Network tab for request details
- Ensure Firebase token is being sent
- Verify your account role in Firebase Console
- Only doctors, therapists, psychiatrists can comment
- Hard refresh the page (Ctrl+F5)
- Sentiment analysis for stress detection
- One-on-one professional consultations
- Post editing and deletion
- User profiles and messaging
- Advanced feed filtering
- Notification system
- Mobile app
- AI chatbot for immediate support
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions, please open an issue on GitHub or contact the development team.
Made with β€οΈ for mental health awareness