# vedant-303/globeroute-ai-trip-planner architecture

> Architecture diagram of the GitHub repository vedant-303/globeroute-ai-trip-planner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vedant-303/globeroute-ai-trip-planner
- Repository: https://github.com/vedant-303/globeroute-ai-trip-planner

## Overview

##### Project Type and Purpose
- GlobeRoute is a full-stack web application for AI-powered trip planning.
- Frontend: React.js SPA that handles user authentication, trip creation UI, trip listing/details, and PDF export.
- Backend: Node.js + Express API that manages users, trips, session cookies/JWT, MongoDB persistence, and integrates with external AI (Gemini) and image (Unsplash) services.

##### File Structure
- Top-level split into `Backend/` and `Frontend/`.
- **Backend**
- `server.js` – Express app entry point.
- `config/database.js` – Mongoose connection setup.
- `models/` – Mongoose schemas: `user.js`, `trip.js`.
- `controllers/` – Business logic: `authController.js` (signup/login/logout), `tripCreationController.js` (create/view trips).
- `routes/` – Route definitions: `auth.js`, `tripCreation.js`.
- `middleware/authMiddleware.js` – JWT/cookie validation.
- `utils/gemini.js` – Wrapper for Gemini AI API.
- **Frontend**
- `index.html`, `main.jsx` – Entry point.
- `src/components/` – Reusable UI components (Navbar, Spinner, TripCard, forms, Hero, ExtraInfo, TripNav).
- `src/pages/` – Route‐level pages: Landing, Authentication, Profile, AIGenTrip.
- `src/utils/axios.js` – Axios instance configured for backend API.
- `src/utils/unsplash.js` – Unsplash API wrapper.
- `.env`, `vite.config.js` – Build/configuration.

##### Extract Key Insights from README
- Auth flow uses cookies + JWT.
- Trip planning includes AI-driven itinerary, weather, cost, safety, lodging, transport, local language, plus dynamic Unsplash images.
- PDF download powered by html2pdf.js.
- Tech stack calls out React, Node/Express, MongoDB, Gemini API, Unsplash API.

##### Main Components
a. **User’s Browser (Frontend SPA)**
- Pages & Components (Landing, Auth, AIGenTrip, Profile)
- Axios layer for HTTP calls
- html2pdf.js for PDF export
b. **Backend Service (Node.js + Express)**
- Authentication subsystem (routes → controllers → models)
- Trip subsystem (routes → controllers → Gemini utils → models)
- JWT/Cookie middleware
- Database connector
c. **Database**
- MongoDB cluster (Users collection, Trips collection)
d. **External Services**
- Gemini AI API (trip generation, itinerary)
- Unsplash API (destination images)

##### Relationships & Data Flows
1. Browser → (POST /signup, /login) → AuthController → User model → MongoDB → Set JWT Cookie
2. Browser → (POST /trips) → TripController → uses gemini.js (Gemini API) + unsplash.js (Unsplash API) → Compose trip → Trip model → MongoDB → Return trip data
3. Browser ← (GET /trips, /trips/:id) ← TripController ← Trip model ← MongoDB
4. Browser → html2pdf.js to render and download PDF
5. Browser renders dynamic images via direct Unsplash fetch or via backend proxy

