A comprehensive backend system for mental health assessments with multilingual support (English & Kashmiri), advanced scoring algorithms, and personalized recommendations.
- Multiple Assessment Tools: PHQ-9, GAD-7, GHQ-12, PSS-10, K-10, WHO-5, BRS, UCLA Loneliness Scale, ISI, MBI-SS, AUDIT, 16 Personality MBTI
- Multilingual Support: English and Kashmiri languages
- Advanced Scoring: Handles reverse scoring, MBTI trait calculation, percentile calculations
- Privacy-First: Anonymous user IDs, no personally identifiable information stored
- Real-time Results: Immediate scoring and interpretation
- Personalized Suggestions: Based on test scores and personality type
- Category-Based: Meditation, counseling, lifestyle, exercise, social, medical recommendations
- Priority-Based: Urgent, high, medium, low priority recommendations
- Evidence-Based: Clinically validated recommendation strategies
- Anonymous User Tracking: Secure anonymous IDs for session management
- Data Protection: IP and device hashing, no PII storage
- CORS Configuration: Secure frontend communication
- Data Retention: Automatic cleanup of old data (1 years)
| Test | Full Name | Purpose | Questions | Languages |
|---|---|---|---|---|
| PHQ-9 | Patient Health Questionnaire | Depression screening | 9 | EN, KS |
| GAD-7 | Generalized Anxiety Disorder Scale | Anxiety screening | 7 | EN, KS |
| GHQ-12 | General Health Questionnaire | Mental health screening | 12 | EN, KS |
| PSS-10 | Perceived Stress Scale | Stress measurement | 10 | EN, KS |
| K-10 | Kessler Psychological Distress Scale | Psychological distress | 10 | EN, KS |
| WHO-5 | WHO Well-Being Index | Well-being assessment | 5 | EN, KS |
| BRS | Brief Resilience Scale | Resilience measurement | 6 | EN, KS |
| UCLA | UCLA Loneliness Scale | Loneliness assessment | 8 | EN, KS |
| ISI | Insomnia Severity Index | Sleep disorder screening | 7 | EN, KS |
| MBI-SS | Maslach Burnout Inventory - Student | Academic burnout | 7 | EN, KS |
| AUDIT | Alcohol Use Disorders Identification | Alcohol screening | 10 | EN, KS |
| 16PER/MBTI | 16 Personality Type Indicator | Personality assessment | 8+ | EN, KS |
- Node.js (v16 or higher)
- MongoDB (local or cloud)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd p_tests
-
Install dependencies
npm install
-
Environment Configuration
cp .env.example .env # Edit .env with your configuration -
Database Setup
# Start MongoDB (if local) mongod # The application will auto-create collections and indexes
-
Start the server
# Development mode with auto-restart npm run dev # Production mode npm start
# Database
MONGODB_URI=mongodb://localhost:27017/mental_health_tests
# Server
NODE_ENV=development
PORT=3000
# CORS Origins
FRONTEND_URL_1=http://localhost:3001
FRONTEND_URL_2=http://127.0.0.1:3001
# Security
SESSION_SECRET=your-session-secret
JWT_SECRET=your-jwt-secret
# Rate Limiting
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=15
# Data Retention (days)
DATA_RETENTION_DAYS=365GET /api/v1/questions/:testName
GET /api/v1/questions/phq9
GET /api/v1/questions/gad7
GET /api/v1/questions/mbtiPOST /api/v1/answers/:testName
POST /api/v1/answers/batch
POST /api/v1/answers/:testName/validateGET /api/v1/answers/user/:userId
GET /api/v1/answers/recommendations/:userId
PUT /api/v1/answers/recommendations/:recommendationId/readGET /api/health
GET /api/docs
GET /api/v1/answers/testsPOST /api/v1/answers/phq9
Content-Type: application/json
{
"answers": {
"1": 2,
"2": 1,
"3": 3,
// ... all 9 answers
},
"language": "en",
"userId": "2024092301a1b2c3d4e5f6" // optional
}{
"success": true,
"data": {
"userId": "2024092301a1b2c3d4e5f6",
"testResults": {
"rawScore": 12,
"maxPossibleScore": 27,
"percentile": 44,
"severity": {
"level": "moderate",
"label": "Moderate depression"
},
"interpretation": {
"min": 10,
"max": 14,
"severity": { "en": "Moderate depression" }
},
"recommendations": [...]
},
"recommendations": [...],
"timestamp": "2024-09-23T10:30:00Z"
}
}POST /api/v1/answers/batch
Content-Type: application/json
{
"tests": [
{
"testName": "phq9",
"answers": { "1": 2, "2": 1, ... }
},
{
"testName": "gad7",
"answers": { "1": 3, "2": 2, ... }
}
],
"language": "en",
"userId": "2024092301a1b2c3d4e5f6"
}For MBTI personality types, the system provides:
- Type-specific coping strategies
- Tailored intervention approaches
- Personality-aware therapy recommendations
- Learning style considerations
- Meditation: Mindfulness, breathing exercises, guided meditation
- Counseling: Professional therapy, support groups, crisis resources
- Lifestyle: Exercise, nutrition, sleep hygiene, routine building
- Social: Community connections, relationship building
- Medical: Professional evaluation, medication consideration
- Educational: Self-help resources, books, articles
- user_results: Test results with anonymous user IDs
- recommendations: Personalized recommendations
- user_analytics: Privacy-preserving usage statistics
- system_analytics: Aggregate system statistics (no personal data)
- Anonymous user IDs (timestamp + random hash)
- IP and device information hashed
- No personally identifiable information stored
- Automatic data cleanup after retention period
- User analytics opt-out support
// Anonymous ID format: 2024092301a1b2c3d4e5f6
// 10 digits (timestamp) + 12 hex characters (random)
const anonymousId = generateAnonymousId();- All sensitive data hashed using SHA-256
- IP addresses hashed for analytics
- User agent strings hashed for device tracking
- No session cookies or authentication required
- CORS protection for API access
- User results: 1 years maximum
- Recommendations: Until expiry date
- Analytics: Aggregated data only
- Automatic cleanup processes
- English (en): Default language
- Kashmiri (ks): Regional language support
- Test questions translated
- Response options localized
- Severity interpretations translated
- Recommendations in user's language
- Error messages localized
GET /api/healthReturns system status, database connectivity, memory usage, and uptime.
- Test completion rates
- Language usage statistics
- Popular test combinations
- System performance metrics
- Error tracking and monitoring
- 200: Success
- 400: Bad Request (invalid data)
- 404: Not Found (test/user not found)
- 429: Too Many Requests (rate limiting)
- 500: Internal Server Error
{
"success": false,
"error": "Error type",
"message": "Detailed error description"
}npm run dev# Run tests (when implemented)
npm test
# Validate test data
node src/scripts/validateTestData.jsnpm run seed- Set
NODE_ENV=production - Configure production MongoDB URI
- Set up proper CORS origins
- Enable rate limiting
- Configure data retention policies
- Set up monitoring and logging
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]- 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
ISC License - see LICENSE file for details.
For support and questions:
- Check the API documentation:
GET /api/docs - Review health status:
GET /api/health - Contact: [Your contact information]
Built with β€οΈ for mental health awareness and support