Skip to content

Repository files navigation

Trippz - Travel Booking Platform API

Trippz Logo

Table of Contents

Overview

Trippz is a comprehensive travel booking platform API that enables users to search, book, and manage travel experiences including flights, hotels, and custom trips. The platform also supports service providers and travel agencies to offer their services to travelers.

Features

  • User Management: Registration, authentication, profile management
  • Destination Management: Comprehensive destination information with weather, attractions, and travel tips
  • Booking System: Book flights, hotels, and trips with flexible options
  • Payment Processing: Secure payment processing with multiple payment methods
  • Review System: User reviews and ratings for hotels, flights, and trips
  • Notification System: Real-time notifications for bookings, payments, and promotions
  • Service Provider Portal: For hotels, tour guides, and other service providers
  • Travel Agency Portal: For travel agencies to create and manage travel packages
  • Admin Dashboard: Comprehensive admin tools for platform management
  • Analytics: Detailed analytics and reporting for business insights
  • Maintenance Mode: System-wide maintenance mode for updates
  • Multi-language Support: API supports multiple languages
  • Geolocation Services: Find nearby destinations and attractions

Tech Stack

  • Backend: Node.js, Express.js
  • Database: PostgreSQL with Prisma ORM
  • Authentication: JWT, OAuth (Google, Facebook, Apple)
  • File Storage: Cloudinary
  • Email Service: Resend
  • SMS Service: Twilio
  • Payment Processing: Stripe
  • Documentation: Swagger/OpenAPI
  • Testing: Jest, Supertest
  • CI/CD: GitHub Actions
  • Deployment: Docker, Kubernetes, Vercel

Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • PostgreSQL (v13 or higher)
  • Git

Installation

  1. Clone the repository: ```bash git clone https://github.com/yourusername/trippz-api.git cd trippz-api ```

  2. Install dependencies: ```bash npm install

    or

    yarn install ```

  3. Set up environment variables (see Environment Variables section)

  4. Run database migrations: ```bash npx prisma migrate dev ```

  5. Seed the database (optional): ```bash npm run seed

    or

    yarn seed ```

  6. Start the development server: ```bash npm run dev

    or

    yarn dev ```

Environment Variables

Create a .env file in the root directory with the following variables:

```

Database

DATABASE_URL="postgresql://username:password@localhost:5432/trippz?schema=public"

Authentication

JWT_SECRET="your-jwt-secret" JWT_EXPIRES_IN="1d" JWT_REFRESH_SECRET="your-jwt-refresh-secret" JWT_REFRESH_EXPIRES_IN="7d" JWT_RESET_PASSWORD_SECRET="your-jwt-reset-password-secret" JWT_EMAIL_VERIFICATION_SECRET="your-jwt-email-verification-secret" JWT_PHONE_VERIFICATION_SECRET="your-jwt-phone-verification-secret" JWT_ACCESS_EXPIRES_IN="15m"

Email

RESEND_API_KEY="your-resend-api-key" RESEND_FROM_EMAIL="noreply@trippz.com"

SMS

TWILIO_ACCOUNT_SID="your-twilio-account-sid" TWILIO_AUTH_TOKEN="your-twilio-auth-token" TWILIO_PHONE_NUMBER="your-twilio-phone-number"

File Upload

CLOUDINARY_CLOUD_NAME="your-cloudinary-cloud-name" CLOUDINARY_API_KEY="your-cloudinary-api-key" CLOUDINARY_API_SECRET="your-cloudinary-api-secret"

Payment

STRIPE_SECRET_KEY="your-stripe-secret-key"

OAuth

GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret" FACEBOOK_APP_ID="your-facebook-app-id" FACEBOOK_APP_SECRET="your-facebook-app-secret" APPLE_CLIENT_ID="your-apple-client-id" APPLE_CLIENT_SECRET="your-apple-client-secret" APPLE_TEAM_ID="your-apple-team-id" APPLE_KEY_ID="your-apple-key-id"

Application

PORT=5000 NODE_ENV="development" API_URL="http://localhost:5000/api" FRONTEND_URL="http://localhost:5000" USE_COOKIE_AUTH="true" ```

