# krithik-m-codes/tripmate architecture

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

- Interactive diagram: https://gitdiagram.com/krithik-m-codes/tripmate
- Repository: https://github.com/krithik-m-codes/tripmate

## Overview

##### Project type and purpose
- TripMate is a full-stack web application built with Next.js (App Router), TypeScript, and MongoDB.
- It provides users with trip planning features: authentication, itinerary generation, saved places, maps, weather, and attractions via external APIs (Gemini, OpenWeather, MapBox, TripAdvisor, Pixabay).

##### File structure
- Top-level config and metadata: next.config.mjs, tsconfig.json, tailwind.config.ts, package.json, .eslintrc.json
- Public assets: public/assets/... (images, logos, SVGs)
- src/app: Next.js App Router pages, layouts, loading states, dynamic API route handlers under /src/app/api
- src/components: UI and website components broken into subfolders (ui primitives, website, skeleton) plus feature-specific cards and panels
- src/context: React context for AuthProvider
- src/hooks, src/lib: client and server utilities (dbConnect, external API wrappers, fetchers, utils)
- src/models & src/schemas: Mongoose models and Zod or Joi schemas for validation
- src/middleware.ts: global middleware
- src/types & src/utils: shared type definitions and helper functions

##### Extract architectural insights from the README
- NextAuth for authentication, using [...nextauth] route handlers under /src/app/api/auth
- REST-style API endpoints in Next.js route handlers under /src/app/api
- Mongoose connection logic in lib/dbConnect.ts
- External API calls abstracted in lib/weatherService.ts, fetchTravelData.ts, etc.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        Layout["Global Layout & Styling"]:::frontend
        AuthPages["Authentication Pages"]:::frontend
        DashboardPages["Dashboard & Feature Pages"]:::frontend
        AuthProvider["AuthProvider Context"]:::frontend
    end

    %% Server Layer
    subgraph "Next.js Server" 
        direction TB
        Middleware["Middleware (src/middleware.ts)"]:::server
        subgraph "API Routes" 
            direction TB
            NextAuthRoute["NextAuth Route Handler"]:::server
            ItineraryGen["Itinerary Generation API"]:::server
            ItineraryCRUD["User Itineraries CRUD"]:::server
            SavedPlacesCRUD["Saved Places CRUD"]:::server
            SearchHistoryCRUD["Search History CRUD"]:::server
            ProfileAPI["User Profile API"]:::server
            SignInAPI["Sign-In Endpoint"]:::server
            SignUpAPI["Sign-Up Endpoint"]:::server
            VerifyCodeAPI["Email Verification API"]:::server
            WeatherAPI["Weather Data API"]:::server
        end
        subgraph "Business Logic & Services"
            direction TB
            DBConnect["Database Connection (dbConnect)"]:::server
            FetchSuggestions["Trip Planning Suggestions"]:::server
            FetchTravelData["Travel Data Fetching"]:::server
            WeatherService["Weather Service"]:::server
        end
        subgraph "Models & Validation"
            direction TB
            Models["Mongoose Models"]:::server
            Schemas["Validation Schemas"]:::server
        end
    end

    %% Database
    subgraph "MongoDB Database" 
        direction TB
        DB["MongoDB"]:::database
    end

    %% External Services
    subgraph "External APIs" 
        direction TB
        Gemini["Gemini API"]:::external
        OpenWeather["OpenWeatherMap API"]:::external
        MapBox["MapBox API"]:::external
        TripAdvisor["TripAdvisor API"]:::external
        Pixabay["Pixabay API"]:::external
    end

    %% Connections
    AuthPages -->|"uses"| AuthProvider
    AuthProvider -->|"injects auth state"| Layout
    Layout -->|"renders"| AuthPages
    Layout -->|"renders"| DashboardPages

    AuthPages -->|"> Request"| Middleware
    DashboardPages -->|"> Request"| Middleware

    Middleware -->|"routes to"| NextAuthRoute
    Middleware -->|"routes to"| ItineraryGen
    Middleware -->|"routes to"| ItineraryCRUD
    Middleware -->|"routes to"| SavedPlacesCRUD
    Middleware -->|"routes to"| SearchHistoryCRUD
    Middleware -->|"routes to"| ProfileAPI
    Middleware -->|"routes to"| SignInAPI
    Middleware -->|"routes to"| SignUpAPI
    Middleware -->|"routes to"| VerifyCodeAPI
    Middleware -->|"routes to"| WeatherAPI

    NextAuthRoute -->|"reads/writes"| DBConnect
    ItineraryGen -->|"uses"| FetchSuggestions
    ItineraryGen -->|"uses"| DBConnect
    ItineraryCRUD -->|"uses"| DBConnect
    SavedPlacesCRUD -->|"uses"| DBConnect
    SearchHistoryCRUD -->|"uses"| DBConnect
    ProfileAPI -->|"uses"| DBConnect
    SignInAPI -->|"uses"| DBConnect
    SignUpAPI -->|"uses"| DBConnect
    VerifyCodeAPI -->|"uses"| DBConnect
    WeatherAPI -->|"uses"| WeatherService

    FetchSuggestions -->|"calls"| Gemini
    FetchTravelData -->|"calls"| TripAdvisor
    FetchTravelData -->|"calls"| Pixabay
    WeatherService -->|"calls"| OpenWeather
    WeatherService -->|"calls"| MapBox

    DBConnect -->|"connects to"| DB
    Models -->|"define collections"| DB
    Schemas -->|"validate data"| NextAuthRoute

    %% Click Events
    click Layout "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/layout.tsx"
    click AuthPages "https://github.com/krithik-m-codes/tripmate/tree/main/src/app"
    click DashboardPages "https://github.com/krithik-m-codes/tripmate/tree/main/src/app/(auth)"
    click AuthProvider "https://github.com/krithik-m-codes/tripmate/blob/main/src/context/AuthProvider.tsx"
    click Middleware "https://github.com/krithik-m-codes/tripmate/blob/main/src/middleware.ts"
    click NextAuthRoute "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click ItineraryGen "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/generate-trip-itinerary/route.ts"
    click ItineraryCRUD "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/itinerary/[userId]/route.ts"
    click SavedPlacesCRUD "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/saved-places/[userId]/route.ts"
    click SearchHistoryCRUD "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/search-history/[userId]/route.ts"
    click ProfileAPI "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/profile/route.ts"
    click SignInAPI "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/sign-in/route.ts"
    click SignUpAPI "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/sign-up/route.ts"
    click VerifyCodeAPI "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/verify-code/route.ts"
    click WeatherAPI "https://github.com/krithik-m-codes/tripmate/blob/main/src/app/api/weather-report/route.ts"
    click DBConnect "https://github.com/krithik-m-codes/tripmate/blob/main/src/lib/dbConnect.ts"
    click FetchSuggestions "https://github.com/krithik-m-codes/tripmate/blob/main/src/lib/fetchSuggestions.ts"
    click FetchTravelData "https://github.com/krithik-m-codes/tripmate/blob/main/src/lib/fetchTravelData.ts"
    click WeatherService "https://github.com/krithik-m-codes/tripmate/blob/main/src/lib/weatherService.ts"
    click Models "https://github.com/krithik-m-codes/tripmate/tree/main/src/models"
    click Schemas "https://github.com/krithik-m-codes/tripmate/tree/main/src/schemas"
    click DB "https://github.com/krithik-m-codes/tripmate/tree/main/MongoDB"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef server fill:#DFFFE0,stroke:#228B22,color:#228B22
    classDef database fill:#FFEFD5,stroke:#FF8C00,color:#FF8C00
    classDef external fill:#E8D0FF,stroke:#800080,color:#800080
```
