A complete Node.js backend API for a mobile Q&A application with AI integration.
- User Authentication - Registration, login, email verification, JWT tokens, password reset
- Questions & Answers - Full CRUD operations with voting and search
- Comments System - Add comments to questions and answers
- Bookmarks - Save questions for later reference
- File Uploads - Support for image and document attachments
- AI Integration - Powered by Google Gemini AI for suggestions and improvements
- Admin Panel - Content moderation, user management, and reporting system
- Reputation System - User reputation based on community engagement
- Search & Filtering - Full-text search with advanced filtering options
- Pagination - Efficient data loading for mobile clients
- Error Handling - Comprehensive error handling and validation
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- AI Integration: Google Gemini AI
- File Upload: Multer
- Email: Nodemailer
- Security: bcryptjs for password hashing
- Node.js (v14 or higher)
- MongoDB (local or cloud)
- Google Gemini API key (for AI features)
- Email service credentials (for email verification)
-
Install Dependencies
npm install
-
Environment Setup
- Copy
.envfile and update with your credentials - Set your MongoDB URI
- Add your Gemini API key
- Configure email settings
- Copy
-
Start the Server
npm start
For development with auto-reload:
npm run dev
-
Verify Installation
- Open http://localhost:3000
- You should see the API status page
POST /api/auth/register- Register new userPOST /api/auth/login- User loginGET /api/auth/verify/:token- Email verificationGET /api/auth/me- Get current user profilePUT /api/auth/profile- Update user profile
GET /api/questions- Get all questions (with pagination)POST /api/questions- Create new questionGET /api/questions/:id- Get specific questionPUT /api/questions/:id- Update questionDELETE /api/questions/:id- Delete questionGET /api/questions/search- Search questionsPOST /api/questions/:id/vote- Vote on question
GET /api/answers/question/:questionId- Get answers for questionPOST /api/answers/:questionId- Create new answerPUT /api/answers/:id- Update answerDELETE /api/answers/:id- Delete answerPOST /api/answers/:id/vote- Vote on answerPOST /api/answers/:id/accept- Accept answer as solution
GET /api/comments/question/:questionId- Get question commentsGET /api/comments/answer/:answerId- Get answer commentsPOST /api/comments/question/:questionId- Add comment to questionPOST /api/comments/answer/:answerId- Add comment to answerPUT /api/comments/:id- Update commentDELETE /api/comments/:id- Delete comment
GET /api/ai/status- Check AI service statusPOST /api/ai/answer-suggestion- Get AI answer suggestionsPOST /api/ai/tag-suggestions- Get tag suggestionsPOST /api/ai/chatbot- AI chatbot interactionPOST /api/ai/question-improvements- Get question improvement suggestionsPOST /api/ai/similar-questions- Find similar questions
GET /api/users/me- Get current user profileGET /api/users/:id- Get user profile by IDPUT /api/users/profile- Update user profileGET /api/users/leaderboard- Get top users by reputationGET /api/users/search- Search usersGET /api/users/:id/activity- Get user activity feed
GET /api/bookmarks- Get user bookmarksPOST /api/bookmarks/:questionId- Add bookmarkDELETE /api/bookmarks/:questionId- Remove bookmarkGET /api/bookmarks/check/:questionId- Check bookmark status
POST /api/upload- Upload file (images, documents)
GET /api/admin/reports- Get all reportsPOST /api/admin/reports- Create new reportPUT /api/admin/reports/:id/resolve- Resolve reportGET /api/admin/stats- Get admin dashboard statisticsDELETE /api/admin/content/:type/:id- Delete content as adminPUT /api/admin/users/:id- Manage user (ban/promote/etc.)
This backend is specifically designed for mobile applications with:
- RESTful API - Clean, predictable endpoints
- JSON Responses - Lightweight data format
- CORS Support - Cross-origin requests enabled
- Token Authentication - Stateless authentication perfect for mobile
- Pagination - Efficient data loading for mobile networks
- Error Handling - Consistent error response format
- JWT Authentication - Secure token-based authentication
- Password Hashing - bcryptjs for secure password storage
- Input Validation - Comprehensive request validation
- Role-based Access - Admin and user roles
- CORS Protection - Controlled cross-origin access
- File Upload Security - File type and size restrictions
- Question upvote: +5 reputation
- Answer upvote: +10 reputation
- Accepted answer: +15 reputation bonus
- Downvotes: -2 to -5 reputation
- Answer Suggestions: AI analyzes questions and provides helpful answers
- Tag Suggestions: Automatic tag recommendations based on content
- Question Improvements: AI feedback for better question formulation
- Chatbot: General programming help and guidance
- User Reports: Community-driven content reporting
- Admin Dashboard: Centralized moderation tools
- Automated Actions: Bulk content management
- User Management: Ban, promote, and manage user accounts
You can test the API using tools like:
- Postman - Import the API endpoints
- curl - Command line testing
- Mobile App - Direct integration testing
Example login request:
curl -X POST http://https://devoverflow-backend.onrender.com/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "password123"}'This backend follows the Monolithic Architecture pattern, which is perfect for getting started:
- Single Codebase - All functionality in one application
- Shared Database - All models use the same MongoDB instance
- Unified API - Single entry point for all mobile app requests
- Easy Deployment - Simple deployment and scaling
The structure follows the MVC Pattern:
- Models (
/models) - Data schemas and database interactions - Controllers (
/controllers) - Business logic and request handling - Routes (
/routes) - API endpoint definitions and middleware - Middleware (
/middleware) - Authentication and validation
Key environment variables to configure:
# Database
MONGO_URI=mongodb://devoverflow-backend.onrender.com/mobile_app_db
# JWT
JWT_SECRET=your_super_secret_jwt_key
JWT_EXPIRE=30d
# Email
EMAIL_SERVICE=gmail
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password
# AI
GEMINI_API_KEY=your_gemini_api_key
# Server
PORT=3000
NODE_ENV=developmentThis backend can be deployed to:
- Heroku - Easy deployment with MongoDB Atlas
- AWS EC2 - Full control over the environment
- DigitalOcean - Simple cloud deployment
- Vercel - Serverless deployment option
The backend is fully documented with:
- Inline Comments - Detailed code documentation
- API Comments - Every endpoint documented
- Error Handling - Comprehensive error responses
- Examples - Real-world usage examples
This is a complete, production-ready backend. Key areas for potential enhancement:
- Real-time features (WebSocket integration)
- Caching layer (Redis)
- Email templates
- Push notifications
- Advanced AI features
This project is provided as educational material for mobile app development.
Built for Mobile App Development Course