Database Setup

The project uses Prisma ORM for database management. The database schema is defined in prisma/schema.prisma.

To set up the database:

  1. Make sure PostgreSQL is running and you have created a database for the project.
  2. Update the DATABASE_URL in your .env file.
  3. Run migrations to create the database schema: ```bash npx prisma migrate dev ```
  4. Generate Prisma client: ```bash npx prisma generate ```

API Documentation

The API is documented using Swagger/OpenAPI. You can access the documentation at /api-docs when the server is running.

Authentication Endpoints

MethodEndpointDescriptionAuth Required
POST/api/auth/registerRegister a new userNo
POST/api/auth/loginUser loginNo
POST/api/auth/forgot-passwordRequest password resetNo
POST/api/auth/reset-passwordReset passwordNo
POST/api/auth/verify-emailVerify emailNo
POST/api/auth/verify-phoneVerify phone numberYes
POST/api/auth/social-loginSocial loginNo
POST/api/auth/logoutLogoutYes
POST/api/auth/refresh-tokenRefresh access tokenNo
GET/api/auth/googleInitiate Google OAuth flowNo
GET/api/auth/google/callbackGoogle OAuth callbackNo
GET/api/auth/facebookInitiate Facebook OAuth flowNo
GET/api/auth/facebook/callbackFacebook OAuth callbackNo
GET/api/auth/appleInitiate Apple OAuth flowNo
POST/api/auth/apple/callbackApple OAuth callbackNo

User Endpoints

MethodEndpointDescriptionAuth Required
GET/api/users/profileGet user profileYes
PUT/api/users/profileUpdate user profileYes
PUT/api/users/passwordUpdate passwordYes
POST/api/users/profile-pictureUpload profile pictureYes
POST/api/users/addressesAdd addressYes
GET/api/users/addressesGet user addressesYes
DELETE/api/users/addresses/{id}Delete addressYes

Destination Endpoints

MethodEndpointDescriptionAuth Required
GET/api/destinationsGet all destinationsNo
POST/api/destinationsCreate a new destinationYes (Admin)
GET/api/destinations/trendingGet trending destinationsNo
GET/api/destinations/nearbyGet nearby destinationsNo
GET/api/destinations/{id}Get destination by IDNo
PUT/api/destinations/{id}Update destinationYes (Admin)
DELETE/api/destinations/{id}Delete destinationYes (Admin)
PUT/api/destinations/{id}/featured-imageSet featured imageYes (Admin)
GET/api/destinations/{id}/weatherGet weather informationNo
GET/api/destinations/{id}/attractionsGet attractionsNo

Hotel Endpoints

MethodEndpointDescriptionAuth Required
GET/api/hotelsGet all hotelsNo
POST/api/hotelsCreate a new hotelYes (Admin)
GET/api/hotels/{id}Get hotel by IDNo
PUT/api/hotels/{id}Update hotelYes (Admin)
DELETE/api/hotels/{id}Delete hotelYes (Admin)
GET/api/hotels/searchSearch hotelsNo

Flight Endpoints

MethodEndpointDescriptionAuth Required
GET/api/flightsGet all flightsNo
POST/api/flightsCreate a new flightYes (Admin)
GET/api/flights/{id}Get flight by IDNo
PUT/api/flights/{id}Update flightYes (Admin)
DELETE/api/flights/{id}Delete flightYes (Admin)
GET/api/flights/searchSearch flightsNo

Trip Endpoints

MethodEndpointDescriptionAuth Required
GET/api/tripsGet all tripsNo
POST/api/tripsCreate a new tripYes
GET/api/trips/{id}Get trip by IDNo
PUT/api/trips/{id}Update tripYes (Owner)
DELETE/api/trips/{id}Delete tripYes (Owner)
GET/api/trips/searchSearch tripsNo

