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
Install dependencies
Install the required Node.js packages:The main dependencies include:
- express (v5.2.1) - Web application framework
- pg (v8.16.3) - PostgreSQL client for Node.js
Set up PostgreSQL database
Create a new PostgreSQL database for MayTravel:Configure your database connection in
PostgreSQL is used for its flexibility with dynamic schema changes. If the AI adds new fields to itinerary tables, the database won’t break.
/src/databases/postgres-db/maytraveldb.mjs:maytraveldb.mjs
Server Configuration
The MayTravel backend uses Express.js and is configured in/src/configs/server.mjs:
server.mjs
/src/app.mjs) sets up middleware and routing:
app.mjs
Making Your First API Call
Now that your server is running, let’s test the API endpoints.Authentication
- Register a new user
- Login
User Management
- Get all users
- Get user by ID
- Update user info
- Delete user
Interests
Manage user interests for personalized travel recommendations:- Get all interests
- Get user interests
- Add interests to user
- Create new interest
Trips
- Get all trips
- Get user trips
- Create a trip
- Get trip by ID
- Delete a trip
Points of Interest (POIs)
- Get all POIs
- Create a POI
- Update a POI
- Delete a POI
Stops
Create trip stops (itinerary items):Available API Routes
Here’s a complete reference of all available endpoints from/src/configs/routing.mjs:
| Method | Endpoint | Description |
|---|---|---|
| Authentication | ||
| POST | /auth/register | Register a new user |
| POST | /auth/login | Login and receive authentication token |
| Users | ||
| GET | /users | Get all users |
| GET | /users/:id | Get user by ID |
| POST | /users | Create a new user |
| PUT | /users/:id | Update user information |
| DELETE | /users/:id | Delete a user |
| GET | /users/:id/interests | Get user interests |
| POST | /users/:id/interests | Add interests to user |
| GET | /users/:id/trips | Get user trips |
| Interests | ||
| GET | /interests | Get all interests |
| POST | /interests | Create a new interest |
| PUT | /interests/:id | Update an interest |
| DELETE | /interests/:id | Delete an interest |
| Trips | ||
| GET | /trips | Get all trips |
| GET | /trips/:id | Get trip by ID |
| POST | /users/:id/trips | Create a trip for a user |
| DELETE | /trips/:id | Delete a trip |
| POIs (Points of Interest) | ||
| GET | /pois | Get all POIs |
| POST | /pois | Create a new POI |
| PATCH | /pois/:id | Update a POI |
| DELETE | /pois/:id | Delete a POI |
| Stops | ||
| POST | /stops | Create 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
Database connection failed
Database connection failed
Ensure PostgreSQL is running and the credentials in
maytraveldb.mjs match your database configuration:Port 3000 already in use
Port 3000 already in use
Change the port in
/src/configs/server.mjs:Module import errors
Module import errors
Ensure you’re using Node.js v16 or higher and that the project is configured as ES modules (check
"type": "module" in package.json).CORS errors from frontend
CORS errors from frontend
The backend has CORS configured in
/src/middlewares/cors.mjs. Update the origin if your frontend runs on a different port: