# vashu4832/wanderlust architecture

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

- Interactive diagram: https://gitdiagram.com/vashu4832/wanderlust
- Repository: https://github.com/vashu4832/wanderlust

## Overview

##### Project type and purpose
- Full-stack web application named “WanderLust” for browsing, adding, and booking vacation properties.
- Front-end: EJS templates, HTML/CSS/JS, Mapbox for maps, responsive design.
- Back-end: Node.js/Express REST API, Passport.js authentication (local, Google, GitHub), session management.
- Database: MongoDB Atlas for listings, users, reviews.
- External services: Cloudinary for image storage, Mapbox API, OAuth providers.

##### File structure
- Top-level files
– app.js: entry point that configures Express, middleware, routes
– cloudConfig.js: Cloudinary setup
– schema.js & init/: input validation schemas and one-time data seeding scripts
– middleware.js & utils/: custom error handling and async wrapper
- Directories
– controllers/: business logic for listings, reviews, users
– routes/: route definitions mapped to controllers
– models/: Mongoose models for Listing, Review, User
– views/: EJS templates organized by layouts, includes, listings, users, error
– public/: static assets (CSS, JS) including map.js for client-side Mapbox integration
- Configuration & deployment
– package.json/package-lock.json: dependencies
– cloudConfig.js & .env variables for API keys
– Render config implied in README

##### README for additional insights
- MVC architecture is explicitly used
- Technology stack and major features (search/filter, reviews, session and cookie management, Multer uploads)
- Deployment details: Render + MongoDB Atlas
- Third-party integrations: Mapbox API, Cloudinary, Passport OAuth strategies

##### Main components
- Client (Browser)
– EJS-rendered pages, static JS (search, map integration), CSS
- Web Server (Express)
– Middleware layer (session, flash, cookie parsing, error handler, validation)
– Routes → Controllers → Models
– Auth layer (Passport strategies + session store via Connect-Mongo)
– File upload handler (Multer)
- Database
– MongoDB Atlas (Listings, Users, Reviews collections)
– Session store in MongoDB
- External Services
– Cloudinary for image upload/storage
– Mapbox API for map tiles and geocoding
– OAuth Providers (Google, GitHub) for authentication
- Deployment Platform
– Render (hosting Express server)

##### Relationships and interactions
- Server → MongoDB (CRUD via Mongoose)
- Server → Cloudinary (upload/retrieve images)
- Server → Mapbox (geocoding, map tiles)
- Server ↔ OAuth Providers (token exchange, callback flows)
- Session store: Express Session ↔ MongoDB

##### Architectural patterns and design principles
- MVC separation: clear division between Models, Views, Controllers
- Layered middleware pipeline in Express
- RESTful API endpoints for listing and review operations
- Single responsibility in controllers and utils (wrapAsync, ExpressError)
- Modular EJS partials for reusable UI components
- Security: data validation via Joi (schema.js), sanitization, Passport sessions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser/UI)"
        Browser["Browser\n(EJS, HTML/CSS/JS)"]:::client
        Views["views/"]:::client
        CSS["public/css/"]:::client
        JS["public/js/"]:::client
    end

    %% Server Layer
    subgraph "Server (Express App)"
        App["app.js\n(Express.js)"]:::server
        Middleware["Middleware\n(session, flash, error, validation)"]:::server
        Routes["Routes\n(listing.js, reviews.js, user.js)"]:::server
        Controllers["Controllers\n(listing.js, reviews.js, user.js)"]:::server
        Models["Models\n(listing.js, review.js, user.js)"]:::server
        CloudinaryCfg["cloudConfig.js\n(Cloudinary)"]:::server
        Validation["schema.js\n(Joi)"]:::server
    end

    %% Data Seeding
    subgraph "Data Seeding (One-time)"
        InitScripts["init/\n(data.js, index.js)"]:::server
    end

    %% Database Layer
    subgraph "Database (MongoDB Atlas)"
        MongoDB["MongoDB Atlas\n(Listings, Users, Reviews)"]:::db
        Sessions["Session Store\n(Connect-Mongo)"]:::db
    end

    %% External Services
    subgraph "External Services"
        Cloudinary["Cloudinary"]:::external
        Mapbox["Mapbox API"]:::external
        OAuth["OAuth Providers\n(Google, GitHub)"]:::external
    end

    %% Connections
    Browser -->|"HTTP Request"| App
    App --> Middleware
    Middleware --> Routes
    Routes --> Controllers
    Controllers --> Models
    Models --> MongoDB
    App -->|"Store Sessions"| Sessions
    App --> Cloudinary
    App --> Mapbox
    App --> OAuth
    InitScripts --> MongoDB

    %% Click Events
    click Views "https://github.com/vashu4832/wanderlust/tree/main/views/"
    click CSS "https://github.com/vashu4832/wanderlust/tree/main/public/css/"
    click JS "https://github.com/vashu4832/wanderlust/tree/main/public/js/"
    click App "https://github.com/vashu4832/wanderlust/blob/main/app.js"
    click Middleware "https://github.com/vashu4832/wanderlust/blob/main/middleware.js"
    click Middleware "https://github.com/vashu4832/wanderlust/blob/main/utils/ExpressError.js"
    click Middleware "https://github.com/vashu4832/wanderlust/blob/main/utils/wrapAsync.js"
    click Routes "https://github.com/vashu4832/wanderlust/blob/main/routes/listing.js"
    click Routes "https://github.com/vashu4832/wanderlust/blob/main/routes/reviews.js"
    click Routes "https://github.com/vashu4832/wanderlust/blob/main/routes/user.js"
    click Controllers "https://github.com/vashu4832/wanderlust/blob/main/controllers/listing.js"
    click Controllers "https://github.com/vashu4832/wanderlust/blob/main/controllers/reviews.js"
    click Controllers "https://github.com/vashu4832/wanderlust/blob/main/controllers/user.js"
    click Models "https://github.com/vashu4832/wanderlust/blob/main/models/listing.js"
    click Models "https://github.com/vashu4832/wanderlust/blob/main/models/review.js"
    click Models "https://github.com/vashu4832/wanderlust/blob/main/models/user.js"
    click CloudinaryCfg "https://github.com/vashu4832/wanderlust/blob/main/cloudConfig.js"
    click Validation "https://github.com/vashu4832/wanderlust/blob/main/schema.js"
    click InitScripts "https://github.com/vashu4832/wanderlust/blob/main/init/data.js"

    %% Styles
    classDef client fill:#D6EAF8,stroke:#21618C,color:#1B4F72
    classDef server fill:#F9E79F,stroke:#B9770E,color:#7E5109
    classDef db fill:#ABEBC6,stroke:#239B56,color:#1D8348
    classDef external fill:#D7BDE2,stroke:#6C3483,color:#4A235A
```