Booking Endpoints

MethodEndpointDescriptionAuth Required
POST/api/bookingsCreate a new bookingYes
GET/api/bookingsGet user bookingsYes
GET/api/bookings/{id}Get booking by IDYes
PUT/api/bookings/{id}Update bookingYes (Owner)
POST/api/bookings/{id}/cancelCancel bookingYes (Owner)

Payment Endpoints

MethodEndpointDescriptionAuth Required
POST/api/paymentsProcess paymentYes
GET/api/paymentsGet user paymentsYes
GET/api/payments/{id}Get payment by IDYes (Owner)
POST/api/payments/{id}/refundRefund paymentYes (Owner/Admin)

Review Endpoints

MethodEndpointDescriptionAuth Required
POST/api/reviewsCreate a reviewYes
GET/api/reviewsGet user reviewsYes
GET/api/reviews/{id}Get review by IDNo
PUT/api/reviews/{id}Update reviewYes (Owner)
DELETE/api/reviews/{id}Delete reviewYes (Owner)
GET/api/reviews/hotels/{id}Get hotel reviewsNo
GET/api/reviews/flights/{id}Get flight reviewsNo
GET/api/reviews/trips/{id}Get trip reviewsNo

Notification Endpoints

MethodEndpointDescriptionAuth Required
GET/api/notificationsGet user notificationsYes
PUT/api/notifications/{id}/readMark notification as readYes
PUT/api/notifications/read-allMark all notifications as readYes
DELETE/api/notifications/{id}Delete notificationYes
GET/api/notifications/preferencesGet notification preferencesYes
PUT/api/notifications/preferencesUpdate notification preferencesYes
POST/api/notifications/bulkSend bulk notificationsYes (Admin)

Service Provider Endpoints

MethodEndpointDescriptionAuth Required
POST/api/service-providers/registerRegister as service providerYes
GET/api/service-providers/profileGet service provider profileYes (Provider)
PUT/api/service-providers/profileUpdate service provider profileYes (Provider)
POST/api/service-providers/servicesCreate a new serviceYes (Provider)
GET/api/service-providers/servicesGet all servicesYes (Provider)
GET/api/service-providers/services/{id}Get service by IDYes (Provider)
PUT/api/service-providers/services/{id}Update serviceYes (Provider)
DELETE/api/service-providers/services/{id}Delete serviceYes (Provider)
GET/api/service-providers/ordersGet all ordersYes (Provider)
POST/api/service-providers/respond/{orderId}Respond to orderYes (Provider)

Travel Agency Endpoints

MethodEndpointDescriptionAuth Required
POST/api/travel-agencies/registerRegister as travel agencyYes
GET/api/travel-agencies/profileGet travel agency profileYes (Agency)
PUT/api/travel-agencies/profileUpdate travel agency profileYes (Agency)
POST/api/travel-agencies/packagesCreate a new packageYes (Agency)
GET/api/travel-agencies/packagesGet all packagesYes (Agency)
GET/api/travel-agencies/packages/{id}Get package by IDYes (Agency)
PUT/api/travel-agencies/packages/{id}Update packageYes (Agency)
DELETE/api/travel-agencies/packages/{id}Delete packageYes (Agency)
GET/api/travel-agencies/ordersGet all ordersYes (Agency)
POST/api/travel-agencies/respond/{orderId}Respond to orderYes (Agency)

Admin Endpoints

