How rohitmaji18/travelexa works
Project Type and Purpose
• This is a full-stack, server-side rendered (SSR) travel booking platform (“Travelexa”) built with Node.js/Express, MongoDB/Mongoose, and Pug.
• Key features include user authentication (JWT), booking flows (Stripe), interactive maps (Leaflet), AI itinerary generation (Google Generative AI), email notifications (Nodemailer), and standard CRUD operations.
File Structure
• Top-level entries:
• app.js / server.js: Express application bootstrap and HTTP server.
• config/: security and CSP settings.
• controllers/: MVC controllers for tours, users, bookings, AI, views, errors, plus a generic factory.
• models/: Mongoose schemas for tours, users, reviews, bookings, itineraries.
• routes/: Express routers mapping URL paths to controller actions (/api/v1/... and view routes).
• utils/: shared helpers (error handling, async wrapper, email sender, API feature filtering).
• public/: static assets (CSS, JS bundles, images).
• views/: Pug templates for pages and email.
• dev-data/: seed/import scripts and JSON fixtures.
README for Technical Stack & Flows
• Frontend: Pug SSR + Parcel-bundled JS (Axios for AJAX, Leaflet for maps).
• Backend: Express MVC, middleware for security (Helmet, rate-limit, sanitizers), auth (JWT + bcryptjs), file upload (Multer + Sharp).
• Database: MongoDB with Mongoose.
• External Services: Stripe (checkout + webhooks), Google Generative AI, Email service via Nodemailer/SendGrid.
Main Components
• Browser/Client:
• SSR Pug pages + static assets (CSS/JS).
• AJAX calls (Axios) for map data and itinerary.
• Express Server Layer:
• View Engine (Pug) + viewController.
• API Gateway / Routers (/api/v1/users, /tours, /bookings, /ai).
• Controllers (business logic).
• Middleware stack (security, logging, error handling).
• Service/Utility Layer:
• AI Itinerary Service (calls Google Generative AI API).
• Payment Service (Stripe SDK + webhook handler).
• Email Service (Nodemailer + templates).
• File Processing (Multer → Sharp).
• Data Access Layer:
• Mongoose Models → MongoDB Atlas.
• External Integrations:
• Google Generative AI API
• Stripe API + Webhook endpoint
• Email Provider (SendGrid SMTP)
• Auxiliary:
• dev-data importer (one-off CLI script).
Relationships and Data Flows
• User → HTTP Request → Express Router → Controller → Service/Model → Response → Browser
• Booking flow: Client clicks “Book” → /bookings/checkout-session → Stripe → Redirect → Webhook → bookingController → MongoDB
• AI flow: Client → /ai/itinerary → aiController → Google AI → JSON itinerary → Browser
• Email flow: user signup/booking → email util → SendGrid → user inbox
• Static assets served from public/ via Express’s static middleware.
Architectural Patterns & Principles
• MVC: clear separation of routes, controllers (logic), models (data).
• Service-oriented calls: paymentService, aiService, emailService.
• Layered security middleware: rate limiting, sanitization, CSP, HPP, CORS.
• API versioning: /api/v1/…
• SSR for core pages; AJAX for dynamic features (maps, AI).