Skip to main content
MayTravel is an AI-powered travel planning assistant that uses Google Gemini and RAG to help users plan their trips.

Prerequisites

Before you begin, ensure you have the following installed:
  • Node.js (v16 or higher)
  • PostgreSQL (v12 or higher)
  • npm, yarn, or pnpm package manager

Installation

1

Clone the repository

Clone the MayTravel repository to your local machine:
git clone https://github.com/morenojf/MayTravel.git
cd MayTravel/backend
2

Install dependencies

Install the required Node.js packages:
npm install
The main dependencies include:
  • express (v5.2.1) - Web application framework
  • pg (v8.16.3) - PostgreSQL client for Node.js
3

Set up PostgreSQL database

Create a new PostgreSQL database for MayTravel:
CREATE DATABASE MayTravel;
PostgreSQL is used for its flexibility with dynamic schema changes. If the AI adds new fields to itinerary tables, the database won’t break.
Configure your database connection in /src/databases/postgres-db/maytraveldb.mjs:
maytraveldb.mjs
import { Client } from 'pg'

const pgdb = new Client({
  user: 'postgres',
  password: 'admin',
  host: 'localhost',
  port: 5432,
  database: 'MayTravel'
})

await pgdb.connect()
export const db = pgdb
Update the database credentials (user, password, host, port) to match your PostgreSQL configuration before running the server.
4

Start the server

Start the backend server:
node src/app.mjs
You should see the following output:
Example app listening on port 3000
The server is now running at http://localhost:3000

Server Configuration

The MayTravel backend uses Express.js and is configured in /src/configs/server.mjs:
server.mjs
import express from 'express'
export const app = express()
export const port = 3000
The main application file (/src/app.mjs) sets up middleware and routing:
app.mjs
import {app, port} from "./configs/server.mjs"
import express from 'express'
import { routing } from "./configs/routing.mjs"

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

app.use(express.json());
app.use('/', routing)

Making Your First API Call

Now that your server is running, let’s test the API endpoints.

Authentication

curl -X POST http://localhost:3000/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "traveler123",
    "email": "traveler@example.com",
    "password": "securepassword"
  }'
Response:
{
  "message": "User registered succesfully"
}

User Management

curl http://localhost:3000/users

Interests

Manage user interests for personalized travel recommendations:
curl http://localhost:3000/interests

Trips

curl http://localhost:3000/trips

Points of Interest (POIs)

curl http://localhost:3000/pois

Stops

Create trip stops (itinerary items):
curl -X POST http://localhost:3000/stops \
  -H "Content-Type: application/json" \
  -d '{
    "trip_id": 1,
    "poi_id": 1,
    "order": 1,
    "duration_minutes": 120
  }'

Available API Routes

Here’s a complete reference of all available endpoints from /src/configs/routing.mjs:
MethodEndpointDescription
Authentication
POST/auth/registerRegister a new user
POST/auth/loginLogin and receive authentication token
Users
GET/usersGet all users
GET/users/:idGet user by ID
POST/usersCreate a new user
PUT/users/:idUpdate user information
DELETE/users/:idDelete a user
GET/users/:id/interestsGet user interests
POST/users/:id/interestsAdd interests to user
GET/users/:id/tripsGet user trips
Interests
GET/interestsGet all interests
POST/interestsCreate a new interest
PUT/interests/:idUpdate an interest
DELETE/interests/:idDelete an interest
Trips
GET/tripsGet all trips
GET/trips/:idGet trip by ID
POST/users/:id/tripsCreate a trip for a user
DELETE/trips/:idDelete a trip
POIs (Points of Interest)
GET/poisGet all POIs
POST/poisCreate a new POI
PATCH/pois/:idUpdate a POI
DELETE/pois/:idDelete a POI
Stops
POST/stopsCreate a trip stop

Next Steps

API Reference

Explore detailed API documentation

Architecture

Understand the system architecture

Database Schema

Learn about the database structure

AI Integration

Discover how AI powers MayTravel

Troubleshooting

Ensure PostgreSQL is running and the credentials in maytraveldb.mjs match your database configuration:
# Check if PostgreSQL is running
pg_isready

# Or on Linux
sudo systemctl status postgresql
Change the port in /src/configs/server.mjs:
export const port = 3001 // or any available port
Ensure you’re using Node.js v16 or higher and that the project is configured as ES modules (check "type": "module" in package.json).
The backend has CORS configured in /src/middlewares/cors.mjs. Update the origin if your frontend runs on a different port:
app.use(cors({
  origin: 'http://localhost:3000', // Update this
  credentials: true,
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
  allowedHeaders: ['Content-Type', 'Authorization'],
}))

Build docs developers (and LLMs) love