Backend service for the Travel Book platform, enabling users to share travel stories, manage user accounts, and authenticate securely.
This Node.js/Express backend provides RESTful API endpoints for the Travel Book application. The service includes user authentication, travel story management, image uploads, email notifications, and AI-powered chatbot functionality.
- API Base URL: https://api.travelbook.sahilfolio.live
- Frontend Application: https://travelbook.sahilfolio.live
- API Documentation: Travel Book API Documentation
- Frontend Application GitHub Repository: Travel-Book frontend GitHub Repository
The backend is deployed on:
- Server: AWS EC2 instance
- Reverse Proxy: Nginx
- Process Manager: PM2
- Database: MongoDB
- Image Storage: Cloudinary
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens), Firebase Admin SDK
- Password Security: Bcrypt
- File Upload: Multer
- Email Service: Nodemailer
- AI Integration: Google Generative AI
- Image Management: Cloudinary
- Development: Nodemon
Backend/
├── models/ # Database schemas
│ ├── user.model.js
│ ├── travelStory.model.js
│ └── contributor.model.js
├── services/ # Business logic and external integrations
│ └── chatbot.service.js
├── webhook/ # Webhook handlers
│ └── webhook.js
├── index.js # Application entry point
├── multer.js # File upload configuration
├── utilities.js # Helper functions and utilities
├── firebase-admin.js # Firebase configuration
├── sendLoginNotification.js # Email notification service
└── package.json # Dependencies and scripts
- Node.js (v14 or higher)
- npm or yarn
- MongoDB instance or MongoDB Atlas account
- Firebase Admin credentials
- Cloudinary account (for image uploads)
- Nodemailer configuration (Gmail or other SMTP service)
git clone https://github.com/Sahilll94/Travel-Book-Backend-Repository.git
cd Travel-Book-Backend-Repositorynpm installCreate a .env file in the root directory with the following variables:
# Email Config to send the emails to logged in user.
ACCESS_TOKEN_SECRET = ADD_YOUR_ACCESS_TOKEN_SECRET
EMAIL_USER = ADD_YOUR_EMAIL_USER
EMAIL_PASSWORD = ADD_YOUR_EMAIL_PASSWORD
# Gemini APY for chatbot
GEMINI_API_KEY = ADD_YOUR_GEMINI_API_KEY
# CORS Configuration
CORS_ORIGINS = http://localhost:5173
# Frontend URLs
FRONTEND_URL = https://travelbook.sahilfolio.live
FRONTEND_URL_DEV = http://localhost:5173
# Placeholder Images
PLACEHOLDER_IMAGE_URL = https://github.com/Sahilll94/Travel-Book-Backend/blob/master/logo.png?raw=true
LOGO_IMAGE_URL = https://raw.githubusercontent.com/Sahilll94/Travel-Book/main/src/assets/images/logo.png
Copy the example config and create config.json in the project root from config.json.example, then replace the placeholders with your own credentials:
pc config.json.example config.json
Important: Do NOT commit config.json — it contains sensitive credentials. Add config.json to your local .gitignore if it is not already ignored.
npm run devStarts the server with Nodemon for automatic reload on file changes.
npm startFor detailed information about available endpoints, request/response formats, and authentication requirements, please refer to the official API documentation.
We welcome contributions to Travel Book Backend! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated. Please read this guide before contributing.
We are committed to providing a welcoming and inclusive environment. Please review our Code of Conduct before contributing.
Fork the Travel Book Backend repository to your GitHub account, then clone it:
git clone https://github.com/YOUR_GITHUB_ID/Travel-Book-Backend.git
cd Travel-Book-Backend# Install dependencies
npm install
# Copy the environment file
cp .env.example .env
# Copy the config example (create config.json from the example and fill credentials)
cp config.json.example config.json
# Update .env with your configuration:
# - MongoDB connection string (local or MongoDB Atlas)
# - Firebase Admin credentials
# - Cloudinary API keys
# - Email service credentials (Nodemailer)
# - Google Generative AI API key
# - JWT secret
# - Port (default: 5000)
# Start development server
npm run devgit checkout -b feature/your-feature-name
# or for bug fixes:
git checkout -b bugfix/your-bug-fix- File Organization: Follow the existing directory structure
- Naming Conventions: Use descriptive names for files and variables (camelCase for JS)
- Comments: Add comments for complex logic or non-obvious implementations
- Error Handling: Always handle errors gracefully and provide meaningful error messages
- Environment Variables: Use
.envfor all sensitive data; never commit credentials
Before submitting your contribution, ensure you have tested:
-
Authentication & Authorization:
- JWT token generation and validation
- Firebase Admin authentication
- Protected routes work correctly
-
API Endpoints:
- All CRUD operations (Create, Read, Update, Delete)
- Error handling and validation
- Proper HTTP status codes
- Request/response formats
-
Database Operations:
- MongoDB connections and queries
- Data persistence and retrieval
- Relationship handling between models
-
File Uploads:
- Image uploads to Cloudinary
- File validation and error handling
- Large file handling
-
External Services:
- Email notifications (Nodemailer)
- AI chatbot service (Google Generative AI)
- Firebase Admin operations
Before submitting a PR, verify:
- Code follows the existing style and conventions
- All tests pass locally
- No console errors or warnings
- Environment variables are properly documented
- API endpoints are properly documented
- Error handling is implemented
- No sensitive data is committed
For API Endpoints:
- Define the route in
index.js - Create models if needed in
models/ - Add business logic in
services/or utility functions inutilities.js - Handle all error cases
- Document the endpoint in comments
- Test thoroughly with different scenarios
For External Service Integration:
- Create a service file in
services/(e.g.,services/myservice.service.js) - Implement error handling and validation
- Test integration locally
- Document API keys/credentials needed in
.env.example - Add documentation to this README
For Database Models:
- Create model in
models/following existing patterns - Add validation and constraints
- Document field types and required fields
- Handle relationships properly
- Check if an issue already exists for what you want to work on
- If not, create an issue first to discuss the feature/fix
- Assign yourself to the issue once approved
- Keep commits atomic and descriptive
- Reference the issue number in your commits:
git commit -m "Fix: #123 - description" - Keep your branch updated with the main branch
# Push your branch
git push origin feature/your-feature-nameThen open a PR with:
- Title: Clear, concise description of the change
- Description: Explain what you changed and why
- Related Issues: Link to related issues (#123)
- Testing: Describe how you tested the changes
- Checklist: Ensure all requirements are met
## Description
Brief description of what this PR does.
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Documentation update
- [ ] Performance improvement
## Related Issues
Closes #(issue number)
## Testing
Describe the testing you did.
## Environment Variables Added/Modified
List any new environment variables required.
## Checklist
- [ ] My code follows the code style of this project
- [ ] I have tested my changes locally
- [ ] I have added appropriate comments
- [ ] I have updated documentation if needed
- [ ] No new warnings are generated
- Maintainers will review your PR
- They may request changes or clarifications
- Once approved, your PR will be merged
- Your contribution will be credited
Include:
- Clear description of the bug
- Steps to reproduce
- Expected vs. actual behavior
- Environment details (Node version, OS, etc.)
- Error messages or logs
Include:
- Clear description of the feature
- Why it's needed
- Potential implementation approach
- Use cases and benefits
- Fix typos or unclear explanations
- Add missing information
- Improve code examples
- Update outdated content
Backend/
├── models/ # Database schemas
│ ├── user.model.js
│ ├── travelStory.model.js
│ └── contributor.model.js
├── services/ # Business logic and integrations
│ └── chatbot.service.js
├── webhook/ # Webhook handlers
│ └── webhook.js
├── index.js # Server entry point
├── multer.js # File upload config
├── utilities.js # Helper functions
├── firebase-admin.js # Firebase setup
└── sendLoginNotification.js
- Define the route in
index.js - Implement the handler logic
- Use middleware for authentication if needed
- Return appropriate HTTP status codes
- Document with comments
Example:
// In index.js
app.post('/api/stories', authenticateToken, async (req, res) => {
try {
// Validate input
// Process request
// Return response
res.status(201).json({ success: true, data: result });
} catch (error) {
res.status(500).json({ success: false, message: error.message });
}
});- Separate Repositories: Frontend and Backend are separate repos
- Contributors Clone Both: Contributors clone both repos separately
- API Contract: Frontend uses
http://localhost:5000for local development - Shared Conventions: Keep API responses consistent with existing patterns
- Questions: Open an issue with the
questionlabel - Documentation: Check the API Documentation
- Chat: Join discussions in issues for help
- Maintainers: Tag maintainers in issues if you need urgent help
Contributors are recognized in the project! Your name and profile will be added to the contributors list once your PR is merged.
This project is licensed under the ISC License - see the LICENSE file for details.
For issues, questions, or suggestions, please open an issue on the GitHub repository.
Email: contact@sahilfolio.live