# anshuvrit/wanderlust architecture

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

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

## Overview

1. **Overall shape**
   - This is a server-rendered **Node.js + Express + MongoDB** application organized around a clear **MVC-style split**: routes receive requests, controllers implement behavior, Mongoose models persist data, and EJS templates render pages.

2. **Application bootstrap**
   - `app.js` is the main entry point. It is the place where the Express app is assembled: route mounting, view engine setup, static asset serving from `public/`, and application-wide middleware/error handling are likely wired here.
   - `cloudConfig.js` is a separate integration point for cloud image storage, indicating that upload/storage configuration is isolated from business logic.

3. **Domain model**
   - The data layer centers on three core entities in `models/`: **User**, **Listing**, and **Review**.
   - That suggests the main business object is a property listing, with users owning listings and posting reviews against them.

4. **Request flow**
   - Incoming requests are split by resource in `routes/`:
     - `routes/listing.js`
     - `routes/review.js`
     - `routes/user.js`
   - These route modules delegate to matching controllers in `controllers/`, which keeps HTTP wiring separate from domain logic.

5. **Listings subsystem**
   - `controllers/listings.js` and `routes/listing.js` handle the primary marketplace flow: browsing listings, creating new ones, editing them, and viewing details.
   - The corresponding EJS views in `views/listings/` (`index`, `show`, `new`, `edit`) confirm the key pages for CRUD-style listing management.

6. **Reviews subsystem**
   - `controllers/reviews.js` and `routes/review.js` isolate review creation and deletion from listing management.
   - Reviews are likely nested under listings in the user experience, with the `Review` model linking feedback to both a listing and a user.

7. **User/auth subsystem**
   - `controllers/user.js` and `routes/user.js` handle signup/login and user-facing account flows.
   - The presence of `views/users/login.ejs` and `views/users/signup.ejs` shows that authentication is rendered through server-side pages rather than a separate SPA client.

8. **Validation and middleware boundary**
   - `middleware.js` and `schema.js` are the main guardrails around request handling.
   - This is where authentication/authorization checks and input validation likely live, creating a boundary between untrusted request data and the controllers/models.
   - `utills/ExpressError.js` and `utills/wrapAsync.js` provide centralized error handling and async controller wrapping.

9. **Database and persistence**
   - `models/` plus the `init/` directory indicate a MongoDB/Mongoose persistence layer with optional seed data.
   - `init/data.js` and `init/index.js` are likely used to initialize or reseed listing data during development.
   - The README indicates **MongoDB Atlas** as the backing database, so persistence is externalized from the app process.

10. **Presentation layer**
    - EJS is the templating system, with shared layout fragments in `views/includes/` and `views/layouts/`.
    - `views/includes/navbar.ejs`, `footer.ejs`, and `flash.ejs` show reusable UI chrome and message display.
    - `public/css/` contains the styling layer, separating presentation assets from server logic.

11. **External services**
    - The README mentions **Cloudinary** for image storage, which is consistent with `cloudConfig.js` and a listing-focused app that needs upload/delivery support.
    - The app is therefore not just a CRUD site; it has an external media storage dependency that affects how listings are created and displayed.

12. **Architectural summary for a diagram**
    - A good diagram would show:
      - Browser/request client at the top
      - Express app as the central orchestrator
      - Route modules branching into listing/review/user controllers
      - Controllers calling Mongoose models
      - Models persisting to MongoDB Atlas
      - Listing creation/update also touching Cloudinary for images
      - EJS views and shared partials rendering the response
      - Middleware/validation/error utilities as cross-cutting layers around the request path