MethodEndpointDescriptionAuth Required
GET/api/admin/usersGet all usersYes (Admin)
GET/api/admin/users/{id}Get user by IDYes (Admin)
DELETE/api/admin/users/{id}Delete userYes (Admin)
PUT/api/admin/users/{id}/roleUpdate user roleYes (Admin)
GET/api/admin/statsGet dashboard statisticsYes (Admin)
GET/api/admin/analyticsGet detailed analyticsYes (Admin)
GET/api/admin/settingsGet system settingsYes (Admin)
PUT/api/admin/settingsUpdate system settingsYes (Admin)
GET/api/admin/destinationsGet all destinationsYes (Admin)
POST/api/admin/destinationsCreate destinationYes (Admin)
PUT/api/admin/destinations/{id}Update destinationYes (Admin)
DELETE/api/admin/destinations/{id}Delete destinationYes (Admin)

System Endpoints

MethodEndpointDescriptionAuth Required
GET/api/healthHealth check endpointNo
GET/api/maintenance-statusGet maintenance statusNo

Authentication

The API uses JWT (JSON Web Tokens) for authentication. When a user logs in or registers, they receive an access token and a refresh token.

Access Token

  • Used for authenticating API requests
  • Short-lived (15 minutes by default)
  • Must be included in the Authorization header as a Bearer token

Refresh Token

  • Used to obtain a new access token when it expires
  • Longer-lived (7 days by default)
  • Can be stored securely in an HTTP-only cookie or in local storage

OAuth Authentication

The API supports OAuth authentication with:

  • Google
  • Facebook
  • Apple

Error Handling

The API uses a consistent error handling approach:

  • All errors return a JSON response with a success field set to false
  • The message field provides a human-readable error message
  • The errors field may contain detailed validation errors
  • HTTP status codes are used appropriately (400, 401, 403, 404, 500, etc.)

Example error response:

```json { "success": false, "message": "Validation error", "errors": [ { "path": "email", "message": "Email is required" }, { "path": "password", "message": "Password must be at least 8 characters" } ] } ```

Database Schema

The database schema is defined using Prisma ORM. The main entities are:

  • User
  • Destination
  • Hotel
  • Flight
  • Trip
  • Booking
  • Payment
  • Review
  • Notification
  • ServiceProvider
  • TravelAgency
  • SystemSetting

For detailed schema information, refer to the prisma/schema.prisma file.

Testing

The project uses Jest for testing. To run tests:

```bash

Run all tests

npm test

Run tests with coverage

npm run test:coverage

Run specific test file

npm test -- src/tests/auth.test.js ```

Deployment

Production Deployment

  1. Build the application: ```bash npm run build ```

  2. Start the production server: ```bash npm start ```

Docker Deployment

  1. Build the Docker image: ```bash docker build -t trippz-api . ```

  2. Run the Docker container: ```bash docker run -p 5000:5000 --env-file .env trippz-api ```

Kubernetes Deployment

Kubernetes deployment files are available in the k8s directory.

Maintenance Mode

The API supports a system-wide maintenance mode that can be enabled by administrators. When maintenance mode is active:

  1. All API endpoints except for /api/health and /api/maintenance-status return a 503 Service Unavailable response
  2. The maintenance message is customizable through the admin settings
  3. Specific IP addresses can be whitelisted to bypass maintenance mode

Security Measures

The API implements several security measures:

  • HTTPS for all communications
  • JWT for secure authentication
  • Password hashing using bcrypt
  • CSRF protection
  • Rate limiting to prevent brute force attacks
  • Input validation and sanitization
  • Secure HTTP headers
  • Database query parameterization to prevent SQL injection

Performance Optimization

  • Database indexing for frequently queried fields
  • Query optimization with Prisma
  • Response caching for frequently accessed data
  • Pagination for large data sets
  • Compression for API responses
  • Optimized file uploads and processing

CI/CD Pipeline

The project uses GitHub Actions for continuous integration and deployment:

  • Automated testing on pull requests
  • Code quality checks with ESLint and Prettier
  • Automated deployment to staging and production environments
  • Database migration automation

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature-name
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin feature/your-feature-name
  5. Open a pull request

Please make sure to update tests as appropriate and follow the code style guidelines.

License

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

Contact

For questions or support, please contact:

Releases

Packages

Contributors

Languages