Skip to content

Sahilll94/Travel-Book-Backend

Repository files navigation

Travel Book Backend

Backend service for the Travel Book platform, enabling users to share travel stories, manage user accounts, and authenticate securely.

Overview

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.

Live Deployment

Infrastructure

The backend is deployed on:

  • Server: AWS EC2 instance
  • Reverse Proxy: Nginx
  • Process Manager: PM2
  • Database: MongoDB
  • Image Storage: Cloudinary

Tech Stack

  • 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

Project Structure

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

Prerequisites

  • 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)

Installation

Clone the Repository

git clone https://github.com/Sahilll94/Travel-Book-Backend-Repository.git
cd Travel-Book-Backend-Repository

Install Dependencies

npm install

Environment Setup

Create 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.

Running the Application

Development Mode

npm run dev

Starts the server with Nodemon for automatic reload on file changes.

Production Mode

npm start

API Documentation

For detailed information about available endpoints, request/response formats, and authentication requirements, please refer to the official API documentation.

Contributing

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.

Code of Conduct

We are committed to providing a welcoming and inclusive environment. Please review our Code of Conduct before contributing.

Getting Started as a Contributor

1. Fork and Clone

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

2. Set Up Development Environment

# 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 dev

3. Create a Feature Branch

git checkout -b feature/your-feature-name
# or for bug fixes:
git checkout -b bugfix/your-bug-fix

Development Guidelines

Code Standards

  • 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 .env for all sensitive data; never commit credentials

Testing Requirements

Before submitting your contribution, ensure you have tested:

  1. Authentication & Authorization:

    • JWT token generation and validation
    • Firebase Admin authentication
    • Protected routes work correctly
  2. API Endpoints:

    • All CRUD operations (Create, Read, Update, Delete)
    • Error handling and validation
    • Proper HTTP status codes
    • Request/response formats
  3. Database Operations:

    • MongoDB connections and queries
    • Data persistence and retrieval
    • Relationship handling between models
  4. File Uploads:

    • Image uploads to Cloudinary
    • File validation and error handling
    • Large file handling
  5. External Services:

    • Email notifications (Nodemailer)
    • AI chatbot service (Google Generative AI)
    • Firebase Admin operations

Code Quality Checklist

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

Adding New Features

For API Endpoints:

  1. Define the route in index.js
  2. Create models if needed in models/
  3. Add business logic in services/ or utility functions in utilities.js
  4. Handle all error cases
  5. Document the endpoint in comments
  6. Test thoroughly with different scenarios

For External Service Integration:

  1. Create a service file in services/ (e.g., services/myservice.service.js)
  2. Implement error handling and validation
  3. Test integration locally
  4. Document API keys/credentials needed in .env.example
  5. Add documentation to this README

For Database Models:

  1. Create model in models/ following existing patterns
  2. Add validation and constraints
  3. Document field types and required fields
  4. Handle relationships properly

Submitting Your Contribution

1. Before You Start

  • 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

2. While Working

  • 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

3. Creating a Pull Request

# Push your branch
git push origin feature/your-feature-name

Then 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

4. PR Template

## 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

Review Process

  1. Maintainers will review your PR
  2. They may request changes or clarifications
  3. Once approved, your PR will be merged
  4. Your contribution will be credited

Common Contribution Types

Bug Reports

Include:

  • Clear description of the bug
  • Steps to reproduce
  • Expected vs. actual behavior
  • Environment details (Node version, OS, etc.)
  • Error messages or logs

Feature Requests

Include:

  • Clear description of the feature
  • Why it's needed
  • Potential implementation approach
  • Use cases and benefits

Documentation Improvements

  • Fix typos or unclear explanations
  • Add missing information
  • Improve code examples
  • Update outdated content

Architecture Overview

Project Structure

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

Adding a New API Endpoint

  1. Define the route in index.js
  2. Implement the handler logic
  3. Use middleware for authentication if needed
  4. Return appropriate HTTP status codes
  5. 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 });
  }
});

Frontend & Backend Coordination

  • Separate Repositories: Frontend and Backend are separate repos
  • Contributors Clone Both: Contributors clone both repos separately
  • API Contract: Frontend uses http://localhost:5000 for local development
  • Shared Conventions: Keep API responses consistent with existing patterns

Getting Help

  • Questions: Open an issue with the question label
  • Documentation: Check the API Documentation
  • Chat: Join discussions in issues for help
  • Maintainers: Tag maintainers in issues if you need urgent help

Recognition

Contributors are recognized in the project! Your name and profile will be added to the contributors list once your PR is merged.

License

This project is licensed under the ISC License - see the LICENSE file for details.

Support

For issues, questions, or suggestions, please open an issue on the GitHub repository.

Contact

Email: contact@sahilfolio.live

About

This Repository is the Backend of the Travel-Book Application.

Topics

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published