This is the backend API for Sense AI - an accessible AI assistant with real-time voice-to-text, text-to-speech, subscriptions, and wearable integrations.
- Development:
http://localhost:5000 - Production:
https://your-domain.com
The API uses JWT (JSON Web Tokens) for authentication. Include the access token in the Authorization header:
Authorization: Bearer <access_token>
Register a new user account.
Request Body:
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "SecurePass123!",
"phone": "+1234567890"
}Response (201):
{
"success": true,
"message": "User registered successfully",
"data": {
"user": {
"_id": "64a1b2c3d4e5f6789012345",
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"subscriptionTier": "free",
"subscriptionExpiry": null,
"usageMetrics": {
"voiceMinutesUsed": 0,
"textCharactersUsed": 0,
"apiCallsUsed": 0,
"lastResetDate": "2024-01-15T10:30:00.000Z"
},
"provider": "local",
"avatar": null,
"isEmailVerified": false,
"isActive": true,
"lastLogin": null,
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
},
"tokens": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
}Login with email and password.
Request Body:
{
"email": "john.doe@example.com",
"password": "SecurePass123!"
}Response (200):
{
"success": true,
"message": "Login successful",
"data": {
"user": {
"_id": "64a1b2c3d4e5f6789012345",
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"subscriptionTier": "free",
"subscriptionExpiry": null,
"usageMetrics": {
"voiceMinutesUsed": 5,
"textCharactersUsed": 250,
"apiCallsUsed": 12,
"lastResetDate": "2024-01-15T10:30:00.000Z"
},
"provider": "local",
"avatar": null,
"isEmailVerified": false,
"isActive": true,
"lastLogin": "2024-01-15T12:45:00.000Z",
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T12:45:00.000Z"
},
"tokens": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
}Refresh access token using refresh token.
Request Body:
{
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Response (200):
{
"success": true,
"message": "Token refreshed successfully",
"data": {
"tokens": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
}Logout user and invalidate refresh token.
Headers:
Authorization: Bearer <access_token>
Request Body:
{
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Response (200):
{
"success": true,
"message": "Logout successful"
}Initiate Google OAuth login.
Response: Redirects to Google OAuth consent screen.
Google OAuth callback (handled automatically).
Initiate GitHub OAuth login.
Response: Redirects to GitHub OAuth consent screen.
GitHub OAuth callback (handled automatically).
Get current user profile.
Headers:
Authorization: Bearer <access_token>
Response (200):
{
"success": true,
"message": "Profile retrieved successfully",
"data": {
"user": {
"_id": "64a1b2c3d4e5f6789012345",
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"subscriptionTier": "premium",
"subscriptionExpiry": "2024-12-31T23:59:59.000Z",
"usageMetrics": {
"voiceMinutesUsed": 45,
"textCharactersUsed": 5000,
"apiCallsUsed": 200,
"lastResetDate": "2024-01-15T10:30:00.000Z"
},
"provider": "local",
"avatar": null,
"isEmailVerified": true,
"isActive": true,
"lastLogin": "2024-01-15T12:45:00.000Z",
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T12:45:00.000Z"
}
}
}Update user profile.
Headers:
Authorization: Bearer <access_token>
Request Body:
{
"name": "John Smith",
"phone": "+1987654321"
}Response (200):
{
"success": true,
"message": "Profile updated successfully",
"data": {
"user": {
"_id": "64a1b2c3d4e5f6789012345",
"name": "John Smith",
"email": "john.doe@example.com",
"phone": "+1987654321",
"subscriptionTier": "premium",
"subscriptionExpiry": "2024-12-31T23:59:59.000Z",
"usageMetrics": {
"voiceMinutesUsed": 45,
"textCharactersUsed": 5000,
"apiCallsUsed": 200,
"lastResetDate": "2024-01-15T10:30:00.000Z"
},
"provider": "local",
"avatar": null,
"isEmailVerified": true,
"isActive": true,
"lastLogin": "2024-01-15T12:45:00.000Z",
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T14:20:00.000Z"
}
}
}Change user password.
Headers:
Authorization: Bearer <access_token>
Request Body:
{
"currentPassword": "SecurePass123!",
"newPassword": "NewSecurePass456!",
"confirmPassword": "NewSecurePass456!"
}Response (200):
{
"success": true,
"message": "Password changed successfully. Please login again."
}Get user usage metrics and limits.
Headers:
Authorization: Bearer <access_token>
Response (200):
{
"success": true,
"message": "Usage metrics retrieved successfully",
"data": {
"usage": {
"voiceMinutesUsed": 45,
"textCharactersUsed": 5000,
"apiCallsUsed": 200,
"lastResetDate": "2024-01-15T10:30:00.000Z"
},
"limits": {
"voiceMinutes": 10,
"textCharacters": 1000,
"apiCalls": 50
},
"subscriptionTier": "free"
}
}Delete user account (soft delete).
Headers:
Authorization: Bearer <access_token>
Response (200):
{
"success": true,
"message": "Account deleted successfully"
}Get current user (optional authentication).
Headers (Optional):
Authorization: Bearer <access_token>
Response (200) - Authenticated:
{
"success": true,
"message": "User authenticated",
"data": {
"user": {
"_id": "64a1b2c3d4e5f6789012345",
"name": "John Doe",
"email": "john.doe@example.com",
"subscriptionTier": "premium",
"isPremium": true
}
}
}Response (200) - Not Authenticated:
{
"success": false,
"message": "No user authenticated",
"data": {
"user": null
}
}Health check endpoint.
Response (200):
{
"success": true,
"message": "Sense AI Backend is running",
"timestamp": "2024-01-15T14:30:00.000Z",
"environment": "development",
"version": "1.0.0"
}API documentation endpoint.
Response (200):
{
"success": true,
"message": "Sense AI API",
"version": "1.0.0",
"endpoints": {
"auth": {
"signup": "POST /api/auth/signup",
"login": "POST /api/auth/login",
"refresh": "POST /api/auth/refresh",
"logout": "POST /api/auth/logout",
"profile": "GET /api/auth/profile",
"updateProfile": "PUT /api/auth/profile",
"changePassword": "PUT /api/auth/change-password",
"deleteAccount": "DELETE /api/auth/account",
"usage": "GET /api/auth/usage",
"google": "GET /api/auth/google",
"github": "GET /api/auth/github"
}
}
}{
"success": false,
"message": "Validation failed",
"errors": [
{
"field": "email",
"message": "Please provide a valid email address",
"value": "invalid-email"
}
]
}{
"success": false,
"message": "Access token is required"
}{
"success": false,
"message": "Premium subscription required",
"code": "PREMIUM_REQUIRED",
"subscriptionTier": "free"
}{
"success": false,
"message": "Route not found",
"path": "/api/invalid-route"
}{
"success": false,
"message": "Too many requests from this IP, please try again later"
}{
"success": false,
"message": "Internal server error"
}- Global Rate Limit: 100 requests per 15 minutes per IP
- Auth Rate Limit: 5 authentication attempts per 15 minutes per IP
- Strict Auth Rate Limit: 3 password change attempts per 15 minutes per IP
Create a .env file in the root directory with the following variables:
# Database Configuration
MONGO_URI=mongodb+srv://senewtech:admin@senew-cluster.rg6pb.mongodb.net/sense_ai
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_here_make_it_very_long_and_secure
JWT_REFRESH_SECRET=your_super_secret_refresh_jwt_key_here_make_it_very_long_and_secure
JWT_EXPIRE=15m
JWT_REFRESH_EXPIRE=7d
# OAuth Configuration
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
GITHUB_CLIENT_ID=your_github_client_id_here
GITHUB_CLIENT_SECRET=your_github_client_secret_here
# Session Configuration
SESSION_SECRET=your_session_secret_here_make_it_very_long_and_secure
# Server Configuration
PORT=5000
NODE_ENV=development
# CORS Configuration
FRONTEND_URL=http://localhost:3000
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100- Create a new Postman collection called "Sense AI API"
- Set the base URL variable:
{{baseUrl}}=http://localhost:5000 - Create an environment variable for
accessToken
POST {{baseUrl}}/api/auth/signup
Content-Type: application/json
{
"name": "Test User",
"email": "test@example.com",
"password": "TestPass123!",
"phone": "+1234567890"
}
POST {{baseUrl}}/api/auth/login
Content-Type: application/json
{
"email": "test@example.com",
"password": "TestPass123!"
}
GET {{baseUrl}}/api/auth/profile
Authorization: Bearer {{accessToken}}
PUT {{baseUrl}}/api/auth/profile
Authorization: Bearer {{accessToken}}
Content-Type: application/json
{
"name": "Updated Name",
"phone": "+1987654321"
}
- Password Hashing: Uses bcrypt with salt rounds of 12
- JWT Tokens: Access tokens (15min) and refresh tokens (7 days)
- Rate Limiting: Prevents brute force attacks
- CORS: Configured for specific frontend origins
- Helmet: Security headers
- Input Validation: Comprehensive validation using express-validator
- Error Handling: Secure error messages in production
- Voice minutes: 10 per month
- Text characters: 1,000 per month
- API calls: 50 per month
- Voice minutes: Unlimited
- Text characters: Unlimited
- API calls: Unlimited
- Advanced AI features
- Priority support