##### Architectural Patterns & Design Principles
- **Layered Architecture**: Presentation (React), API (Express), Persistence (MongoDB).
- **MVC-like Separation** in backend: Routes → Controllers → Models.
- **Service/Utility Modules**: gemini.js, unsplash.js encapsulate external-API logic.
- **Stateless API** with JWT authentication.
- **Single-Page Application** on frontend with clearly separated components and pages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
        FE_Index["index.html"]:::frontend
        FE_Main["main.jsx"]:::frontend
        FE_App["App.jsx"]:::frontend

        subgraph "Pages"
            Landing["LandingPage.jsx"]:::frontend
            Authenticate["AuthenticatePage.jsx"]:::frontend
            TripPage["Trip.jsx"]:::frontend
            Profile["ProfilePage.jsx"]:::frontend
        end

        subgraph "Components"
            Navbar["Navbar.jsx"]:::frontend
            Spinner["Spinner.jsx"]:::frontend
            TripCard["TripCard.jsx"]:::frontend
            LoginForm["LoginForm.jsx"]:::frontend
            SignupForm["SignupForm.jsx"]:::frontend
            TripForm["TripForm.jsx"]:::frontend
            Hero["Hero.jsx"]:::frontend
            ExtraInfo["Extra.jsx"]:::frontend
            TripNav["TripNav.jsx"]:::frontend
            TripDetails["TripDetails.jsx"]:::frontend
        end

        subgraph "Utils"
            Axios["axios.js"]:::frontend
            UnsplashUtilFE["unsplash.js"]:::frontend
        end

        PDF["html2pdf.js"]:::frontend

        FE_Index --> FE_Main --> FE_App
        FE_App --> Landing
        FE_App --> Authenticate
        FE_App --> TripPage
        FE_App --> Profile

        Landing --> Navbar
        Landing --> Hero
        Authenticate --> LoginForm
        Authenticate --> SignupForm
        Authenticate --> Spinner
        Profile --> TripCard
        Profile --> Spinner
        TripPage --> TripForm
        TripPage --> TripNav
        TripPage --> TripDetails
        TripPage --> Spinner
        TripPage --> Navbar
        TripPage --> ExtraInfo

        TripPage --> PDF

        Landing --> Axios
        Authenticate --> Axios
        TripPage --> Axios
        Profile --> Axios

        TripPage --> UnsplashUtilFE
        UnsplashUtilFE -->|"Direct fetch"| UnsplashAPI

    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        classDef backend fill:#D0F5D8,stroke:#333,stroke-width:1px
        Server["server.js"]:::backend
        DBConfig["database.js"]:::backend
        AuthMiddleware["authMiddleware.js"]:::backend

        subgraph "Routes"
            AuthRoutes["auth.js"]:::backend
            TripRoutes["tripCreation.js"]:::backend
        end

        subgraph "Controllers"
            AuthController["authController.js"]:::backend
            TripController["tripCreationController.js"]:::backend
        end

        subgraph "Models"
            UserModel["user.js"]:::backend
            TripModel["trip.js"]:::backend
        end

        subgraph "Utils"
            GeminiUtil["gemini.js"]:::backend
        end

        Server --> DBConfig
        Server --> AuthMiddleware
        Server --> AuthRoutes
        Server --> TripRoutes

        AuthRoutes --> AuthController
        TripRoutes --> TripController

        AuthController --> UserModel
        TripController --> TripModel

        TripController --> GeminiUtil
        GeminiUtil -->|"API call"| GeminiAPI

        AuthController -->|"CRUD"| MongoDB
        TripController -->|"CRUD"| MongoDB
    end

    %% Database
    MongoDB[(MongoDB)]:::db

    %% External Services
    GeminiAPI["Gemini AI API"]:::external
    UnsplashAPI["Unsplash API"]:::external

    %% Connections
    Axios -->|"POST /signup, /login"| AuthRoutes
    Axios -->|"POST /trips, GET /trips"| TripRoutes

    UserModel --> MongoDB
    TripModel --> MongoDB

    %% Direct DB for config
    DBConfig --> MongoDB

    %% Styles
    classDef db fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:1px

    %% Click Events
    click FE_Index "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/index.html"
    click FE_Main "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/main.jsx"
    click FE_App "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/App.jsx"
    click Landing "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/pages/Landing/LandingPage.jsx"
    click Authenticate "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/pages/Authentication/AuthenticatePage.jsx"
    click TripPage "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/pages/AIGenTrip/Trip.jsx"
    click Profile "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/pages/Profile/ProfilePage.jsx"
    click Navbar "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/Navbar/Navbar.jsx"
    click Spinner "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/Spinner/Spinner.jsx"
    click TripCard "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/TripCard/TripCard.jsx"
    click LoginForm "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/LoginForm/LoginForm.jsx"
    click SignupForm "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/SignupForm/SignupForm.jsx"
    click TripForm "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/TripCreationForm/TripForm.jsx"
    click Hero "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/HeroSection/Hero.jsx"
    click ExtraInfo "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/ExtraInfo/Extra.jsx"
    click TripNav "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/TripNav/TripNav.jsx"
    click TripDetails "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/components/TripDetails.jsx/TripDetails.jsx"
    click Axios "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/utils/axios.js"
    click UnsplashUtilFE "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Frontend/src/utils/unsplash.js"
    click Server "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/server.js"
    click DBConfig "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/config/database.js"
    click AuthController "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/controllers/authController.js"
    click AuthMiddleware "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/middleware/authMiddleware.js"
    click AuthRoutes "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/routes/auth.js"
    click TripRoutes "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/routes/tripCreation.js"
    click UserModel "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/models/user.js"
    click TripModel "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/models/trip.js"
    click GeminiUtil "https://github.com/vedant-303/globeroute-ai-trip-planner/blob/main/Backend/utils/gemini.js"
```