Main entry points: [`app.js`](https://github.com/anshuvrit/wanderlust/blob/main/app.js) (Express app), [`controllers/listings.js`](https://github.com/anshuvrit/wanderlust/blob/main/controllers/listings.js) (Listing ctrl), [`controllers/reviews.js`](https://github.com/anshuvrit/wanderlust/blob/main/controllers/reviews.js) (Review ctrl), [`controllers/user.js`](https://github.com/anshuvrit/wanderlust/blob/main/controllers/user.js) (User ctrl)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Request entry"]
  node_client(("Browser<br/>client"))
  node_app["Express app<br/>bootstrap<br/>[app.js]"]
  node_listing_route["Listing routes<br/>route module<br/>[listing.js]"]
  node_review_route["Review routes<br/>route module<br/>[review.js]"]
  node_user_route["User routes<br/>route module<br/>[user.js]"]
end

subgraph group_domain["Domain and data"]
  node_listing_ctrl["Listing ctrl<br/>controller<br/>[listings.js]"]
  node_review_ctrl["Review ctrl<br/>controller<br/>[reviews.js]"]
  node_user_ctrl["User ctrl<br/>controller<br/>[user.js]"]
  node_listing_model[("Listing<br/>mongoose model<br/>[listing.js]")]
  node_review_model[("Review<br/>mongoose model<br/>[review.js]")]
  node_user_model[("User<br/>mongoose model<br/>[user.js]")]
  node_mongo[("MongoDB Atlas<br/>database")]
end

subgraph group_ui["Presentation"]
  node_views["EJS views<br/>template layer"]
  node_partials["Shared partials<br/>view partials"]
  node_styles["Stylesheets<br/>assets"]
end

subgraph group_support["Support services"]
  node_cloud{{"Cloudinary<br/>media service<br/>[cloudConfig.js]"}}
  node_middleware["Middleware<br/>request guards<br/>[middleware.js]"]
  node_schema["Validation schema<br/>input validation<br/>[schema.js]"]
  node_errors["Error utils<br/>helpers"]
  node_seed["Seed data<br/>init scripts"]
end

node_client -->|"requests"| node_app
node_app -->|"mounts"| node_listing_route
node_app -->|"mounts"| node_review_route
node_app -->|"mounts"| node_user_route
node_listing_route -->|"delegates"| node_listing_ctrl
node_review_route -->|"delegates"| node_review_ctrl
node_user_route -->|"delegates"| node_user_ctrl
node_listing_ctrl -->|"reads/writes"| node_listing_model
node_review_ctrl -->|"reads/writes"| node_review_model
node_user_ctrl -->|"reads/writes"| node_user_model
node_listing_model -->|"persists to"| node_mongo
node_review_model -->|"persists to"| node_mongo
node_user_model -->|"persists to"| node_mongo
node_listing_ctrl -->|"uploads images"| node_cloud
node_app -->|"uses"| node_middleware
node_listing_ctrl -->|"validates"| node_schema
node_review_ctrl -->|"validates"| node_schema
node_listing_ctrl -->|"wraps errors"| node_errors
node_review_ctrl -->|"wraps errors"| node_errors
node_user_ctrl -->|"wraps errors"| node_errors
node_app -->|"renders"| node_views
node_views -->|"includes"| node_partials
node_app -->|"serves"| node_styles
node_seed -.->|"seeds"| node_listing_model
node_seed -.->|"loads"| node_mongo

click node_app "https://github.com/anshuvrit/wanderlust/blob/main/app.js"
click node_listing_route "https://github.com/anshuvrit/wanderlust/blob/main/routes/listing.js"
click node_review_route "https://github.com/anshuvrit/wanderlust/blob/main/routes/review.js"
click node_user_route "https://github.com/anshuvrit/wanderlust/blob/main/routes/user.js"
click node_listing_ctrl "https://github.com/anshuvrit/wanderlust/blob/main/controllers/listings.js"
click node_review_ctrl "https://github.com/anshuvrit/wanderlust/blob/main/controllers/reviews.js"
click node_user_ctrl "https://github.com/anshuvrit/wanderlust/blob/main/controllers/user.js"
click node_listing_model "https://github.com/anshuvrit/wanderlust/blob/main/models/listing.js"
click node_review_model "https://github.com/anshuvrit/wanderlust/blob/main/models/review.js"
click node_user_model "https://github.com/anshuvrit/wanderlust/blob/main/models/user.js"
click node_views "https://github.com/anshuvrit/wanderlust/tree/main/views"
click node_partials "https://github.com/anshuvrit/wanderlust/tree/main/views/includes"
click node_styles "https://github.com/anshuvrit/wanderlust/tree/main/public/css"
click node_cloud "https://github.com/anshuvrit/wanderlust/blob/main/cloudConfig.js"
click node_middleware "https://github.com/anshuvrit/wanderlust/blob/main/middleware.js"
click node_schema "https://github.com/anshuvrit/wanderlust/blob/main/schema.js"
click node_errors "https://github.com/anshuvrit/wanderlust/tree/main/utills"
click node_seed "https://github.com/anshuvrit/wanderlust/tree/main/init"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_app,node_listing_route,node_review_route,node_user_route toneBlue
class node_listing_ctrl,node_review_ctrl,node_user_ctrl,node_listing_model,node_review_model,node_user_model,node_mongo toneAmber
class node_views,node_partials,node_styles toneMint
class node_cloud,node_middleware,node_schema,node_errors,node_seed toneRose
```

## Components

### Request entry

Incoming HTTP requests and app bootstrap

- **Browser**: client · User-facing request source
- [Express app](https://github.com/anshuvrit/wanderlust/blob/main/app.js): bootstrap · Assembles middleware, routes, views, and static files · `app.js`
- [Listing routes](https://github.com/anshuvrit/wanderlust/blob/main/routes/listing.js): route module · HTTP endpoints for listings · `routes/listing.js`
- [Review routes](https://github.com/anshuvrit/wanderlust/blob/main/routes/review.js): route module · HTTP endpoints for reviews · `routes/review.js`
- [User routes](https://github.com/anshuvrit/wanderlust/blob/main/routes/user.js): route module · HTTP endpoints for authentication and accounts · `routes/user.js`

### Domain and data

Resource handlers, models, and persistence

- [Listing ctrl](https://github.com/anshuvrit/wanderlust/blob/main/controllers/listings.js): controller · Marketplace CRUD and listing workflow · `controllers/listings.js`
- [Review ctrl](https://github.com/anshuvrit/wanderlust/blob/main/controllers/reviews.js): controller · Review creation and deletion · `controllers/reviews.js`
- [User ctrl](https://github.com/anshuvrit/wanderlust/blob/main/controllers/user.js): controller · Signup, login, and account flows · `controllers/user.js`
- [Listing](https://github.com/anshuvrit/wanderlust/blob/main/models/listing.js): mongoose model · Primary marketplace record · `models/listing.js`
- [Review](https://github.com/anshuvrit/wanderlust/blob/main/models/review.js): mongoose model · Feedback tied to listings and users · `models/review.js`
- [User](https://github.com/anshuvrit/wanderlust/blob/main/models/user.js): mongoose model · Accounts and ownership · `models/user.js`
- **MongoDB Atlas**: database · External persistence store

### Presentation

Server-rendered pages and shared assets

- [EJS views](https://github.com/anshuvrit/wanderlust/tree/main/views): template layer · Server-rendered pages and shared layout · `views`
- [Shared partials](https://github.com/anshuvrit/wanderlust/tree/main/views/includes): view partials · Navbar, footer, flash, and boilerplate layout · `views/includes`
- [Stylesheets](https://github.com/anshuvrit/wanderlust/tree/main/public/css): assets · Public CSS for layout and rating UI · `public/css`

### Support services

Cross-cutting helpers and external integrations

- [Cloudinary](https://github.com/anshuvrit/wanderlust/blob/main/cloudConfig.js): media service · External image storage and delivery · `cloudConfig.js`
- [Middleware](https://github.com/anshuvrit/wanderlust/blob/main/middleware.js): request guards · Auth, authorization, and request checks · `middleware.js`
- [Validation schema](https://github.com/anshuvrit/wanderlust/blob/main/schema.js): input validation · Request/body validation boundary · `schema.js`
- [Error utils](https://github.com/anshuvrit/wanderlust/tree/main/utills): helpers · Async wrapping and custom errors · `utills`
- [Seed data](https://github.com/anshuvrit/wanderlust/tree/main/init): init scripts · Development data initialization · `init`

## Connections

- Browser → Express app: requests · Browser requests enter the Express application
- Express app → Listing routes: mounts · Listing routes are registered on the app
- Express app → Review routes: mounts · Review routes are registered on the app
- Express app → User routes: mounts · User routes are registered on the app
- Listing routes → Listing ctrl: delegates · Listing endpoints call controller handlers
- Review routes → Review ctrl: delegates · Review endpoints call controller handlers
- User routes → User ctrl: delegates · User endpoints call controller handlers
- Listing ctrl → Listing: reads/writes · Listing workflow persists data through the model
- Review ctrl → Review: reads/writes · Review workflow persists data through the model
- User ctrl → User: reads/writes · Account workflow persists data through the model
- Listing → MongoDB Atlas: persists to · Mongoose stores listing records in MongoDB Atlas
- Review → MongoDB Atlas: persists to · Mongoose stores review records in MongoDB Atlas
- User → MongoDB Atlas: persists to · Mongoose stores user records in MongoDB Atlas
- Listing ctrl → Cloudinary: uploads images · Listing creation and edits use cloud image storage
- Express app → Middleware: uses · App-wide guards and request handling middleware
- Listing ctrl → Validation schema: validates · Listing inputs are validated before persistence
- Review ctrl → Validation schema: validates · Review inputs are validated before persistence
- Listing ctrl → Error utils: wraps errors · Async controller errors are centralized
- Review ctrl → Error utils: wraps errors · Async controller errors are centralized
- User ctrl → Error utils: wraps errors · Async controller errors are centralized
- Express app → EJS views: renders · Server responses are rendered with EJS templates
- EJS views → Shared partials: includes · Pages share common layout fragments
- Express app → Stylesheets: serves · Static CSS is exposed from public assets
- Seed data → Listing: seeds · Initialization scripts populate listing data
- Seed data → MongoDB Atlas: loads · Seed scripts write development data to the database
