# rohitmaji18/travelexa architecture

> Architecture diagram of the GitHub repository rohitmaji18/travelexa, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohitmaji18/travelexa
- Repository: https://github.com/rohitmaji18/travelexa

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    Browser["Browser/Client"]:::frontend
    PublicAssets["Static Assets\n(public/)"]:::frontend
    Views["Pug Templates\n(views/)"]:::frontend

    %% Server Core
    subgraph "Express Server" 
        direction TB

        subgraph "Middleware Layer"
            HelmetCSP["Helmet/CSP"]:::backend
            RateLimit["Rate Limiting"]:::backend
            HPP["HPP/CORS"]:::backend
            FileUpload["Multer + Sharp"]:::backend
        end

        subgraph "Routing Layer"
            ViewRoutes["viewRoutes.js"]:::backend
            AiRoutes["aiRoutes.js"]:::backend
            BookingRoutes["bookingRoutes.js"]:::backend
            TourRoutes["tourRoutes.js"]:::backend
            UserRoutes["userRoutes.js"]:::backend
            ReviewRoutes["reveiwRoutes.js"]:::backend
        end

        subgraph "Controller Layer"
            ViewsController["viewsController.js"]:::backend
            AIController["aiController.js"]:::backend
            BookingController["bookingController.js"]:::backend
            AuthController["authController.js"]:::backend
            UserController["userController.js"]:::backend
            TourController["tourController.js"]:::backend
            ReviewController["reviewController.js"]:::backend
            ErrorController["errorController.js"]:::backend
            HandlerFactory["handlerFactory.js"]:::backend
        end

        subgraph "Service & Utils Layer"
            APIFeatures["apiFeatures.js"]:::service
            AppError["appError.js"]:::service
            CatchAsync["catchAsync.js"]:::service
            EmailUtil["email.js"]:::service
            OptimizeStatic["optimizeStatic.js"]:::service
            AIService["Google AI Service"]:::service
            PaymentService["Stripe Service"]:::service
        end

        subgraph "Data Layer"
            TourModel["tourModel.js"]:::database
            UserModel["userModel.js"]:::database
            ReviewModel["reviewModel.js"]:::database
            BookingModel["bookingModel.js"]:::database
            ItineraryModel["itineraryModel.js"]:::database
        end
    end

    %% Database
    MongoDB["MongoDB Atlas"]:::database

    %% External Services
    GoogleAI["Google Generative AI API"]:::external
    StripeAPI["Stripe API"]:::external
    StripeWebhook["Stripe Webhook"]:::external
    EmailProvider["SendGrid SMTP"]:::external

    %% Dev Data
    DevData["dev-data/import-dev-data.js"]:::auxiliary

    %% Connections
    Browser -->|GET HTML/CSS/JS| PublicAssets
    Browser -->|SSR Pages| Views
    Browser -->|HTTP GET/POST| ViewRoutes
    Browser -->|POST /api/v1/ai| AiRoutes
    Browser -->|POST /api/v1/bookings| BookingRoutes
    Browser -->|GET/POST /api/v1/tours| TourRoutes
    Browser -->|GET/POST /api/v1/users| UserRoutes
    Browser -->|GET/POST /api/v1/reviews| ReviewRoutes

    PublicAssets -->|served by| HelmetCSP
    ViewRoutes -->|calls| ViewsController
    AiRoutes -->|calls| AIController
    BookingRoutes -->|calls| BookingController
    TourRoutes -->|calls| TourController
    UserRoutes -->|calls| UserController
    ReviewRoutes -->|calls| ReviewController

    BookingController -->|uses| PaymentService
    BookingController -->|writes| BookingModel
    BookingController -->|handles webhook| StripeWebhook

    AIController -->|calls| GoogleAI
    AIController -->|writes| ItineraryModel

    AuthController -->|uses| AppError
    UserController -->|uses| APIFeatures
    TourController -->|uses| FileUpload
    TourController -->|writes| TourModel
    ReviewController -->|writes| ReviewModel

    EmailUtil -->|SMTP| EmailProvider
    BookingController -->|sends email| EmailUtil
    AuthController -->|sends email| EmailUtil

    ViewsController -->|reads| TourModel
    ViewsController -->|reads| UserModel
    ViewsController -->|reads| ReviewModel

    *--> ErrorController

    TourModel --> MongoDB
    UserModel --> MongoDB
    ReviewModel --> MongoDB
    BookingModel --> MongoDB
    ItineraryModel --> MongoDB

    StripeAPI -->|REST| PaymentService

    DevData -->|imports to| MongoDB

    %% Click Events
    click HelmetCSP "https://github.com/rohitmaji18/travelexa/blob/main/config/helmet-csp.js"
    click ViewsController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/viewsController.js"
    click AIController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/aiController.js"
    click BookingController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/bookingController.js"
    click AuthController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/authController.js"
    click UserController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/userController.js"
    click TourController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/tourController.js"
    click ReviewController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/reviewController.js"
    click ErrorController "https://github.com/rohitmaji18/travelexa/blob/main/controllers/errorController.js"
    click HandlerFactory "https://github.com/rohitmaji18/travelexa/blob/main/controllers/handlerFactory.js"
    click AiRoutes "https://github.com/rohitmaji18/travelexa/blob/main/routes/aiRoutes.js"
    click BookingRoutes "https://github.com/rohitmaji18/travelexa/blob/main/routes/bookingRoutes.js"
    click TourRoutes "https://github.com/rohitmaji18/travelexa/blob/main/routes/tourRoutes.js"
    click UserRoutes "https://github.com/rohitmaji18/travelexa/blob/main/routes/userRoutes.js"
    click ReviewRoutes "https://github.com/rohitmaji18/travelexa/blob/main/routes/reveiwRoutes.js"
    click ViewRoutes "https://github.com/rohitmaji18/travelexa/blob/main/routes/viewRoutes.js"
    click TourModel "https://github.com/rohitmaji18/travelexa/blob/main/models/tourModel.js"
    click UserModel "https://github.com/rohitmaji18/travelexa/blob/main/models/userModel.js"
    click ReviewModel "https://github.com/rohitmaji18/travelexa/blob/main/models/reviewModel.js"
    click BookingModel "https://github.com/rohitmaji18/travelexa/blob/main/models/bookingModel.js"
    click ItineraryModel "https://github.com/rohitmaji18/travelexa/blob/main/models/itineraryModel.js"
    click APIFeatures "https://github.com/rohitmaji18/travelexa/blob/main/utils/apiFeatures.js"
    click AppError "https://github.com/rohitmaji18/travelexa/blob/main/utils/appError.js"
    click CatchAsync "https://github.com/rohitmaji18/travelexa/blob/main/utils/catchAsync.js"
    click EmailUtil "https://github.com/rohitmaji18/travelexa/blob/main/utils/email.js"
    click OptimizeStatic "https://github.com/rohitmaji18/travelexa/blob/main/utils/optimizeStatic.js"
    click PublicAssets "https://github.com/rohitmaji18/travelexa/tree/main/public/"
    click Views "https://github.com/rohitmaji18/travelexa/tree/main/views/"
    click DevData "https://github.com/rohitmaji18/travelexa/blob/main/dev-data/data/import-dev-data.js"

    %% Styles
    classDef frontend fill:#D0E8F2,stroke:#0B6E99,color:#0B6E99
    classDef backend fill:#E3F2CD,stroke:#558B2F,color:#558B2F
    classDef service fill:#FFF4C1,stroke:#FBC02D,color:#F57F17
    classDef database fill:#FFE0B2,stroke:#FB8C00,color:#E65100
    classDef external fill:#F3E5F5,stroke:#8E24AA,color:#6A1B9A
    classDef auxiliary fill:#ECEFF1,stroke:#607D8B,color:#455A64
```
