An API designed to make mental health support accessible to everyone. Available at https://api-mentalmatters.tdanks.com/
- Mental Health Resources: Access to affirmations, quotes, resources, and mood tracking
- Multi-language Support: Content available in multiple languages
- Secure API Key Authentication: Role-based access control
- Comprehensive Rate Limiting: Tiered rate limits for different endpoints
- CORS Support: Cross-origin resource sharing enabled
- Health Monitoring: Built-in health check endpoint
- Automatic Documentation: Swagger/OpenAPI documentation
The API implements sophisticated rate limiting with different tiers:
- Public Read Endpoints (affirmations, quotes, resources, moods, languages, tags): 200 requests/minute
- Admin Endpoints: 30 requests/minute
- API Key Management: 10 requests/minute
- Documentation: 500 requests/minute
- Default: 100 requests/minute
Algorithms: Uses sliding-window algorithm for better burst protection
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=blockReferrer-Policy: strict-origin-when-cross-originPermissions-Policy: camera=(), microphone=(), geolocation=()Strict-Transport-Security: max-age=31536000; includeSubDomains(production only)
- Automatic revocation of unused keys (30 days)
- Role-based access (USER/ADMIN)
- Secure key validation
- Usage tracking
- Comprehensive input validation for all endpoints
- Request size limits (1MB)
- SQL injection protection via parameterized queries
- XSS protection
# Clone the repository
git clone https://github.com/mentalmatters/mentalmatters-api.git
cd mentalmatters-api
# Install dependencies
bun install
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration
# Run database migrations
bun run db:migrate
# Start development server
bun run devVisit /docs for interactive API documentation powered by Swagger.
- Development:
http://localhost:5177 - Production:
https://api-mentalmatters.tdanks.com
Include your API key in the x-api-key header:
curl -H "x-api-key: your-api-key" https://api-mentalmatters.tdanks.com/affirmationscurl https://api-mentalmatters.tdanks.com/health# Server
PORT=5177
NODE_ENV=production
# Rate Limiting
RATE_LIMIT_HEADERS=true
RATE_LIMIT_VERBOSE=false
# Database
DATABASE_URL=your-database-url
# CORS (optional)
CORS_ORIGIN=https://yourdomain.comWhen RATE_LIMIT_HEADERS=true, responses include:
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Remaining requests in current windowX-RateLimit-Reset: Unix timestamp when the window resetsRetry-After: Seconds to wait before retrying (when rate limited)
{
"message": "Too many requests, please try again later.",
"retryAfter": 45,
"resetTime": "45 seconds"
}- Keep API keys secure: Never expose keys in client-side code
- Use HTTPS: Always use HTTPS in production
- Implement retry logic: Handle rate limiting gracefully
- Validate responses: Always validate API responses
- Monitor usage: Track your API usage to stay within limits
- Environment variables: Never commit secrets to version control
- Input validation: Always validate user input
- Error handling: Don't expose internal errors in production
- Logging: Implement proper logging for debugging
- Updates: Keep dependencies updated
GET /- Welcome messageGET /health- Health checkGET /docs- API documentationGET /affirmations- Get affirmationsGET /quotes- Get quotesGET /resources- Get resourcesGET /moods- Get moodsGET /languages- Get supported languagesGET /tags- Get tags
POST /affirmations- Create affirmation (ADMIN only)PUT /affirmations/:id- Update affirmation (ADMIN only)DELETE /affirmations/:id- Delete affirmation (ADMIN only)POST /quotes- Create quote (ADMIN only)PUT /quotes/:id- Update quote (ADMIN only)DELETE /quotes/:id- Delete quote (ADMIN only)POST /resources- Create resource (ADMIN only)PUT /resources/:id- Update resource (ADMIN only)DELETE /resources/:id- Delete resource (ADMIN only)
GET /api-keys- List API keys (ADMIN only)POST /api-keys- Create API key (ADMIN only)DELETE /api-keys/:id- Revoke API key (ADMIN only)
The API returns consistent error responses:
{
"message": "Human-readable error message",
"requestId": "uuid-for-tracking",
"error": "ERROR_CODE"
}MISSING_API_KEY- API key required but not providedINVALID_API_KEY- API key is invalid or revokedVALIDATION_ERROR- Input validation failedNOT_FOUND- Resource not foundRATE_LIMITED- Rate limit exceeded
Monitor API health with the /health endpoint:
{
"status": "healthy",
"timestamp": "2024-01-01T00:00:00.000Z",
"uptime": 3600
}All errors include a requestId for tracking:
{
"message": "Error message",
"requestId": "550e8400-e29b-41d4-a716-446655440000"
}- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you need help or have questions:
- Check the API documentation
- Open an issue on GitHub
- Contact the maintainers
Remember: You matter, and support is always here for you. Take care. β€οΈβπ©Ή