# krishsavaliya/wanderlust-airbnb-clone- architecture

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

- Interactive diagram: https://gitdiagram.com/krishsavaliya/wanderlust-airbnb-clone-
- Repository: https://github.com/krishsavaliya/wanderlust-airbnb-clone-

## Overview

##### Project type and purpose
- This is a full-stack web application ("Wanderlust") inspired by Airbnb.
- It implements user authentication, listing CRUD, image uploads, map integration, geocoding, and reviews.

##### File structure
- Top-level files:
- app.js (Express server entry point)
- Schema.js, cloudConfig.js (DB schema and cloudinary setup)
- init/ (database seeding scripts)
- package.json (dependencies and scripts)
- Directories:
- controllers/ – Express controller logic for listings, reviews, users
- routes/ – Route definitions binding URLs to controllers
- models/ – Mongoose schemas for Listing, Review, User
- views/ – EJS templates (layouts, partials, pages)
- public/ – Static assets (CSS, JS, images)
- utiles/ – Custom middleware and error helpers
- middleware.js – global Express middleware (validation, auth checks)

##### README for additional insights
- Technology stack: Node, Express, MongoDB, Mongoose, Passport.js, Cloudinary, Multer, Joi, express-session, connect-flash, EJS, Bootstrap, MapLibre GL JS, Geoapify
- Features: authentication, file upload, mapping, geocoding, responsive UI

##### Main components and their relationships
a. Client/browser UI
- Static assets (CSS/JS/images) served from public/
- EJS templates rendered server-side
- Interactive map widget calling MapLibre + Geoapify APIs
b. Web server (Express)
- Entry point: app.js
- Middleware chain: session, flash, body-parser, cloudinary config, custom middleware.js
- Routes layer: routes/*.js delegates to controller functions
- Controllers: business logic for listings, reviews, users
- File upload handling: Multer + Cloudinary SDK
- Form validation: Joi schemas in middleware
- Authentication: Passport-local strategy, express-session, connect-flash
c. Data layer
- Models (Mongoose schemas) for Users, Listings, Reviews
- MongoDB (hosted or local)
- init scripts to seed initial data
d. External services
- Cloudinary API for image storage
- Geoapify API for geocoding
- (Implicit) MapLibre GL JS for client-side map rendering

##### Architectural patterns and principles
- MVC: Views (EJS) ←→ Controllers ←→ Models (Mongoose)
- Layered architecture:
- Presentation layer (EJS + public JS/CSS)
- Application layer (Express routes/controllers)
- Domain/data layer (Mongoose + MongoDB)
- Separation of concerns: routing, business logic, data access, validation, error handling
- External abstraction: middleware for auth, file uploads, error wrapping (wrapAsync)

##### Relationships and data flows
- From Client → Express (HTTP requests for pages, API calls)
- Express → Middleware → Controllers → MongoDB (CRUD)
- Controllers → Cloudinary API (upload images)
- Controllers → Geoapify API (get coordinates)
- MongoDB → Controllers → EJS views → Client (rendered HTML)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client/Browser"
        direction TB
        EJS["EJS Templates"]:::client
        CSS["CSS"]:::client
        JS1["script.js"]:::client
        JS2["map.js"]:::client
        Images["Images"]:::client
        MapWidget["Map Widget"]:::client
    end

    %% Express Server
    subgraph "Express Server"
        direction TB
        AppEntry["app.js"]:::internal
        subgraph "Middleware Layer"
            direction TB
            Session["express-session & Passport"]:::internal
            Validation["Validation (Joi)"]:::internal
        end
        subgraph "Routes Layer"
            direction TB
            ListingRoutes["Listing Routes"]:::internal
            ReviewRoutes["Review Routes"]:::internal
            UserRoutes["User Routes"]:::internal
        end
        subgraph "Controllers"
            direction TB
            ListingCtrl["Listing Controller"]:::internal
            ReviewCtrl["Review Controller"]:::internal
            UserCtrl["User Controller"]:::internal
        end
        subgraph "File Upload Flow"
            direction TB
            Multer["Multer"]:::internal
            CloudUpload["Cloudinary SDK"]:::internal
        end
        subgraph "Utilities"
            direction TB
            ExpressError["ExpressError"]:::internal
            WrapAsync["wrapAsync"]:::internal
        end
    end

    %% Database Layer
    subgraph "MongoDB Database"
        direction TB
        DB["MongoDB"]:::internal
        subgraph Collections
            direction TB
            ListingModel["Listing Model"]:::internal
            ReviewModel["Review Model"]:::internal
            UserModel["User Model"]:::internal
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CloudinaryAPI["Cloudinary API"]:::external
        GeoapifyAPI["Geoapify API"]:::external
        MapLibre["MapLibre GL JS CDN"]:::external
    end

    %% Init Scripts
    Init["Data Seeding Scripts"]:::internal

    %% Connections
    EJS -->|renders from| AppEntry
    CSS -->|served by| AppEntry
    JS1 -->|served by| AppEntry
    JS2 -->|served by| AppEntry
    Images -->|served by| AppEntry
    MapWidget -->|calls| GeoapifyAPI
    MapWidget -->|renders via| MapLibre

    AppEntry --> Session
    Session --> Validation
    Validation --> ListingRoutes
    ListingRoutes --> ListingCtrl
    ReviewRoutes --> ReviewCtrl
    UserRoutes --> UserCtrl

    AppEntry --> ListingRoutes
    AppEntry --> ReviewRoutes
    AppEntry --> UserRoutes

    ListingCtrl -->|CRUD| DB
    ReviewCtrl -->|CRUD| DB
    UserCtrl -->|CRUD| DB

    ListingCtrl --> Multer
    Multer --> CloudUpload
    CloudUpload --> CloudinaryAPI

    ListingCtrl --> GeoapifyAPI

    ListingCtrl --> EJS
    ReviewCtrl --> EJS
    UserCtrl --> EJS

    DB --> ListingModel
    DB --> ReviewModel
    DB --> UserModel

    Init --> DB

    %% Click Events
    click AppEntry "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/app.js"
    click ExpressError "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/utiles/ExpressError.js"
    click WrapAsync "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/utiles/wrapAsync.js"
    click ListingCtrl "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/controllers/listing.js"
    click ReviewCtrl "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/controllers/review.js"
    click UserCtrl "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/controllers/user.js"
    click ListingRoutes "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/routes/listing.js"
    click ReviewRoutes "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/routes/review.js"
    click UserRoutes "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/routes/user.js"
    click ListingModel "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/models/listing.js"
    click ReviewModel "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/models/reviews.js"
    click UserModel "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/models/user.js"
    click CSS "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/public/css/style.css"
    click JS1 "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/public/js/script.js"
    click JS2 "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/public/js/map.js"
    click Init "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/init/index.js"
    click CloudUpload "https://github.com/krishsavaliya/wanderlust-airbnb-clone-/blob/main/cloudConfig.js"

    %% Styles
    classDef client fill:#b2f2bb,stroke:#2f9e44,color:#074214
    classDef internal fill:#74c0fc,stroke:#228be6,color:#1c7ed6
    classDef external fill:#ffd8a8,stroke:#fd7e14,color:#c2410c
```
